News for hackers. Stuff that matters.
Re:Ask HN: What should I teach a class of low-income kids ab... by lsiebert on Wednesday April 10, 2013 @04:38PM (#5527989)
You can do a simple terminal program in 10 lines. 10 commands probably not, but this is still fairly readable. in perl, a simple guessing game that runs in linux/unix

#!/usr/bin/perl $SIG{ALRM} = \&timesup; my $random_num = int (rand(10)); print "Guess my number (0-9) in less than 10 seconds!\nGuess: "; alarm 10; while(1){ my $guess = <>; if ($guess == $random_num){alarm 0;print "You Got it! Well done!\n"; last; } else { print "Nope; guess again: ";} } sub timesup {die "Uh oh! Time ran out while waiting!\n";}

There are no comments on this comment yet.