done
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
# nothing
|
||||
|
||||
A WIP implementation of Tom Stuart’s [Programming with Nothing](https://www.youtube.com/watch?v=VUhlNx_-wYk)
|
||||
challenge in ES6. I got to factorial, and will try to do the whole thing soon.
|
||||
Am implementation of Tom Stuart’s [Programming with Nothing](https://www.youtube.com/watch?v=VUhlNx_-wYk)
|
||||
challenge in ES6.
|
||||
|
||||
Look at [`example.js`](/example.js) if you want to see the thing in action.
|
||||
|
10
example.js
Normal file
10
example.js
Normal file
@@ -0,0 +1,10 @@
|
||||
const nothing = require('./nothing.js');
|
||||
const helper = require('./nothing-helper.js');
|
||||
const fizzbuzz = (x) => {
|
||||
let a = [];
|
||||
for (let i = 1; i <= x; i++) {
|
||||
a.push(i % 15 ? i % 5 ? i % 3 ? i : "Fizz" : "Buzz" : "FizzBuzz");
|
||||
}
|
||||
return a;
|
||||
};
|
||||
console.log(helper.check_represent(nothing.FIZZBUZZ(helper.representation_of(100)), fizzbuzz(100)));
|
@@ -41,7 +41,7 @@ const zip = (a, b) => a.map((e, i) => [e, b[i]]);
|
||||
const check_represent = function(r, v) {
|
||||
if (typeof v == "number") return to_int(r) == v;
|
||||
if (typeof v == "boolean") return to_bool(r) == v;
|
||||
if (typeof v == "string") { console.log("checking ", to_array(r).map(to_int), " against ", v); return to_string(r) == v; }
|
||||
if (typeof v == "string") return to_string(r) == v;
|
||||
if (Array.isArray(v)) {
|
||||
let a = to_array(r);
|
||||
return a.length == v.length && zip(a, v).every(([r, v]) => check_represent(r,v));
|
||||
@@ -49,5 +49,5 @@ const check_represent = function(r, v) {
|
||||
throw Error(`Oops, I don’t know how check this: ${v}`);
|
||||
};
|
||||
module.exports = {
|
||||
to_string, to_array, representation_of, check_represent, to_int, to_char
|
||||
representation_of, check_represent
|
||||
};
|
||||
|
@@ -25,7 +25,7 @@ const Y = f => (x => f(x(x)))(x => f(x(x))); // lazy recursion
|
||||
const Z = f => (x => f(_ => x(x)(_)))(x => f(_ => x(x)(_))); // eager recursion
|
||||
const FACT = Z(f => n => IF(IS_ZERO(n))(ONE)(_ => MULT(n)(f(DEC(n)))(_)));
|
||||
const DIV = Z(f => n => m => IF(IS_LEQ(m)(n))(_ => INC(f(SUB(n)(m))(m))(_))(ZERO));
|
||||
const MOD = Z(f => n => m => IF(IS_LEQ(m)(n))(_ => f(SUB(n)(m))(m)(_))(m));
|
||||
const MOD = Z(f => n => m => IF(IS_LEQ(m)(n))(_ => f(SUB(n)(m))(m)(_))(n));
|
||||
const PAIR = x => y => f => f(x)(y);
|
||||
const LEFT = p => p(x => y => x);
|
||||
const RIGHT = p => p (x => y => y);
|
||||
@@ -48,8 +48,8 @@ const DOUBLE_ALL = l => MAP(l)(MULT(TWO));
|
||||
const TEN = INC(MULT(THREE)(THREE));
|
||||
const RADIX = TEN;
|
||||
const FOUR = INC(THREE);
|
||||
const FIVE = INC(INC(THREE));
|
||||
const FIFTEEN = MULT(THREE)(FIVE);
|
||||
const FIVE = INC(FOUR);
|
||||
const FIFTEEN = ADD(FIVE)(TEN);
|
||||
const FIZZ = MAP(UNSHIFT(UNSHIFT(UNSHIFT(UNSHIFT(EMPTY)(FOUR))(FOUR))(TWO))(ONE))(ADD(RADIX));
|
||||
const BUZZ = MAP(UNSHIFT(UNSHIFT(UNSHIFT(UNSHIFT(EMPTY)(FOUR))(FOUR))(THREE))(ZERO))(ADD(RADIX));
|
||||
const FIZZBUZZ = n => MAP(RANGE(ONE)(n))(m =>
|
||||
|
Reference in New Issue
Block a user