Skip to content

Instantly share code, notes, and snippets.

@tuscen
Last active June 25, 2021 03:32
Show Gist options
  • Select an option

  • Save tuscen/4709ac6daec6ebf5d059 to your computer and use it in GitHub Desktop.

Select an option

Save tuscen/4709ac6daec6ebf5d059 to your computer and use it in GitHub Desktop.

CodeWars Kata

Description:

In order to stop too much communication from happening, your overlords declare that you are no longer allowed to use certain functionality in your code!

Disallowed functionality:

  • Strings
  • Numbers
  • Regular Expressions
  • Functions named "Hello", "World", "HelloWorld" or anything similar.
  • Object keys named "Hello", "World", "HelloWorld" or anything similar.

Without using the above, output the string "Hello World!" to prove that there is always a way.


The solution inspired by Tom Stuart' "Programming with nothing" great article.

const helloWorld = () => {
const zero = p => x => x;
const one = p => x => p(zero(p)(x));
const two = p => x => p(one(p)(x));
const three = p => x => p(two(p)(x));
const four = p => x => p(three(p)(x));
const five = p => x => p(four(p)(x));
const six = p => x => p(five(p)(x));
const seven = p => x => p(six(p)(x));
const eight = p => x => p(seven(p)(x));
const nine = p => x => p(eight(p)(x));
const zeroLiteral = +[];
const oneLiteral = !+[];
const toInteger = number => number(x => x + oneLiteral)(zeroLiteral);
const charCodes = [
[seven, two],
[one, zero, one],
[one, zero, eight],
[one, zero, eight],
[one, one, one],
[three, two],
[eight, seven],
[one, one, one],
[one, one, four],
[one, zero, eight],
[one, zero, zero],
[three, three]
];
return charCodes.map(codes => codes.map(fn => toInteger(fn).toString()).join(String()))
.map(number => String.fromCharCode(number))
.join(String())
}
// -----------------------
console.log(helloWorld()); // => "Hello World!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment