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


当前回答

这是一个非常基本的基于文本的c#程序,模拟老虎机的旋转动作。它不包括不同的中奖几率或现金奖励,但这对学生来说是一个很好的练习。

抱歉,超过10行。

string[] symbols = new[] { "#", "?", "~" }; // The symbols on the reel
Random rand = new Random();

do
{
    string a="",b="",c="";

    for( int i = 0; i < 20; i++ )
    {
        Thread.Sleep( 50 + 25 * i ); // slow down more the longer the loop runs

        if( i < 10 )
            a = symbols[rand.Next( 0, symbols.Length )];

        if( i < 15 )
            b = symbols[rand.Next( 0, symbols.Length )];

        c = symbols[rand.Next( 0, symbols.Length )];

        Console.Clear();
        Console.WriteLine( "Spin: " + a + b + c );
    }

    if( a == b && b == c )
        Console.WriteLine( "You win. Press enter to play again or type \"exit\" to exit" );
    else
        Console.WriteLine( "You lose. Press enter to play again or type \"exit\" to exit" );
}
while( Console.ReadLine() != "exit" );

其他回答

试着让你的学生编一个神奇的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()等立即使编程面向对象。

祝你好运;-)

当我还是个孩子的时候,这是最酷的事情:

10 PRINT "BEDWYR "
20 GOTO 10

我想现在它已经不太管用了;)

我没有这方面的代码,但是它可以在10行或更少的时间内被抽象出来。使鼠标画一个方框。不管你怎么移动它。当你点击(左)框消失,当你点击(右)框改变颜色。

学生们想要一些实用的东西,一些他们可以修改和定制的东西,一些表明这“不是典型的无聊课程”的东西。

Xen的mini-os内核现在可以做到这一点,但它需要额外的抽象来满足您的需求。

您还可以尝试绘制一个manderbolt (julia)集,同时从环境噪声获得二次平面的参数(如果机器有麦克风和声卡)..他们的声音会产生分形。同样,要在10行(在他们编辑的实际函数中)完成这一点很棘手,但并非不可能。

在现实世界中,您将使用现有的库。所以我认为,在main()(或任何你使用的语言)中使用10行代码更实用。我们让存在的东西为我们工作,而写不存在或不为我们工作的东西。你不妨一开始就介绍这个概念。

同时,行吗?Int main(void){无符号Int i;(我= 0;I < 10;我+ +);返回0;也许,10次函数调用将是一个更现实的目标?这不是一场模糊的代码竞赛。

好运!

我敢肯定它会变成超过10行代码,但你有没有考虑过一个基于表单的应用程序,按下按钮就可以改变背景的颜色或改变文本的大小?这将向他们展示交互程序是如何工作的。这也会告诉他们,作为程序员,他们可以完全控制计算机(程序)所做的事情。

希望这会引导他们对其他可以改变的事情提出建议,然后对其他他们可能想做的事情提出建议。

我倾向于认为,人们会对那些与他们生活有关或相关的东西印象深刻。我会试着以他们知道和理解的东西为基础编写我的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行]