我正在寻找最酷的事情,你可以在几行简单的代码。我相信你可以用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。你还有什么其他的想法吗?


当前回答

这是我的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);
}

其他回答

It has been fun reading the answers to this question. Once you've achieved the 'wow' factor from the students, illustrate the daisy-chaining affect of the results of one becoming the input of another. Learning how input and output works will illustrate the idea of building blocks and how software grows from lots of little things solving specific problems to larger applications solving bigger problems. If a few 10 line programs can be cool, how cool would it be to then put a bunch of them together? That is non-linear cool.

我从我的孩子那里得到了一个很好的反应,用一个快速的VB脚本来操作微软代理字符。对于那些不熟悉MS Agent的人来说,它是一系列可以通过COM接口操作的动画屏幕角色。您可以在Microsoft Agent下载页面下载代码和字符。

下面几句台词会让梅林角色出现在屏幕上,飞来飞去,敲屏幕引起你的注意,并打招呼。

agentName = "Merlin"
agentPath = "c:\windows\msagent\chars\" & agentName & ".acs"
Set agent = CreateObject("Agent.Control.2")

agent.Connected = TRUE
agent.Characters.Load agentName, agentPath
Set character = agent.Characters.Character(agentName)

character.Show

character.MoveTo 500, 400
character.Play "GetAttention"
character.Speak "Hello, how are you?"
Wscript.Sleep 15000
character.Stop
character.Play "Hide"

您还可以使用许多其他命令。查看http://www.microsoft.com/technet/scriptcenter/funzone/agent.mspx了解更多信息。

编辑2011-09-02 我最近发现Microsoft Agent并没有安装在Windows 7上。不过,这里提供单独的下载。我没有测试过这个,所以无法验证它是否运行。

处理总是很有趣的,它创造的东西对所有类型的人都印象深刻。例如,布朗树:

int xf = (int) random(width);
int yf = (int) random(height);
int x = (int) random(width);
int y = (int) random(height);

background(0xFF);
while(x != xf || y != yf) {
  set(x,y,color(0,0,0));
  x = max(0, min(x + -1 + (int) random(3), width - 1) );
  y = max(0, min(y + -1 + (int) random(3), height - 1) );
}

嗯,我记得用QBasic制作雪花和火焰时,一个朋友过来教我如何做一个旋转的3D立方体,完全让我震惊。

然后我把火调到立方体上,那真是美好的时光。

我得看看能不能找到那些旧剧本,它们不是很长。

你可以让你的学生去codeplex IronPython silverlight示例站点,其中包括一个< 10行的修改画布和与鼠标交互的演示。你可以在这里找到silverlight的例子

仅仅看到在web浏览器中编写的代码,然后执行修改一个小的WPF可能会让一些人陶醉。