Skip to content

Instantly share code, notes, and snippets.

@roblogic
Last active August 25, 2019 11:16
Show Gist options
  • Select an option

  • Save roblogic/2745c2f1c85b8c73f4d4d9fe007894b1 to your computer and use it in GitHub Desktop.

Select an option

Save roblogic/2745c2f1c85b8c73f4d4d9fe007894b1 to your computer and use it in GitHub Desktop.
printing all 2-letter scrabble words, using zsh https://codegolf.stackexchange.com/a/190647/15940

Zsh, 175 bytes

This solution uses a 125-char string, where the lowercase letters serve as delimiters and the first letter of the following sequence of capital letters.

We iterate over the letters of $L. If the current letter $X is lowercase by ascii comparison, set $W to $X. Otherwise, print $W concatenated with $X to make the current word.

Try it Online!

L=aABDEGHILMNRSTWXYbAEIOYdEOeDFHLMNRSTXfAEgOhAEIMOiDFNSTjOkAIlAIOmAEIMOUYnAEOUoDEFHIMNPRSWXYpAEIqIrEsHIOtAIOuHMNPSTwEOxIUyAEOzA
for X in ${(s::)L};{((#X>90))&&W=$X||<<<$W$X:l}

Edit: appended :l to set lowercase consistently, per requirement
Edit2: -4 bytes using $X variable and simplified if [[..]] condition
Edit3: -4 bytes by removing quotes (")
Edit5: -5 bytes using array conversion instead of iterating over L per below
Edit4: Alternate approach for 182 bytes, exploiting reversible strings in the first 33 letters, $L is only 107 letters

L=aBHLMNTYdEOeFHMNRhOiSTmOUnOUoSWYaADEGIRSWXbEIOYeLSTXfAgOhIMiDFNjOkAIlIOmIMYoEFIPRXpAEIqIsHtOuHPSTwExIUyEzA
for ((;i++<$#L;))X=$L[i]&&((#X>90))&&W=$X:u||<<<$W$X`((i<34))&&<<<\ $X$W`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment