This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
| (defn fib-pair [[a b]] [b (+ a b)]) | |
| (defn nth-fib [n] | |
| "Return the nth fib number" | |
| (nth (map first (iterate fib-pair [0 1])) n)) |
| import time | |
| import sys | |
| from multiprocessing import Process, Pipe | |
| def test_proc(name, conn): | |
| x = 0 | |
| while True: | |
| #print x | |
| x += 1 | |
| if conn.poll(10): | |
| conn.recv() |
| import unittest | |
| def fizzbuzz(value): | |
| if value % 5 == 0 and value % 3 == 0: | |
| return 'fizzbuzz' | |
| elif value % 5 == 0: | |
| return 'buzz' | |
| elif value % 3 == 0: | |
| return 'fizz' | |
| else: |
| def fact(x): | |
| if x == 0: | |
| return 0 | |
| elif x == 1: | |
| return 1 | |
| else: | |
| return x * fact(x-1) | |
| for x in range(0,10): | |
| print x, fact(x) |
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
| import Test.HUnit | |
| fizzbuzz :: Int -> String | |
| fizzbuzz x | |
| | x `mod` 15 == 0 = "fizzbuzz" | |
| | x `mod` 3 == 0 = "fizz" | |
| | x `mod` 5 == 0 = "buzz" | |
| | True = show x | |
| def add(x, y): | |
| return x + y | |
| def subtract(x, y): | |
| return x - y | |
| import shelve | |
| d = shelve.open('shelve_state.dat') |
| // 1. Multiply Each Item in a List by 2 | |
| list(1,2,3,4,5) map(v, v*2) println | |
| // 2. Sum a List of Numbers | |
| list(1,2,3,4,5) reduce(+) println | |
| // 3. Verify if a Word Exists in a String |
| var expected = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113]; | |
| compareLists(lista, listb) { | |
| if (lista.length == listb.length) { | |
| for(var i = 0; i < lista.length; i ++) { | |
| if (lista[i] != listb[i]) { | |
| return false; | |
| } | |
| } | |
| return true; |
| ;; mattyw's solution to Reverse a Sequence | |
| ;; https://4clojure.com/problem/23 | |
| (defn reverse-func [seq] | |
| (reduce (fn [a b] (cons b a)) '() seq)) | |
| (println (= (reverse-func [1 2 3 4 5]) [5 4 3 2 1])) |