public
Description: deepblue's thoughts
Homepage: http://myruby.net/
Clone URL: git://github.com/deepblue/snippets.git
snippets / chalenge / jolly_jumpers / jolly.factor
100644 20 lines (13 sloc) 0.438 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
USING: kernel sequences arrays math math.vectors sorting ;
IN: jolly
 
: differences ( seq -- new-seq )
  [ but-last ] keep rest v- [ abs ] map ;
 
: jolly? ( seq -- ? )
  differences natural-sort
  [ length >array [ 1+ ] map ] keep
  = ;
 
USING: tools.test ;
 
[ { 3 2 1 } ] [ { 1 4 2 3 } differences ] unit-test
 
[ t ] [ { 1 4 2 3 } jolly? ] unit-test
[ t ] [ { 3 -1 -3 -2 } jolly? ] unit-test
[ f ] [ { 1 4 2 -1 6 } jolly? ] unit-test