This file contains 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
// https://instacode.app/run/FAYw9gdgzgLgBAFQJIFkCiBlOBeOBGAUwHYBuUSWODBAJRzgHIEALASyjgAcAnMAKwIh4AdwCGHbgVEAbVgC8CAEzjiuo7vDAAzOAFsAnio2sQ0ggzLlo8SZ2miQBegG1gcOLG44AfB5jcAOlt7RwBBaWkACgZGABpGAFoGAEpYtz8vbF9PIII7BwJIgHo4IoBzeIYk1PTPHwzc-MdigB0AdXLK6rSAXUtggoDdUU5IyK0IeNZk+oBvdPBrOBg8egBqCAJhOAARURgCMnctMC9Is3hWegAGEjgrgB5EVEw7tbXpuHn3Y4hI6hoySOcAAvgsKPAYAAmdabbZ7A7AxZQMBmALSMBlSIAAwA8pwYKxIHAACSzVgggBcy1YugI1LJ0ISKxB2KBwBB7OAQA | |
const TIMES = 1e7; | |
const STR = 'This project was realized as part of my article'; | |
const replace = [ | |
str => str.replaceAll(' ', '-'), | |
str => str.replace(/ /g, '-'), | |
str => str.replace(/\W/g, '-'), |
This file contains 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
// https://projecteuler.net/problem=57 | |
const squareRoot = n => { | |
const STEPS = 100; | |
let res = 0; | |
for (let i = 0; i < STEPS; ++i) { | |
res = (n-1) / (2 + res); | |
} | |
return res + 1; | |
}; |
This file contains 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
const M = (n, verbose = false) => { | |
const steps = n - 2; | |
const prime = 2n ** BigInt(n) - 1n; | |
verbose && console.log('prime: ', prime); | |
let s = 4n; | |
for (let i = 0; i < steps; ++i) { | |
s = (s ** 2n - 2n) % prime; | |
verbose && console.log(i, s); | |
} |
This file contains 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
// this code pasted on Project Euler console site shows difficulty of tasks using colors | |
const round = n => Math.round(n); | |
[...document.querySelectorAll('.smaller')].forEach(e=>{; | |
const diff = (+e.innerHTML.match(/\d{1,3}/)[0]) / 100 * 255; | |
const color = `rgba(${diff},${255-diff},0,1)`; | |
e.parentNode.parentNode.parentNode.style.backgroundColor = color; | |
}); |
This file contains 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
// https://www.codewars.com/kata/5b84e44d6aa40d1ca5000124/train/bf | |
const bf = strCode => { | |
let orders = ',.[]<>+-'.split(''); | |
let regex = { | |
clean: new RegExp('[^' + escapeRegExp(orders.join('')) + ']', 'g'), | |
value: /[\+\-]+/g, | |
pointer: /[\<\>]+/g, | |
instruction: /[0-9]*./g, | |
zero: /\[(\-|\+)\]/g | |
}; |
This file contains 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
function factors(n) { | |
let max = Math.floor(Math.sqrt(n)); | |
let res = []; | |
for (let i = 2; i <= max; ++i) { | |
if (n % i === 0) { | |
res.push(i); | |
n /= i; | |
max = Math.floor(Math.sqrt(n)); | |
i = (Math.min(...res) || 2) - 1; |
This file contains 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
const singleNumber = nums => { | |
let ones = 0; | |
let twos = 0; | |
let notThrees = 0; | |
for (let n of nums) { | |
twos |= (ones & n); | |
ones ^= n; | |
notThrees = ~(ones & twos); | |
ones &= notThrees; | |
twos &= notThrees; |
This file contains 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
// Eulers bricks (brute force) | |
const check = (a, b, c) => { | |
if (Math.hypot(a, b) % 1 !== 0) return false; | |
if (Math.hypot(b, c) % 1 !== 0) return false; | |
if (Math.hypot(c, a) % 1 !== 0) return false; | |
return Math.hypot(a, b, c); | |
} | |
const MAX = 1e3; |
This file contains 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
// https://youtu.be/HDre_o2qz1o?t=238 | |
// Dziadek i babcia mają razem 126 lat, a dziadek ma dwa razy tyle, | |
// ile babcia miała wtedy kiedy dziadek miał tyle ile babcia ma obecnie. | |
// Ile lat ma babcia? | |
const test = (x, diff) => { | |
const bago = x; | |
const d = bago * 2; | |
const b = bago + diff; |
This file contains 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
$names = array('Apollona', | |
'Apollina', | |
'Apolonia', | |
'Arabella', | |
'Ariadna', | |
'Arleta', | |
'Arnolda', | |
'Astryda', | |
'Atena', | |
'Augusta', |
NewerOlder