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


当前回答

如何展示你可以在任何网页浏览器中输入JavaScript到地址栏,然后让代码执行?

编辑:去一个有很多图片的页面,在地址栏试试这个:

javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.images; DIL=DI.length; function A(){for(i=0; i<DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=Math.sin(R*x1+i*x2+x3)*x4+x5; DIS.top=Math.cos(R*y1+i*y2+y3)*y4+y5}R++ }setInterval('A()',5); void(0)

其他回答

我认为在Python中使用NodeBox进行一些很酷的实验将是一个很酷的开始。它的功能是绘制从正方形到复杂路径的物体。它甚至可以接收来自Mac iSight/网络摄像头的图像,并通过缩放、旋转和应用滤镜进行操作。

不幸的是,它只适用于Mac OS X,所以我不认为教它有多大用处,但作为一个例子(如果你自己有一台Mac),用一点代码就能做到什么,这将是相当漂亮的。

当史蒂夫·沃兹尼亚克(Steve Wozniak)制作第一台Apple II时,他喜欢用Apple Basic来展示一款Breakout游戏,他当场就输入了这个游戏。我想大概有10行;我希望我能把它粘贴在这里。你也可以在Processing这样的系统中这样做。

import sys
for y in range(80):
    for x in range(80):
        c = complex(x-40.0,y-40.0) / 20.0
        z = 0.0
        for i in range(100):
            z = z*z+c
        sys.stdout.write('#' if abs(z) < 2.0 else ' ')
    sys.stdout.write('\n')

我一直很喜欢河内塔。在计划

(define (hanoi x from to spare)
  (if (= x 1)
    (begin
      (display "move ")(display from)(display " to ")(display to)(display "\n"))
  (begin
    (hanoi (- x 1) from spare to)
    (hanoi 1 from to spare)
    (hanoi (- x 1) spare to from))))

示例输出

gosh> (hanoi 3 'start 'dest 'spare)
move start to dest
move start to spare
move dest to spare
move start to dest
move spare to start
move spare to dest
move start to dest
#<undef>

同样在Python中(尽管这不能像Scheme版本那样做1000张光盘)

def hanoi(x, source, dest, spare):
  if x == 1:
    print "%s to %s" % (source, dest)
  else:
    hanoi(x - 1, source, spare, dest)
    hanoi(1, source, dest, spare)
    hanoi(x - 1, spare, dest, source)

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