public
Description: deepblue's thoughts
Homepage: http://myruby.net/
Clone URL: git://github.com/deepblue/snippets.git
Bryan Kang (author)
Sun Feb 08 18:55:02 -0800 2009
commit  50bcfcc83070f51559557fec8c20256fc72e781f
tree    fd5e69329803b69cb67cb4795a58ee36ec547764
parent  b188bf3aacdc917b1cbd03bedb35745d9992da71
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