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


当前回答

使用游戏!不是编程游戏,而是编程比赛。想想谷歌AI挑战,把它简化。

让我举个例子。我曾经和我的朋友进行过一次小竞赛:我们中的一个人建立了一个模拟框架,其他人编写了一个AI,范围从简单到高度分析,我们进行了100次测试,看看哪个AI表现最好。

该框架?基本I/O:模拟控制由每个竞争AI生成一个子进程执行,每一轮模拟将数据写入标准输入管道,并读取输出。这样,我们就可以用任何我们想要的语言来编写我们的ai,只需要遵循一个非常简单的协议。

规则非常简单,但事情很有挑战性:我们有两个村庄,A村和B村,它们在居住在那里的家庭中平均分配资金。A有800个硬币,B有500个。每一轮,所有人工智能都被要求选择一个村庄居住(将“a”或“B”打印到stdout),然后返回每个村庄在此期间的总数(通过读取stdin中的数字)。我们的目标是在100轮比赛后获得最多的钱。

我们创造的一些ai拥有非常复杂的机制去尝试并猜测该去哪个村庄定居—-尽管它们并不是很好,因为获胜的策略总是选择上一轮给每个家庭最少钱的村庄(假设大多数人会在下一轮搬到另一个村庄)。

我认为这很吸引人,鼓励研究,是一种健康的竞争方式。有成千上万的游戏可以玩,它只需要基本的编程知识(标准I/O!)让玩家进行互动。

其他回答

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

大多数答案都使用某种API,这在某种程度上打破了10行代码的要求。每个API调用可能包含数百行代码。最初的问题说要使用“简单代码”。这对我来说意味着没有API调用。仅仅使用“简单代码”的定义,我们能得出什么样的答案呢?

使用游戏!不是编程游戏,而是编程比赛。想想谷歌AI挑战,把它简化。

让我举个例子。我曾经和我的朋友进行过一次小竞赛:我们中的一个人建立了一个模拟框架,其他人编写了一个AI,范围从简单到高度分析,我们进行了100次测试,看看哪个AI表现最好。

该框架?基本I/O:模拟控制由每个竞争AI生成一个子进程执行,每一轮模拟将数据写入标准输入管道,并读取输出。这样,我们就可以用任何我们想要的语言来编写我们的ai,只需要遵循一个非常简单的协议。

规则非常简单,但事情很有挑战性:我们有两个村庄,A村和B村,它们在居住在那里的家庭中平均分配资金。A有800个硬币,B有500个。每一轮,所有人工智能都被要求选择一个村庄居住(将“a”或“B”打印到stdout),然后返回每个村庄在此期间的总数(通过读取stdin中的数字)。我们的目标是在100轮比赛后获得最多的钱。

我们创造的一些ai拥有非常复杂的机制去尝试并猜测该去哪个村庄定居—-尽管它们并不是很好,因为获胜的策略总是选择上一轮给每个家庭最少钱的村庄(假设大多数人会在下一轮搬到另一个村庄)。

我认为这很吸引人,鼓励研究,是一种健康的竞争方式。有成千上万的游戏可以玩,它只需要基本的编程知识(标准I/O!)让玩家进行互动。

Mandelbrot集合可以用一种不太复杂的方式来表示,例如下面的Java:

public class MiniMandelbrot {
    public static void main(String[] args) {
        int[] rgbArray = new int[256 * 256];
        for (int y=0; y<256; y++) {
            for (int x=0; x<256; x++) {
                double cReal=x/64.0-2.0, cImaginary=y/64.0-2.0;
                double zReal=0.0, zImaginary=0.0, zRealSquared=0.0, zImaginarySquared=0.0;
                int i;
                for (i = 0; (i < 63) && (zRealSquared + zImaginarySquared < 4.0); i++) {
                    zImaginary = (zReal * zImaginary) + (zReal * zImaginary) + cImaginary;
                    zReal = zRealSquared - zImaginarySquared - cReal;
                    zImaginarySquared = zImaginary * zImaginary;
                    zRealSquared = zReal * zReal;
                }
                rgbArray[x+y*256] = i * 0x040404;
            }
        }
        java.awt.image.BufferedImage bufferedImage = new java.awt.image.BufferedImage(256, 256, 1);
        bufferedImage.setRGB(0, 0, 256, 256, rgbArray, 0, 256);
        javax.swing.JOptionPane.showMessageDialog(null, new javax.swing.ImageIcon(bufferedImage), "The Mandelbrot Set", -1);
    }
}

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

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