Skip to content

Instantly share code, notes, and snippets.

@threeifbywhiskey
Created March 19, 2014 17:54
Show Gist options
  • Save threeifbywhiskey/9647454 to your computer and use it in GitHub Desktop.
Save threeifbywhiskey/9647454 to your computer and use it in GitHub Desktop.
This is a solution to /r/dailyprogrammer's Intermediate challenge #154 written using the Church gem.
require 'church'
include Church
GORELLIAN = -> n, alphabet, words {
alphabet = MAP[CHARS[alphabet], &-> a { ORD[a] | 32 }]
EACH[SORT_BY[words, &-> w {MAP[CHARS[w],
&-> c { INDEX[alphabet, ORD[c] | 32] }] }], &PUTS]
}
GORELLIAN[8, 'UVWXYZNOPQRSTHIJKLMABCDEFG',
['ANTLER', 'ANY', 'COW', 'HILL', 'HOW', 'HOWEVER', 'WHATEVER', 'ZONE']]
PUTS['']
GORELLIAN[5, 'ZYXWVuTSRQpONMLkJIHGFEDCBa',
['go', 'aLL', 'ACM', 'teamS', 'Go']]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment