diff --git a/.gitignore b/.gitignore
new file mode 100755
index 0000000..9c4e7a4
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,47 @@
+# Windows image file caches
+Thumbs.db
+ehthumbs.db
+
+# Folder config file
+Desktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Windows Installer files
+*.cab
+*.msi
+*.msm
+*.msp
+
+# =========================
+# Operating System Files
+# =========================
+
+# OSX
+# =========================
+
+.DS_Store
+.AppleDouble
+.LSOverride
+
+# Icon must end with two \r
+Icon
+
+
+# Thumbnails
+._*
+
+# Files that might appear on external disk
+.Spotlight-V100
+.Trashes
+
+# Directories potentially created on remote AFP share
+.AppleDB
+.AppleDesktop
+Network Trash Folder
+Temporary Items
+.apdisk
+
+# other
+.idea
diff --git a/.idea/.name b/.idea/.name
new file mode 100755
index 0000000..f632245
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+puzzles
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100755
index 0000000..7c62b52
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
If you have a solution you'd like to share see the Solutions page for instructions.
diff --git a/solutions/FableT/PyPoetry.py b/solutions/FableT/PyPoetry.py new file mode 100755 index 0000000..89ba046 --- /dev/null +++ b/solutions/FableT/PyPoetry.py @@ -0,0 +1,74 @@ +# load poem or phrase from file into variable +with open('poem.txt') as f: + poem = f.read() + +# load unix words dictionary into words variable +with open('usr/share/dict/words') as w: + words = w.read().splitlines() + + +# pick out all letters with unique, non-zero counts +def unique_letters(key_phrase): + available_letters = set([c for c in key_phrase if c.isalpha()]) + letter_counts = [key_phrase.count(c) for c in available_letters] + return [c for c in available_letters if letter_counts.count(key_phrase.count(c)) == 1] + + +# creates mapping with code as key for decoding +code_into_letter = {poem.count(c): c for c in unique_letters(poem)} + +# creates mapping with letter as key for encoding +letter_into_code = {c: poem.count(c) for c in unique_letters(poem)} + + +# encode or decode the riddle +def riddle_me_this(riddle, mapping): + return [mapping[key] for key in riddle] + + +# returns all words that can be used in a door riddle +def riddle_words(all_words, available_letters): + return [riddle for riddle in all_words if set(riddle).issubset(available_letters)] + + +# returns all riddle codes for potential door riddles +def coded_riddles(all_words, mapping): + return [riddle_me_this(word, mapping) for word in all_words] + + +# print list items to file, one item per line +def print_to_file(file_name, list_to_print): + fo = open(file_name, "w") + for item in list_to_print: + fo.write(str(item) + "\n") + fo.close() + + +# print dictionary to file, one key/value pair per line +def print_dict(file_name, dict_to_print): + fo = open(file_name, "w") + for key, value in dict_to_print.items(): + fo.write(str(key) + ": " + str(value) + "\n") + fo.close() + + +# relevant solutions saved to variables +all_letters = unique_letters(poem) +word_list = riddle_words(words, all_letters) +riddle_codes = coded_riddles(word_list, letter_into_code) +answer_key = {tuple(code): ''.join(riddle_me_this(code, code_into_letter)) for code in riddle_codes} +longest_word = max(word_list, key=len) + +#print comprehensive lists to files +print_to_file("word_list.txt", word_list) +print_to_file("riddle_list.txt", riddle_codes) +print_dict("answer_key.txt", answer_key) + +if __name__ == '__main__': + print("Available letters are: {}".format(', '.join(unique_letters(poem)))) + print("Letter mapping is: {}".format(letter_into_code)) + + print("\nThe answer to the riddle: [56,38,44,56,29] is '{}'".format(''.join(riddle_me_this([56, 38, 44, 56, 29], code_into_letter)))) + print("\nThe longest riddle is {}".format(riddle_me_this(longest_word, letter_into_code))) + print("Its solution is '{}'".format(longest_word)) + print("\nSee the text files for a complete riddle list, a complete word list, or an answer key with riddles and their solutions") diff --git a/solutions/FableT/poem.txt b/solutions/FableT/poem.txt new file mode 100755 index 0000000..5bcb0b1 --- /dev/null +++ b/solutions/FableT/poem.txt @@ -0,0 +1,29 @@ +a narrow fellow in the grass +occasionally rides; +you may have met him, did you not, +his notice sudden is. + +the grass divides as with a comb, +a spotted shaft is seen; +and then it closes at your feet +and opens further on. + +he likes a boggy acre, +a floor too cool for corn. +yet when a child, and barefoot, +i more than once, at morn, + +have passed, i thought, a whip-lash +unbraiding in the sun, +when, stooping to secure it, +it wrinkled, and was gone. + +several of nature's people +i know, and they know me; +i feel for them a transport +of cordiality; + +but never met this fellow, +attended or alone, +without a tighter breathing, +and zero at the bone. \ No newline at end of file