23 May 2022

D00DlE5

We are asked for a list of 2-8 letter words comprising which can be spelled with the symbols ABCDEF0157 with 0 read as O, 1 as either I or L, 5 as S and 7 as T.

The operations required on any word are:

  • discard if not 2-8 letters long
  • discard if contain anything not in ABCDEFOLIST
  • anything left is a solution
From the supplied dictionary there are 1464 such words.

I found that having 1 represent I or L made for some hard to read solutions such as 1111C17 (illicit), so eliminating 1 -> L reduced the number to 693.

For the first optional extra I limited the number of 'special' substitutions to 3, which reduced the number to 559, losing such words as DE5I57ED (desisted).

The second optional extra, requiring us to make 8-letter phrases from these words is a little trickier. Given that the words vary from 2-8 letters long, they could be combined as follows:

2 + 6, 3 + 5, 4 + 4, 2 + 2 + 4, 2 + 3 + 3, 2 + 2 + 2 + 2

Of the 559 words from optional extra 1, 15 have 2 letters, 69 have three letters, 139 have 4 letters, 125 have 5 letters and 109 have 6 letters.

So:
2 + 6 combinations total 1635
3 + 5 -> 8625
4 + 4 -> 19321
2 + 2 + 4 -> 31275
2 + 3 + 3 -> 71415
2 + 2 + 2 + 2 -> 50625

So there are 182896 possible phrases, of which most are probably not 'phrases' that one would use, and while it would be easy enough to generate them all, I didn't.

Directory compare

The logic of this is:
  • Loop over directories and files
  • Find the longest file name (to determine column width)
  • Create %files with key = file name and value = a list of the containing directories
  • Create a string ($all) that indicates the file is in all directories
Print the heading lines using the longest file name (above) to determine column width and then:

  • Loop over directories and files
  • Skip file if $files{$file} eq $all
  • Print the file name in every column that appears in $files{$file}
Getting the columns to line up is a little messy, made slightly worse by the example have one fewer vertical line than columns. The %-s format in sprintf comes in useful for padding the file names to the right width.





No comments:

Post a Comment