Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

gkucmierz

🏠
Working from home
Block or report user

Report or block gkucmierz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gkucmierz
gkucmierz / square_root.js
Last active Aug 11, 2019
Calculating square root - BigInt
View square_root.js
n = 123n**42n
l = BigInt(n.toString().substr(0, n.toString().length/2));
while (l*l - n !== 0n) {
l = (l + n / l) / 2n;
}
console.log(l);
console.log(l*l);
console.log(n);
View to_upper_case.bf
,[
>1 --[-->+<] >2 ----- <1 set 122 to 2 <0
>>2 [-<<->>] sub 122 from char <<0
>1 ++++++++++ ++++++++++ ++++++ set 26 cnt <0
>1 [-
<0 [->>+>+<<<] dup char 2&3 >1
>>3 [-<<<+>>>] recov char to 0 <<1
1 [->>+>+<<<] dup cnt 3&4
>>>4 [-<<<+>>>] recov cnt <<<1
View get_dec_input.bf
// get dec input from 0 to 255 and store it in second cell
++++++++++ ++++++++++ ++++++++++ ++++++++++ ++++++++ 48 0 dec
[
mul by 10:
>1 [-> +++++ +++++ <] >2 [-<+>] <<1
---------- ---------- ---------- ---------- -------- 48
[->+<] add to sum
,
]
View Project Euler 2.js
let f = [1, 1];
let sum = 0;
while(f[0] < 4e6){
f.push(f[0]+f[1]);
let e = f.shift();
sum += e % 2 === 0 ? e : 0;
}
console.log(sum);
View BitArray.js
let BitArray = function(size) {
let arr = new Uint16Array(size >> 4);
let o = new Uint16Array(16);
let z = new Uint16Array(16);
for (let i = 0; i < 16; ++i) {
o[i] = 1 << i;
z[i] = o[i] ^ ((1<<16)-1);
}
return {
View convert_canvas_to_png.js
var canvas = document.getElementsByTagName("canvas")[0];
var img = canvas.toDataURL("image/png");
document.write('<img src="'+img+'"/>');
View solidity_token.sol
pragma solidity ^0.4.8;
// kovan: 0x9af4ad4bad67f640a1416ef448640f906209ba0e
contract Token {
string public name;
uint8 public decimals;
string public symbol;
View wallet_balance_manager.js
const walletBalanceChanged = balance => {
const GAS_PRICE = 1e10;
const TX_GAS = 40e3;
const TX_PRICE = GAS_PRICE * TX_GAS;
let txsNum = balance / TX_PRICE;
const txsLvls = [2, 10, 20];
if (txsNum <= 2) {
@gkucmierz
gkucmierz / nth-permutation.js
Created Aug 20, 2017 — forked from bcherny/nth-permutation.js
get nth permutation of a string
View nth-permutation.js
// (as: Array[Array[A]]) => Array[A]
function flatten (as) {
return as.reduce((a, b) => a.concat(b), [])
}
// (as: Array[A], a: A) => Array[A]
function without (as, a) {
const bs = as.slice(0)
bs.splice(as.indexOf(a), 1)
return bs
You can’t perform that action at this time.