Skip to content

Instantly share code, notes, and snippets.

View rsp's full-sized avatar

Rafał Pocztarski rsp

View GitHub Profile
function inc(x) {
return x + 1;
}
function count(f) {
return f(inc)(0);
}
console.log(count(input1)); // should print 1
console.log(count(input2)); // should print 2
console.log(count(input3)); // should print 10
console.log(count(input4)); // should print 100
console.log(count(input5)); // should print 1000
console.log(count(f(input1))); // should print 0
console.log(count(f(input2))); // should print 1
console.log(count(f(input3))); // should print 9
console.log(count(f(input4))); // should print 99
console.log(count(f(input5))); // should print 999
@rsp
rsp / ifm-lw-r1-task.js
Last active November 29, 2017 19:02
inFullMobile Language Wars: Round 1 - Task Summary - See: https://gist.github.com/rsp/d8bdbafa09f24f99eebc8ed60fe205c8
/*
A task for inFullMobile Language Wars: Round 1
TL;DR
We need a function f that takes a and returns b:
b = f(a)
when:
@rsp
rsp / ifm-lw-r1-ojs-solution-1.js
Last active November 29, 2017 14:11
inFullMobile Language Wars: Round 1 - Old JavaScript Solution 1 by @rsp - See: https://gist.github.com/rsp/d8bdbafa09f24f99eebc8ed60fe205c8
function f(x) {
return function (y) {
return function (z) {
var r = z;
for (var i = 1; i++ < x(function (a) { return a + 1; })(0); r = y(r));
return r;
};
};
}
@rsp
rsp / ifm-lw-r1-js-solution-1.js
Last active November 29, 2017 14:12
inFullMobile Language Wars: Round 1 - JavaScript Solution 1 by @rsp - See: https://gist.github.com/rsp/d8bdbafa09f24f99eebc8ed60fe205c8
const f = x => y => z => {
let r = z;
for (let i = 1; i++ < x(a => a + 1)(0); r = y(r));
return r;
};
@rsp
rsp / ifm-lw-r1-ojs-solution-2.js
Last active November 29, 2017 14:11
inFullMobile Language Wars: Round 1 - Old JavaScript Solution 2 by @rsp - See: https://gist.github.com/rsp/d8bdbafa09f24f99eebc8ed60fe205c8
function e(a) {
return function (b) {
return function (c) {
return c ? e(b(a))(b)(c - 1) : a;
};
};
}
function f(a) {
return function (b) {
@rsp
rsp / ifm-lw-r1-js-solution-2.js
Last active November 29, 2017 14:12
inFullMobile Language Wars: Round 1 - JavaScript Solution 2 by @rsp - See: https://gist.github.com/rsp/d8bdbafa09f24f99eebc8ed60fe205c8
const e = a => b => c => c ? e(b(a))(b)(c - 1) : a;
const f = a => b => c => e(c)(b)(a(a => a + 1)(0) - 1);
@rsp
rsp / ifm-lw-r1-ojs-solution-3.js
Last active November 29, 2017 14:11
inFullMobile Language Wars: Round 1 - Old JavaScript Solution 3 by @rsp - See: https://gist.github.com/rsp/d8bdbafa09f24f99eebc8ed60fe205c8
function f(a) {
return function (b) {
return function (c) {
return a(function (d) {
return function (e) {
return e(d(b));
};
})(function (f) {
return c;
})(function (g) {
@rsp
rsp / ifm-lw-r1-js-solution-3.js
Last active November 29, 2017 14:13
inFullMobile Language Wars: Round 1 - JavaScript Solution 3 by @rsp - See: https://gist.github.com/rsp/d8bdbafa09f24f99eebc8ed60fe205c8
const f = a => b => c => a(d => e => e(d(b)))(f => c)(g => g);