Last active
August 23, 2017 01:27
-
-
Save AaronHarris/d42bdda39559f19f297951b07d9498b2 to your computer and use it in GitHub Desktop.
Includes scripts I've written to help solve puzzles during puzzle competitions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This was an around-the-world-in-80-days type problem where we were given places and had to filli n the blanks based on clues | |
var cities = ["Allahabad", "Battleship", "Brindisi", "Cadet", "Calcutta", "Charcoal", "Dove", | |
"Gunmetal", "Lampblack", "Omaha", "Paris", "Paynes", "Pewter", | |
"Slate", "Spanish", "Suez", "Whitewash", "Yokohama"].map(s => s.toLowerCase()); | |
arriving = ["liverpool", "silver", "singapore", "gainsboro", "hongkong", "kholby", "chalk", 8, 9, 10, [9,10] [7,8], [4,8], 5, "san francisco", [5, 10], [6,10], "new york", "eigengrau"]; | |
answers = | |
function lookup_word(source, range, common_num) { | |
var solns = []; | |
for (var w of cities) { | |
if (typeof range == 'number' && w.length == range) { | |
intersect = _.intersection(w.split(''),source.split('')); | |
if (common_num == null && intersect.length >= 3 || intersect.length == common_num) { | |
solns.push(w); | |
continue; | |
} | |
} | |
intersect = _.intersection(w.split(''),source.split('')); | |
if (intersect.length >= range[0] && intersect.length <= range[1] && (common_num == null && intersect.length >= 3 || intersect.length == common_num) ) { | |
solns.push(w); | |
continue; | |
} | |
} | |
return solns; | |
} | |
// This was a word-processing problem where it was needed to find where a pair of letters in one word would overlap with a pair in another word | |
// Load the full build of lodash | |
var _ = require('lodash'); | |
var ans = ["WILDTIME", "THEMOUSETRAP", "SATORI", "GEORGELEUTZ", "UNATTACHED", "ASTROLABE"]; | |
output = {}; | |
for (let i = 0; i < ans.length; i++) { | |
let word = ans[i]; | |
let others = ans.filter(w => w !== word); | |
output[word] = {} | |
for (let j = 0; j < word.length-1; j++) { | |
let segment = word.slice(j, j+2); | |
let matches = others.filter(w => w.includes(segment)); | |
if (!_.isEmpty(matches)) { output[word][segment] = matches; } | |
} | |
} | |
console.log(output); | |
// Output | |
// { | |
// "WILDTIME": {}, | |
// "THEMOUSETRAP": { | |
// "HE": [ | |
// "UNATTACHED" | |
// ], | |
// "TR": [ | |
// "ASTROLABE" | |
// ] | |
// }, | |
// "SATORI": { | |
// "AT": [ | |
// "UNATTACHED" | |
// ], | |
// "OR": [ | |
// "GEORGELEUTZ" | |
// ] | |
// }, | |
// "GEORGELEUTZ": { | |
// "OR": [ | |
// "SATORI" | |
// ] | |
// }, | |
// "UNATTACHED": { | |
// "AT": [ | |
// "SATORI" | |
// ], | |
// "HE": [ | |
// "THEMOUSETRAP" | |
// ] | |
// }, | |
// "ASTROLABE": { | |
// "TR": [ | |
// "THEMOUSETRAP" | |
// ] | |
// } | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment