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


当前回答

你可以使用jQuery(Write Less,Do More)库以最少的代码在HTML web表单中实现出色的视觉效果。否则,像f#这样的函数式语言也可以用很少的代码行做很多事情。以下是Project euler问题8的解答:-

数据:- 50 * 20网格的数字字符串

let data = txt |> Seq。toList |>列表。filter System.Char.IsDigit |>列表。地图System.Char.GetNumericValue

让rec partition_5 l = 匹配l | x1:: (x2:: x3:: x4:: x5:: _当t) - > (x1、x2、x3、x4 x5):: (partition_5 t) | _ -> []

let euler_8 =列表。map (fun x ->列表。fold (*) 1.0 x) (partition_5 data) |> List.max

其他回答

我认为任何可以做一些有用的事情的shell脚本都是向人们展示编程力量的好方法。在我看来,能够在一个小脚本上花费10-20分钟来自动化另一项任务并节省无数小时是非常令人印象深刻的。

例如,我曾经写过一个简单的Perl脚本,将一个目录中的mp3文件转换为另一种格式,然后将它们刻录到cd上。你用mp3目录的路径调用这个脚本,它就刻录了cd。至少当时我印象深刻。

10 PRINT "HELLO"
20 GOTO 10

但那时我还只是个孩子。这也是为什么它是最酷的事情。我不认为你能从第一次编写计算机程序中获得同样的快感。即使只是简单地向控制台无限地输出“HELLO”。

递归也可以用来解决迷宫。就像谢尔宾斯基三角和其他艺术一样,对我来说,这比解决一些数学问题有趣得多。

试着让你的学生编一个神奇的8号球。一个基本的回答“是”或“否”的8球程序可能只需要不到10行代码,并且它可以以任何方式递增:

First, make it simple: input something like "s" for shake into a CLI; 8ball answers "yes" or "no" Next, input a question, display the question along with the answer Then expand the possible answers.... Loads of options, the students who are quick to catch on can have some fun ("Look, the computer says dirty words!!"), while you help the others Implement a timer, so you can't ask the same question again right away, in case you don't like the answer Group possible answers into variants of "yes", "no" and "hazy" or something; first RNG decides type of answer, second RNG decides the specific answer Reconfigure the timer; you can ask again right away if the answer is hazy Make a frame of *'s around the text And so on....

一个神奇的8球是大多数人都能联系到的东西,它只使用最简单的工具介绍了基本的字符串,浮点数/整数,IO, CLI,布尔和RNG。它很简单,(有点)有趣,而且很容易扩展。根据您的方法,您可以使用类8ball()、类YesAnswer()等立即使编程面向对象。

祝你好运;-)

有点离题了,但你可以看看这个推文编码,它使用了不到140个字符的as3代码:

http://gskinner.com/playpen/tweetcoding_0/

^_^