Skip to content

Instantly share code, notes, and snippets.

@activedecay
Created September 11, 2019 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save activedecay/ba3c37522efa0dc7cb222e2dc453853a to your computer and use it in GitHub Desktop.
Save activedecay/ba3c37522efa0dc7cb222e2dc453853a to your computer and use it in GitHub Desktop.
/* this script will slightly back up production, but that can be
easily solved by adding some storage containers between belts */
const source = parseInt(process.argv[2]);
const begin = { source, nodes: [] };
const splits = [2, 3];
const target = parseInt(process.argv[3]);
let gold = false;
function recurse(current = begin, depth = 1) {
let nodes = current.nodes;
let path = false;
for (let split of splits) {
// with minor rounding errors, but maximize production efficiency
const diverted = Math.floor(current.source / split);
console.info('try', current.source, 'by', split, 'got', diverted);
const found = diverted === target;
path = path || found;
let n = {
up: current.source,
source: diverted,
split,
nodes: [],
depth,
};
if (found) {
console.info('bingo!');
n.gold = gold = true;
}
if (n.source >= target) nodes.push(n);
if (diverted > target) path = path || recurse(n, depth + 1);
}
current.path = path;
return path;
}
recurse();
console.info('---')
console.info(gold ? 'to' : 'you can not', 'get from', begin.source, 'to', target);
function extract(nodes = begin.nodes) {
for (let n of nodes) {
if (n.path || n.gold) console.info('at depth', n.depth, 'split', n.up, 'by', n.split, 'to', n.source);
extract(n.nodes);
}
}
extract();
// console.info(JSON.stringify(begin, null, 1))
/**
$ ./satisfactory.js 240 13
try 240 by 2 got 120
try 120 by 2 got 60
try 60 by 2 got 30
try 30 by 2 got 15
try 15 by 2 got 7
try 15 by 3 got 5
try 30 by 3 got 10
try 60 by 3 got 20
try 20 by 2 got 10
try 20 by 3 got 6
try 120 by 3 got 40
try 40 by 2 got 20
try 20 by 2 got 10
try 20 by 3 got 6
try 40 by 3 got 13
bingo!
try 240 by 3 got 80
---
to get from 240 to 13
at depth 1 split 240 by 2 to 120
at depth 2 split 120 by 3 to 40
at depth 3 split 40 by 3 to 13
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment