Skip to content

Commit

Permalink
pi
Browse files Browse the repository at this point in the history
  • Loading branch information
wpowers42 committed Dec 10, 2023
1 parent 2df4038 commit 4bc2216
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions simulations/pi/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// A constant pi up to 100 digits
const piValue = "141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067";


// Initialize an array to store the binary strings
const binaryStrings = [];

// Loop through each digit (0-9) to create the binary strings
for (let i = 0; i < 10; i++) {
const digit = i.toString();
let binaryString = "";

// Loop through the first 20 digits of pi
for (let j = 0; j < piValue.length; j++) {
// If the current digit matches the desired digit, add '1', otherwise '0'
binaryString += piValue[j] === digit ? "1" : "0";
}

// Push the binary string into the array
binaryStrings.push(parseInt(binaryString, 2));
}

// Print the binary strings
binaryStrings.forEach((binaryString, index) => {
console.log(`[${index}] = ${binaryString}`);
});

0 comments on commit 4bc2216

Please sign in to comment.