Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
54
Task/24-game/Huginn/24-game.huginn
Normal file
54
Task/24-game/Huginn/24-game.huginn
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#! /bin/sh
|
||||
exec huginn --no-argv -E "${0}"
|
||||
#! huginn
|
||||
|
||||
import Algorithms as algo;
|
||||
import Mathematics as math;
|
||||
import RegularExpressions as re;
|
||||
|
||||
make_game( rndGen_ ) {
|
||||
board = "";
|
||||
for ( i : algo.range( 4 ) ) {
|
||||
board += ( " " + string( character( rndGen_.next() + integer( '1' ) ) ) );
|
||||
}
|
||||
return ( board.strip() );
|
||||
}
|
||||
|
||||
main() {
|
||||
rndGen = math.randomizer( 9 );
|
||||
no = 0;
|
||||
dd = re.compile( "\\d\\d" );
|
||||
while ( true ) {
|
||||
no += 1;
|
||||
board = make_game( rndGen );
|
||||
print( "Your four digits: {}\nExpression {}: ".format( board, no ) );
|
||||
line = input();
|
||||
if ( line == none ) {
|
||||
print( "\n" );
|
||||
break;
|
||||
}
|
||||
line = line.strip();
|
||||
try {
|
||||
if ( line == "q" ) {
|
||||
break;
|
||||
}
|
||||
if ( ( pos = line.find_other_than( "{}+-*/() ".format( board ) ) ) >= 0 ) {
|
||||
print( "Invalid input found at: {}, `{}`\n".format( pos, line ) );
|
||||
continue;
|
||||
}
|
||||
if ( dd.match( line ).matched() ) {
|
||||
print( "Digit concatenation is forbidden.\n" );
|
||||
continue;
|
||||
}
|
||||
res = real( line );
|
||||
if ( res == 24.0 ) {
|
||||
print( "Thats right!\n" );
|
||||
} else {
|
||||
print( "Bad answer!\n" );
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
print( "Not an expression: {}\n".format( e.what() ) );
|
||||
}
|
||||
}
|
||||
return ( 0 );
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue