Skip to content

Instantly share code, notes, and snippets.

@davespanton
Created May 7, 2013 14:01
Show Gist options
  • Save davespanton/5532793 to your computer and use it in GitHub Desktop.
Save davespanton/5532793 to your computer and use it in GitHub Desktop.
Columnz challenge in Factor
USING: kernel locals sequences ;
IN: columnz
:: all-equal-first? ( col -- ? )
col [ col first = ] all? ;
: sum-or-first ( seq -- n )
dup all-equal-first? [ first ] [ sum ] if ;
: sum-or-first-seq ( seq -- seq )
flip [ sum-or-first ] map ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment