# Paste: first attempt

Author: | sykopomp |

Mode: | factor |

Date: | Thu, 14 Jan 2010 03:27:20 |

Plain Text |

USING: kernel random io math.parser math combinators ;
IN: high-low
: guess ( -- guess ) "Your guess? " write flush readln string>number ;
: check-guess ( answer guess -- succeeded? )
{
{ [ 2dup > ] [ 2drop "Too low" print f ] }
{ [ 2dup < ] [ 2drop "Too high" print f ] }
[ 2drop "You win!" print t ]
} cond ;
: game-loop ( answer -- ) dup guess check-guess [ drop ] [ game-loop ] if ;
: start ( max -- ) random game-loop ;

Author: | sykopomp |

Mode: | factor |

Date: | Thu, 14 Jan 2010 03:37:00 |

Plain Text |

USING: kernel random io math.parser math combinators ;
IN: high-low
: guess ( -- guess ) "Your guess? " write flush readln string>number ;
: check-guess ( answer guess -- succeeded? )
{
{ [ 2dup > ] [ 2drop "Too low" print f ] }
{ [ 2dup < ] [ 2drop "Too high" print f ] }
[ 2drop "You win!" print t ]
} cond ;
: (game-loop) ( answer -- ) [ guess check-guess not ] curry loop ;
: game-loop ( max -- ) random game-loop ;
: start ( -- ) 30 game-loop ;
MAIN: start

Author: | sykopomp |

Mode: | factor |

Date: | Thu, 14 Jan 2010 04:42:21 |

Plain Text |

USING: kernel random io math.parser math combinators ;
IN: high-low
: guess ( -- guess ) "Your guess? " write flush readln string>number ;
: check-guess ( answer guess -- succeeded? )
{
{ [ 2dup > ] [ 2drop "Too low" print f ] }
{ [ 2dup < ] [ 2drop "Too high" print f ] }
[ 2drop "You win!" print t ]
} cond ;
: (game-loop) ( answer -- ) [ guess check-guess not ] curry loop ;
: game-loop ( max -- ) random (game-loop) ;
: start-game ( -- ) 30 game-loop ;
MAIN: start-game

Author: | sykopomp |

Mode: | factor |

Date: | Thu, 14 Jan 2010 16:47:34 |

Plain Text |

USING: kernel random io math.parser math combinators ;
IN: high-low
: (guess) ( -- guess ) "Your guess? " write flush readln string>number ;
: guess ( -- guess ) (guess) dup [ ] [ drop "Not a number. Try again.\n" write flush guess ] if ;
: check-guess ( answer guess -- succeeded? )
{
{ [ 2dup > ] [ 2drop "Too low" print f ] }
{ [ 2dup < ] [ 2drop "Too high" print f ] }
[ 2drop "You win!" print t ]
} cond ;
: (game-loop) ( answer -- ) [ guess check-guess not ] curry loop ;
: game-loop ( max -- ) random (game-loop) ;
: start-game ( -- ) 30 game-loop ;
MAIN: start-game

## New Annotation