This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def from(n: Integer): Stream[Integer] = n #:: from(n+1) | |
def sieve(input: Stream[Integer]): Stream[Integer] = input.head #:: sieve(input.tail.filter(_ % input.head != 0)) | |
def primes = sieve(from(2)) | |
primes take 10 print |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fibonacci = (n) => n < 3 ? 1 : fibonacci(n - 1) + fibonacci(n - 2) | |
const fibonacci = (n, memo = { 1: 1, 2: 1 }) => n in memo ? memo[n] : memo[n] = fibonacci(n - 1) + fibonacci(n - 2) |