我正在寻找最酷的事情,你可以在几行简单的代码。我相信你可以用Haskell用15行写一个Mandelbrot集,但是很难理解。

我的目标是启发学生编程很酷。

我们知道编程很酷,因为你可以创造任何你想象到的东西——它是最终的创意出口。我想激励这些初学者,让他们尽可能多地克服早期学习的困难。

Now, my reasons are selfish. I'm teaching an Intro to Computing course to a group of 60 half-engineering, half business majors; all freshmen. They are the students who came from underprivileged High schools. From my past experience, the group is generally split as follows: a few rock-stars, some who try very hard and kind of get it, the few who try very hard and barely get it, and the few who don't care. I want to reach as many of these groups as effectively as I can. Here's an example of how I'd use a computer program to teach:

Here's an example of what I'm looking for: a 1-line VBS script to get your computer to talk to you: CreateObject("sapi.spvoice").Speak InputBox("Enter your text","Talk it") I could use this to demonstrate order of operations. I'd show the code, let them play with it, then explain that There's a lot going on in that line, but the computer can make sense of it, because it knows the rules. Then I'd show them something like this: 4(5*5) / 10 + 9(.25 + .75) And you can see that first I need to do is (5*5). Then I can multiply for 4. And now I've created the Object. Dividing by 10 is the same as calling Speak - I can't Speak before I have an object, and I can't divide before I have 100. Then on the other side I first create an InputBox with some instructions for how to display it. When I hit enter on the input box it evaluates or "returns" whatever I entered. (Hint: 'oooooo' makes a funny sound) So when I say Speak, the right side is what to Speak. And I get that from the InputBox. So when you do several things on a line, like: x = 14 + y; You need to be aware of the order of things. First we add 14 and y. Then we put the result (what it evaluates to, or returns) into x.

这就是我的目标,有一堆很酷的例子来演示,并在他们玩得开心的时候教他们。我在我室友身上尝试了这个例子,虽然我可能不会把它作为第一课,但她喜欢它,并学到了一些东西。

一些很酷的数学程序,可以做出漂亮的图形或容易理解的形状,这是很好的想法,我将研究这些。这里有一些复杂的actionscript示例,但这有点太高级了,我不能教flash。你还有什么其他的想法吗?


当前回答

这段PHP代码只能通过命令行在Mac上运行,但当每个人都想玩Twister时,它非常有用

$lr = array('left', 'right');
$hf = array('hand', 'foot');
$colour = array('red', 'yellow', 'blue', 'green');
while(true) {
    $a = $lr[array_rand($lr)];
    $b = $hf[array_rand($hf)];
    $c = $colour[array_rand($colour)];
    system("say $a $b $c");
    sleep(5);
}

其他回答

Back in computer class in high school, myself and a couple of friends taught the class how to program with Delphi. The class was mostly focused on programming with Pascal, so Delphi was a good next step. We demonstrated the event driven nature of Delphi and its RAD capabilities. At the end of the lesson we showed the class a sample application and asked them to reproduce it. The application asked "Are you drunk?" with two buttons Yes and No. ...I think you know what is coming next...the No button changed locations on mouse over and was almost impossible to click.

学生和老师都从中得到了很大的乐趣。

该程序只需要几行用户编写的代码和一个简单的方程来计算按钮的移动位置。我想其他学生都没发现,但也有几个很接近。

我被演讲《Easy AI with Python》(视频和PDF)中展示的一些东西所震撼。例如,教计算机如何玩“Mastermind”游戏,解决八个皇后,字母(那些像“9567 + 1085 == 10652”这样的谜题,以及推断数据中的关系。所有代码都在10行以内(可能包含20或30行“幕后”代码)。

我倾向于认为,人们会对那些与他们生活有关或相关的东西印象深刻。我会试着以他们知道和理解的东西为基础编写我的10行代码。以Twitter及其API为例。为什么不使用这个API来构建一些很酷的东西呢?下面的10行代码将从Twitter返回“公共时间线”,并在控制台应用程序中显示它……

using (var xmlr = XmlReader.Create("http://twitter.com/statuses/public_timeline.rss"))
    {
        SyndicationFeed
            .Load(xmlr)
            .GetRss20Formatter()
            .Feed
            .Items        
            .ToList()
            .ForEach( x => Console.WriteLine(x.Title.Text));
    }

我的代码样本可能不是最适合您的学生的。它是用c#编写的,使用。net 3.5。所以,如果你要教他们PHP、Java或c++,这是没有用的。然而,我的观点是,通过将你的10行代码与一些“酷、有趣、与学生相关”的东西联系起来,你的示例也会变得酷、有趣、与学生相关。

好运!

[是的,我知道我错过了使用语句和Main方法的几行,但我猜这10行并不需要真的是10行]

这是我的10线蜘蛛。从技术上讲,它是11,包括perl shell声明,但我希望这是可以原谅的!

我想让它识别某些文件类型和支持相对路径,但跑出了行!

运行:

perl spider.pl http://yahoo.com/search?q=test

请注意,谷歌不允许没有用户代理的LWP Simple,因此搜索谷歌将不起作用。也容不下那个!总之,代码在哪里:

#!/usr/bin/perl -w
use LWP::Simple;
my @queue = ($ARGV[0]);
my %visited = ();
while (my $url = pop(@queue)) {
    next if $visited{$url};
    $visited{$url} = 1;
    my $html = get($url) or next;
    print "Spidering $url\n";
    push(@queue, $html =~ m/(http:\/\/[^'"]*)/g);
}

我发现最喜欢的(在GWBASIC中)是:

10 input "What is your name ";N$
20 i = int(rnd * 2)
30 if i = 0 print "Hello ";N$;". You are a <fill in insult number 1>"
40 if i = 1 print "Hello ";N$;". You are a <fill in insult number 2>"

我发现初学的学生有一些观念需要修正。

电脑不会读心术。 计算机一次只做一件事,即使它们做得如此之快,它们似乎一次就做完了。 计算机只是愚蠢的机器,只会做被告知的事情。 计算机只能识别特定的东西,而这些东西就像积木一样。 一个关键的概念是,变量是包含一个值的东西,它的名称与该值不同。 你编辑程序的时间和它运行的时间之间的区别。

祝你在课堂上好运。我相信你会做得很好的。

附言:我相信你明白,除了材料和技能,你还在教授一种态度,这也是同样重要的。