Skip to content

Instantly share code, notes, and snippets.

View gkucmierz's full-sized avatar
💻

Grzegorz Kućmierz gkucmierz

💻
View GitHub Profile
// 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
};
// https://hackernoon.com/how-does-rsa-work-f44918df914b
const key = {
mod: 14,
pub: 5,
prv: 11,
};
const msg = 'hello';
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;
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;
// 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;
// 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;
@gkucmierz
gkucmierz / List of over 1000 Polish names
Created November 29, 2022 07:51 — forked from hywak/List of over 1000 Polish names
php array of Polish names
$names = array('Apollona',
'Apollina',
'Apolonia',
'Arabella',
'Ariadna',
'Arleta',
'Arnolda',
'Astryda',
'Atena',
'Augusta',
[
"Kij bejsbolowy i piłka łącznie kosztują 1,10. Kij kosztuje o 1 dolar więcej niż piłka. Jaka w takim razie jest cena piłki?",
"5 urzqdzen produkuje 5 gadżetów w 5 minut. Jak długo zajmie 100 maszyn zrobienie 100 gadżetów?",
"W jeziorze znajdują sie liliowce. Każdego dnia stają się większe, podwajając swoją objętość. Jesli w 48 dni lisć pokryje całe jezioro, to ile czasu zajmie, by liść zakrył połowę jeziora?"
]
// http://www.pleacher.com/handley/puzzles/blackhol.html
const randBI = () => {
const maxLen = 10_000;
return BigInt(new Array(Math.round(Math.random() * maxLen))
.fill(0)
.map(_ => Math.round(Math.random() * 10) % 10)
.join(''))
};
const kaprekarNext = n => {
const a = [...n + ''].map(n => +n);
a.sort((a, b) => b - a);
return +a.join('') - +a.reverse().join('');
};
const kaprekarLoop = n => {
let last;
while (last !== n) {
last = n;