Paste: Ubongo! MK2
Author: | yac |
Mode: | factor |
Date: | Fri, 5 Aug 2011 13:13:07 |
Plain Text |
USING: kernel math math.ranges math.parser math.order
accessors assocs sequences sorting strings arrays splitting
io io.files io.encodings.utf8 command-line ;
IN: ubongo
TUPLE: player n oc ;
: <player> player boa ;
: >players
dup length [1,b] swap zip [ first2 <player> ] map ;
: ubongo'
dup first
[
dup dup first [ = not ] curry find drop
dup [ tail ] dip swap [ suffix ] dip
ubongo'
] when ;
: ubongo
{ } swap natural-sort f suffix ubongo' drop [ >=< ] sort ;
: winner'
[ [ oc>> ] bi@ >=< ] sort
dup first2 [ oc>> ] bi@ = [ drop 0 ] [ first n>> ] if ;
: winner
[ dup empty?
[ drop { } ] [ { CHAR: \s } split ubongo ] if
] map >players winner' ;
: main
(command-line) rest dup empty?
[ drop "Need an input file as only argument" ]
[ first utf8 file-lines winner number>string ]
if print ;
main
New Annotation