From 1789987e7d79b048739e8a1ec7eb40a27a077103 Mon Sep 17 00:00:00 2001 From: Swizec Teller Date: Wed, 10 Oct 2018 23:19:42 -0700 Subject: [PATCH] Warm to target temperature --- index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 7377be7..7ae98ac 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ const si = require("systeminformation"); +const mri = require("mri"); function collatz_step(n) { return n % 2 ? n / 2 : 3 * n + 1; @@ -18,15 +19,21 @@ async function readTemp() { return temp.main; } -async function thawMyCarrots() { +async function thawMyCarrots(targetTemp) { let temp = await readTemp(); - console.log(temp); + console.log(`Warming from ${temp} to ${targetTemp}`); - for (let n = 1; temp < 80; temp = await readTemp(), n += 1) { + for (let n = 1; temp < targetTemp; temp = await readTemp(), n += 1) { console.log("Current temp", temp); console.log(`Collatz takes ${collatz(n)} steps for n=${n}`); } } -thawMyCarrots(); +const args = process.argv.slice(2), + targetTemp = mri(args, { + alias: { temp: "t" }, + default: { temp: 85 } + }); + +thawMyCarrots(targetTemp.temp);