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
ruby-1.9.3-rc1 :001 > @proc = lambda { ScratchPad.record :proc_trap } | |
=> #<Proc:0x8eb361c@(irb):1 (lambda)> | |
ruby-1.9.3-rc1 :002 > @saved_trap = Signal.trap(:HUP, @proc) | |
=> "DEFAULT" | |
ruby-1.9.3-rc1 :003 > Signal.trap :HUP, nil | |
=> #<Proc:0x8eb361c@(irb):1 (lambda)> | |
ruby-1.9.3-rc1 :004 > Signal.trap(:HUP, @saved_trap) | |
=> nil |
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 gcd_recursive(u, v) | |
return u|v if u==0 or v==0 | |
if u.even? | |
if v.even? | |
return gcd(u>>1, v>>1)<<1 | |
else | |
return gcd(u>>1, v) if v.odd? | |
end | |
elsif u.odd? and v.even? |
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
================================ rubinius | |
/ 0 0.0 0i 0 | |
1 ZeroDivisionError Infinity ZeroDivisionError ZeroDivisionError | |
1.0 Infinity Infinity Complex(NaN, NaN) Infinity | |
9223372036854775808 ZeroDivisionError Infinity ZeroDivisionError ZeroDivisionError | |
0 ZeroDivisionError NaN ZeroDivisionError ZeroDivisionError | |
0.0 NaN NaN Complex(NaN, NaN) NaN | |
0i ZeroDivisionError Complex(NaN, NaN) ZeroDivisionError ZeroDivisionError | |
0 ZeroDivisionError NaN ZeroDivisionError ZeroDivisionError |
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
/** Calculate the square root of a BigInteger in logarithmic time */ | |
public BigInteger squareRoot(BigInteger x) { | |
BigInteger right = x, left = BigInteger.ZERO, mid; | |
while(right.subtract(left).compareTo(BigInteger.ONE) > 0) { | |
mid = (right.add(left)).shiftRight(1); | |
if(mid.multiply(mid).compareTo(x) > 0) | |
right = mid; | |
else | |
left = mid; | |
} |
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
escape ^Tt |
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
import org.schwering.irc.lib.IRCConnection; | |
import org.schwering.irc.lib.IRCEventListener; | |
import org.schwering.irc.lib.IRCModeParser; | |
import org.schwering.irc.lib.IRCUser; | |
import org.schwering.irc.lib.ssl.SSLIRCConnection; | |
import org.schwering.irc.lib.ssl.SSLTrustManager; | |
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.io.IOException; |
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
quicksort :: (Ord a) => [a] -> [a] | |
quicksort [] = [] | |
quicksort (x:xs) = | |
let smallerSorted = quicksort [a | a <- xs, a <= x] | |
biggerSorted = quicksort [a | a <- xs, a > x] | |
in smallerSorted ++ [x] ++ biggerSorted | |
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
qs [] = [] | |
qs (x:xs) = qs [a|a<-xs, a<=x]++[x]++qs [a|a<-xs, a>x] |
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
-- the sum of all the multiples of 3 or 5 below 1000 | |
numbers = [x | x <- [1..], x `mod` 3 == 0 || x `mod` 5 == 0] | |
answer = sum $ takeWhile (<1000) numbers |
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
-- the sum of the even valued values of the fibonacci sequence | |
-- whose values do not exeed four million | |
fibonacci 0 = 0 | |
fibonacci 1 = 1 | |
fibonacci n = fibonacci (n-1) + fibonacci (n-2) | |
fib = [fibonacci n | n <- [0..]] | |
answer2 = sum $ filter even $ takeWhile (<4000000) fib | |
main = putStrLn $ show answer2 |