3 ms·
I while ago I wrote a simple Hangman in K, a cousin of J. 6 fairly simple SLoC, and there's still some room for golfing it: d: ("aardvark";"apple";"peanut"
by RodgerTheGreat 11y ago
I while ago I wrote a simple Hangman in K, a cousin of J. 6 fairly simple SLoC, and there's still some room for golfing it:
d: ("aardvark";"apple";"peanut";"etc"); / dictionary
w: d[*1?#d]; / pick a word
c: {|/w=/:x}; / correctly guessed
b: {{$[x 0;x 1;"_"]}'+(c[x];w)}; / word with blanks
p: {`0:" > ";*0:`}; / prompt for a letter
{~&/c[x]}{`0:b[x]; x,p[]}/"__"; `0:w,"\n";
https://github.com/JohnEarnest/ok/blob/gh-pages/examples/hangman.k https://github.com/JohnEarnest/ok/blob/gh-pages/examples/han...
- eggy 11y agoNice. And I am sure in K that you can put all of those lines in one big line, making it a one line solution vs. his 3 line solution. This is why I think the suggestion above about character count is more relevant in this type of 'golfing'. This will give me a start on my J program. However, he does some reaching out for words to the word list found in a local word list. I plan on doing the same, and possibly an internet connection more word lists. EDIT: Realized words from usr/.. word list, not internet.
- RodgerTheGreat 11y agoSure, I could certainly compress it into a oneliner. I'm mainly focused on trying to make something simple with few moving parts. To that end I did a little more tinkering. Most pleasantly I was able to remove the conditional: w: *1?("aardvark";"apple";"peanut";"etc") / pick a word c: {|/w=/:x} / correctly guessed b: {("_",'w)@'c x} / word with blanks p: {`0:" > ";*0:`} / prompt for a letter {~&/c x}{`0:b x; x,p[]}/"__"; `0:w,"\n";