This file contains hidden or 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
$ cat /usr/share/calendar/calendar.lotr | |
/* | |
* Lord Of The Rings | |
* | |
* $FreeBSD: src/usr.bin/calendar/calendars/calendar.lotr,v 1.2 2003/10/09 00:31:48 grog Exp $ | |
*/ | |
#ifndef _calendar_lotr_ | |
#define _calendar_lotr_ |
This file contains hidden or 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
mas que beleza | |
mão colando na mesa | |
quente demais |
This file contains hidden or 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
(defn foo [x] | |
{:pre [(> x 10)]} | |
(println x)) | |
; output: 'user/foo | |
(foo 2) | |
; output: AssertionError Assert failed: (> x 10) user/foo (NO_SOURCE_FILE:1) | |
(foo 11) | |
; output: 11 |
This file contains hidden or 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
(defn start-thread [f] | |
(.start (Thread. f))) | |
(let | |
[sum (future (apply + (range 1e7))) | |
answer (promise)] | |
(println "0. Started...") | |
(start-thread |
This file contains hidden or 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
(defn len [x] | |
(.length x)) | |
(defn len2 [^String x] | |
(.length x)) | |
(time (reduce + (map len (repeat 1000000 "asdf")))) | |
; "Elapsed time: 8711.592674 msecs" | |
(time (reduce + (map len2 (repeat 1000000 "asdf")))) |
This file contains hidden or 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
(defn sleep [] | |
(Thread/sleep 1000)) | |
(defn fast-computation [x] | |
(* x 2)) | |
(defn heavy-computation [x] | |
(sleep) | |
(* x 2)) |
This file contains hidden or 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
; First we create a function. Let's try Fibonacci | |
(defn fib [n] | |
(if (or (zero? n) (= n 1)) | |
1 | |
(+ (fib (dec n) ) (fib (- n 2))))) | |
; Se let's measure the time needed to run the function | |
(do |
This file contains hidden or 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
; without memoization | |
(defn fib [n] | |
(if (or (zero? n) (= n 1)) | |
1 | |
(+ (fib (dec n) ) (fib (- n 2))))) | |
(time (fib 90)) | |
; spent more than 30 minutes and I quit |
This file contains hidden or 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
(use '[clojure.core.match :only (match)]) | |
(doseq [n (range 1 101)] | |
(println | |
(match [(mod n 3) (mod n 5)] | |
[0 0] "FizzBuzz" | |
[0 _] "Fizz" | |
[_ 0] "Buzz" | |
:else n))) |
This file contains hidden or 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
(ns euler.euler04-1) | |
(defn peel | |
"Peel a string like a banana, removing first and last character" | |
[str] | |
(butlast (rest str))) | |
(defn palindrome? | |
"Returns true or false if name is a palindrome. | |
This recursive approach is slightly faster than compare with its reverse." |