Last active
June 7, 2022 08:17
-
-
Save Svehla/aa42802869e944f4530c3a2c08bf3970 to your computer and use it in GitHub Desktop.
assignment: https://www.youtube.com/watch?v=HyRjuPP9S3o
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
var optSafeId = Array.from({ length: 1300 - 13 + 1 }, (_, i) => i + 13) | |
var perfectCube = i => Math.round(i**(1/3))**3 === i // float fuckup | |
var perfectSquare = i => Math.round(i**(1/2))**2 === i // float fuckup | |
var lg500 = i => i > 500 | |
var secDig1 = i => i.toString().substr(1, 1) == '1' | |
var truth = (isTruth, val) => isTruth ? val : !val | |
// combinatorics hacked by bin numbers | |
var possibleResponses = Array.from({ length: 2 ** 4 }) | |
.map((_, i) => i.toString(2).padStart(4, '0')) | |
.map(([q1, q2, q3, q4]) => [q1 === '1', q2 === '1', q3 === '1', q4 === '1']) | |
var getOptSafeIdFor3Rules = ([q1, q2, q3]) => optSafeId | |
.filter(i => truth(q1, lg500(i))) | |
.filter(i => truth(q2, perfectSquare(i))) | |
.filter(i => truth(q3, perfectCube(i))) | |
var getOptSafeIdFor4Rules = ([q1, q2, q3, q4]) => getOptSafeIdFor3Rules([q1, q2, q3]).filter(i => truth(q4, secDig1(i))) | |
var lupici = possibleResponses | |
.map((rules) => ({ rules, optionsAfterThirdQ: getOptSafeIdFor3Rules(rules) })) | |
.filter((i) => i.optionsAfterThirdQ.length === 2) // check that only 2 options left before fourth question was asked | |
.map(i => ({ ...i, finalOptions: getOptSafeIdFor4Rules(i.rules) })) | |
.filter((i) => i.finalOptions.length === 1) | |
var benga = lupici | |
.flatMap(i => [ | |
// check all options if fourth question is true | false | |
[[!i.rules[0], !i.rules[1], i.rules[2], true], i], | |
[[!i.rules[0], !i.rules[1], i.rules[2], false], i] | |
]) | |
.map(([rules, lupic]) => ({ | |
rules, | |
lupic, | |
finalOptions: getOptSafeIdFor4Rules(rules), | |
})) | |
.filter(({ finalOptions }) => finalOptions.length === 1) | |
console.log('benga found options: \n', benga.map(i => i.finalOptions.join(',')).join('\n')) |
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
var perfectCube = n => Math.floor(n**(1/3)) === n**(1/3) | |
/* | |
>>> np.cbrt([64]) | |
array([4.]) | |
>>> 64 ** (1/3) | |
3.9999999999999996 | |
>>> import numpy as np | |
>>> np.cbrt(64) | |
4.0 | |
*/ | |
/* | |
64 ** (1/3) === Math.cbrt(64) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment