Skip to content

Instantly share code, notes, and snippets.

View kyleplo's full-sized avatar
💭
doing stuff

kyleplo

💭
doing stuff
View GitHub Profile
@kyleplo
kyleplo / README.md
Created November 26, 2023 19:40
What if "The Twelve Days of Christmas" had even more gifts?

In the song "The Twelve Days of Christmas," a total of 364 gifts are given. However, the majority of those gifts are of living things (turtle doves, maids a milking, etc). Don't those creatures deserve gifts too? Then how many gifts would there be?

This is a programming problem to find the answer. Assume that every gift given get all of the gifts of a lower number than it (ex. a French hen gets two turtle doves and a partridge in a pear tree). Those gifts also need gifts though (ex. those two turtle doves also get their own partridges in pear trees), and so on, all the way down. Golden rings however, being inanimate objects, do not need any gifts. Additionally, partridges in pear trees do not get any gifts, as they are the first gift. With all of these additional gifts, how many gifts would be given in total through the course of the song?

Hints

  • Dynamic programming is going to be your friend here
  • First figure out how to calculate the 364 gifts in the normal version of the song, then build off of that
// assumes that wordList is a string containing the latest Wordle word list, which can be found at https://gist.githubusercontent.com/dracos/dd0668f281e685bad51479e5acaadb93/raw/valid-wordle-words.txt
// if running in the console of that page, uncomment the following line
// const wordList = document.body.textContent;
const words = wordList.split("\n");
const scores = {};
words.forEach(word => {
if(word.length !== 5){
return;// sanity check
@kyleplo
kyleplo / borders.json
Created September 11, 2022 23:34
U.S. State Borders
{
"wa": ["or", "id"],
"or": ["id", "wa", "nv", "ca"],
"ca": ["or", "nv", "az"],
"id": ["mt", "wy", "ut", "nv", "or", "wa"],
"nv": ["or", "id", "ut", "az", "ca"],
"mt": ["nd", "sd", "wy", "id"],
"wy": ["sd", "ne", "co", "ut", "id", "mt"],
"ut": ["id", "wy", "co", "az", "nv"],
"az": ["ca", "nv", "ut", "nm"],
@kyleplo
kyleplo / walls-and-gates-solution.js
Created June 29, 2022 23:22
Walls and Gates Solution
var maze = [
[Infinity, -1, 0, Infinity],
[Infinity, Infinity, Infinity, -1],
[Infinity, -1, Infinity, -1],
[0, -1, Infinity, Infinity]
];
var trackers = [];
maze.forEach((row, y) => {
// made for use with https://www.wordleunlimited.com/
// run it in the console (Ctrl+Shift+J or Cmnd+Option+J) and it will attempt to solve
const words = "aahedaaliiaarghabacaabaciabackabaftabakaabampabaseabashabateabayaabbasabbesabbeyabbotabeamabeleabetsabhorabideabledablerablesabmhoabodeabohmaboilabomaaboonabortaboutaboveabrisabuseabutsabuzzabyesabysmabyssacariacerbacetaachedachesachooacidsacidyacingaciniackeeacmesacmicacnedacnesacockacoldacornacredacresacridactedactinactoracuteacylsadageadaptaddaxaddedadderaddleadeemadeptadieuadiosaditsadmanadmenadmitadmixadobeadoboadoptadoreadornadownadozeadultaduncadustadytaadzedadzesaeciaaedesaegisaeonsaerieafarsaffixafireafootaforeafoulafritafteragainagamaagapeagarsagateagaveagazeageneagentagersaggeraggieaggroaghasagileagingagiosagismagistagitaagleeagletagleyaglowagmasagoneagonsagonyagoraagreeagriaaguesaheadahingaholdahullaidedaideraidesailedaimedaimeraioliairedairerairnsairthairtsaisleaitchaiverajivaajugaakeesakelaakenealackalamoalandalanealangalansalantalarmalaryalat
String.prototype.isPalindrome = function (){
if(this.length % 2 === 0){
return this.slice(0, (this.length / 2)) === this.slice((this.length / 2)).split("").reverse().join("");
}else{
return (this.slice(0, Math.floor(this.length / 2)) === this.slice(Math.ceil(this.length / 2)).split("").reverse().join(""))
}
}
@kyleplo
kyleplo / dihybrid-punnet-generator.js
Last active January 10, 2021 22:39
Dihybrid Punnet Generator written in JavaScript, because I was too bored to do it manually in biology class. Not sure if writing this saved me any time, but it works.
/*
To use, run the function where m and f are the genotypes of the parents, and c is an object of the alleles and what they do. For example:
generatePunnet("RRBb","rrbb",{"R":"running","r":"waltzing","B":"black", "b":"brown"})
will output:
R: running
r: waltzing
B: black
b: brown
rb rb rb rb
@kyleplo
kyleplo / melons-in-the-desert.js
Last active September 18, 2020 12:18
Watermelons in the Desert You live in a desert oasis and grow miniature watermelons that are worth a great deal of money, if you can get them to the market 15 kilometers away across the desert. Your harvest this year is 45 melons, but you have no way to get them to the market, except to carry them across the desert. You have a backpack that hold…
var dropped = [45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var log = [];
var result = 15;
var pos = 0;
var held = 0;
var error = false;
var attempt = 0;
var done = false;
var doerrors = false;// set to true for error messages
function reset(){