mirror of
https://github.com/Swizec/thaw-carrots.git
synced 2024-09-29 10:45:37 +00:00
Using collatz conjecture to slightly warm things
This commit is contained in:
parent
eb58752f4b
commit
8e83057cb7
32
index.js
Normal file
32
index.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
const si = require("systeminformation");
|
||||
|
||||
function collatz_step(n) {
|
||||
return n % 2 ? n / 2 : 3 * n + 1;
|
||||
}
|
||||
|
||||
function collatz(n) {
|
||||
let count = 0;
|
||||
while (n !== 1) {
|
||||
n = collatz_step(n);
|
||||
count += 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
async function readTemp() {
|
||||
const temp = await si.cpuTemperature();
|
||||
return temp.main;
|
||||
}
|
||||
|
||||
async function thawMyCarrots() {
|
||||
let temp = await readTemp();
|
||||
|
||||
console.log(temp);
|
||||
|
||||
for (let n = 1; temp < 80; temp = await readTemp(), n += 1) {
|
||||
console.log("Current temp", temp);
|
||||
console.log(`Collatz takes ${collatz(n)} steps for n=${n}`);
|
||||
}
|
||||
}
|
||||
|
||||
thawMyCarrots();
|
23
package-lock.json
generated
Normal file
23
package-lock.json
generated
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "thaw-carrots",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"mri": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/mri/-/mri-1.1.1.tgz",
|
||||
"integrity": "sha1-haom09ru7t+A3FmEr5XMXKXK2fE="
|
||||
},
|
||||
"osx-temperature-sensor": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/osx-temperature-sensor/-/osx-temperature-sensor-1.0.3.tgz",
|
||||
"integrity": "sha512-iqgD538Qp6F/RzV+kDeDsoNlSZIFShuS92DE4Zw9VwronG5qWsQIrDzvd777Bv1/+quF0ItR5ooelonENN5AgQ=="
|
||||
},
|
||||
"systeminformation": {
|
||||
"version": "3.45.7",
|
||||
"resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-3.45.7.tgz",
|
||||
"integrity": "sha512-MVTzuYCrrjS3o91oiEBZ7z4F+lw6lg7GXK8VgTaJLdCMTxXyJZCQYKr7GMYgt72y5JCYWz/kWc8a66RNjRnCkQ=="
|
||||
}
|
||||
}
|
||||
}
|
30
package.json
Normal file
30
package.json
Normal file
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"name": "thaw-carrots",
|
||||
"version": "1.0.0",
|
||||
"description": "Thaw carrots by warming up your laptop to a specific temperature",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Swizec/thaw-carrots.git"
|
||||
},
|
||||
"keywords": [
|
||||
"node",
|
||||
"cpu",
|
||||
"cli",
|
||||
"temperature"
|
||||
],
|
||||
"author": "Swizec Teller",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Swizec/thaw-carrots/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Swizec/thaw-carrots#readme",
|
||||
"dependencies": {
|
||||
"mri": "^1.1.1",
|
||||
"osx-temperature-sensor": "^1.0.3",
|
||||
"systeminformation": "^3.45.7"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue