2 ms·
Sometimes a simpler language beats one with problem specific primitives. For instance, Haskell is well equipped to do a short prime number generator with nubBy
by tromp 5y ago
Sometimes a simpler language beats one with problem specific primitives. For instance, Haskell is well equipped to do a short prime number generator with
nubBy(((>1).).gcd)[2..]
where nub removes duplicates from a list according to some notion of equivalence, which in this case is having a greatest common divisor greater than one.
That's just 23 bytes. Can we beat that with a language with no such arithmetic and list support?
It can in fact be beaten with a language that has no built-in numbers, let alone arithmetic.
This 167 bit Binary Lambda Calculus [1] program 0011010100010100010100010000010100000100010100010000010000010100000100010100000100010000010000000100
produces the infinite characteristic sequence of primes.
[1] https://tromp.github.io/cl/Binary_lambda_calculus.html#Complexity_of_Sets https://tromp.github.io/cl/Binary_lambda_calculus.html#Compl...
- contravariant 5y agoI think you confused the program with it's first 100 bits of output.
- tromp 5y agoOops; you're right. The program is 00010001100110010100011010000000010110000010010001010111 11011110100100011010000111001101000000000010110111001110 0111111101111000000001111100110111000000101100000110110 as shown in the top right of https://tromp.github.io/cl/cl.html https://tromp.github.io/cl/cl.html (with colors showing its tokenization as lambdas, appplications, and variables).