Created
April 18, 2020 19:02
-
-
Save mattmontgomery/17e01f66f4d314d9a62268aa94f4add4 to your computer and use it in GitHub Desktop.
A quick stab at the number of possibilities for a starting Onitama outlay.
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
import { Set } from "typescript-collections"; | |
const cards: string[] = [ | |
"Boar", | |
"Cobra", | |
"Crab", | |
"Crane", | |
"Dragon", | |
"Eel", | |
"Elephant", | |
"Frog", | |
"Goose", | |
"Horse", | |
"Mantis", | |
"Monkey", | |
"Ox", | |
"Rabbit", | |
"Rooster", | |
"Tiger", | |
]; | |
const sets = new Set<string>(); | |
cards.forEach((card1, idx) => { | |
cards.forEach((card2, idx2) => { | |
cards.forEach((card3, idx3) => { | |
cards.forEach((card4, idx4) => { | |
cards.forEach((card5, idx5) => { | |
const set = new Set<string>(); | |
set.add(card1); | |
set.add(card2); | |
set.add(card3); | |
set.add(card4); | |
set.add(card5); | |
if (set.size() === 5) { | |
sets.add(set.toArray().sort().join(",")); | |
} | |
}); | |
}); | |
}); | |
}); | |
}); | |
console.log("Sets", sets.size()); | |
const arrangedSets = new Set<string>(); | |
sets.forEach((set) => { | |
const arrSet = set.split(","); | |
arrSet.forEach((card1) => { | |
arrSet.forEach((card2) => { | |
arrSet.forEach((card3) => { | |
arrSet.forEach((card4) => { | |
arrSet.forEach((card5) => { | |
const possibleSet = new Set<string>(); | |
[card1, card2, card3, card4, card5].forEach((card) => | |
possibleSet.add(card) | |
); | |
if (possibleSet.size() !== 5) { | |
return; | |
} | |
const arrangedSet = new Set<string>(); | |
const firstSet = new Set<string>(); | |
const secondSet = new Set<string>(); | |
const remainder = new Set<string>(); | |
firstSet.add(`a:${card1}`); | |
firstSet.add(`a:${card2}`); | |
secondSet.add(`b:${card3}`); | |
secondSet.add(`b:${card4}`); | |
remainder.add(`c:${card5}`); | |
[ | |
...firstSet.toArray(), | |
...secondSet.toArray(), | |
...remainder.toArray(), | |
].forEach((c) => arrangedSet.add(c)); | |
if (arrangedSet.size() === 5) { | |
if (arrangedSets.size() % 100 === 0) { | |
console.log("Up to ", arrangedSets.size()); | |
} | |
arrangedSets.add(arrangedSet.toArray().sort().join()); | |
} | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
console.log("Sets", sets.size()); | |
console.log("Arranged sets", arrangedSets.size()); | |
console.log("Arranged sets sample", arrangedSets.toArray().slice(0, 100)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment