From 32f4fcf16981704931ee11073145d7aa1f82c51b Mon Sep 17 00:00:00 2001 From: fablet Date: Wed, 20 May 2015 23:30:18 -0700 Subject: [PATCH 1/2] Fable's solution to Python Poetry --- .idea/.name | 1 + .idea/encodings.xml | 5 + .idea/misc.xml | 5 + .idea/modules.xml | 9 + .idea/puzzles.iml | 9 + .idea/scopes/scope_settings.xml | 5 + .idea/vcs.xml | 7 + .idea/workspace.xml | 404 ++++++++++++++++++++++++++++++++ poetry.html | 1 + solutions/FableT/PyPoetry.py | 74 ++++++ solutions/FableT/poem.txt | 29 +++ 11 files changed, 549 insertions(+) create mode 100755 .idea/.name create mode 100755 .idea/encodings.xml create mode 100755 .idea/misc.xml create mode 100755 .idea/modules.xml create mode 100755 .idea/puzzles.iml create mode 100755 .idea/scopes/scope_settings.xml create mode 100755 .idea/vcs.xml create mode 100755 .idea/workspace.xml mode change 100644 => 100755 poetry.html create mode 100755 solutions/FableT/PyPoetry.py create mode 100755 solutions/FableT/poem.txt 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 @@ + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100755 index 0000000..490afa6 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100755 index 0000000..5d8dfc6 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/puzzles.iml b/.idea/puzzles.iml new file mode 100755 index 0000000..68c3f23 --- /dev/null +++ b/.idea/puzzles.iml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100755 index 0000000..0d5175c --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100755 index 0000000..ab55cf1 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100755 index 0000000..1d007e5 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,404 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1432189490228 + 1432189490228 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/poetry.html b/poetry.html old mode 100644 new mode 100755 index 648e44a..31b2d63 --- a/poetry.html +++ b/poetry.html @@ -76,6 +76,7 @@

Solutions

  • Matt Page-Lieberman's solution is pythonpoetry.py
  • Aaron Hill's solution is poetry.py
  • Josh McGrath's solution is poetry.py
  • +
  • Fable Turas's solution is PyPoetry.py
  • 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 From 80a2ceb40d57b6dfc7687514352dd37c12719de4 Mon Sep 17 00:00:00 2001 From: fablet Date: Sat, 30 May 2015 10:13:32 -0700 Subject: [PATCH 2/2] added gitignore file --- .gitignore | 47 ++++++++++++++++++++++++++++ .idea/workspace.xml | 76 ++++++++++++++++++++------------------------- 2 files changed, 80 insertions(+), 43 deletions(-) create mode 100755 .gitignore 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/workspace.xml b/.idea/workspace.xml index 1d007e5..a8791fc 100755 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,14 +2,7 @@ - - - - - - - - + @@ -17,10 +10,20 @@ + + + + + + + + + + @@ -53,16 +56,26 @@ - + - + + + + + + + + + + + @@ -78,6 +91,7 @@ @@ -131,38 +145,6 @@