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
| import Control.Applicative | |
| process :: [[[a]]] -> [[a]] | |
| process [] = [] | |
| process [x] = x | |
| process (x : xs) = (++) <$> x <*> process xs | |
| main :: IO () | |
| main = putStrLn . show . process $ [[[3], [5]], [[1]]] |
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
| digs :: Int -> [Int] | |
| digs = map (read . return) . show | |
| process :: Int -> Int | |
| process = sum . map (^2) . digs | |
| isHappy :: Int -> Bool | |
| isHappy x = isHappyHelper x [] |
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
| import System.Environment | |
| import Control.Monad | |
| import System.IO | |
| calculateTime :: Double -> Double -> Double -> Double | |
| calculateTime c f x = loop 2 | |
| where loop rate | |
| | outright <= buying = outright | |
| | otherwise = waiting + loop newRate | |
| where waiting = c / rate |
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
| #!/usr/bin/sbcl --script | |
| (setf *read-default-float-format* 'double-float) | |
| (defun calculate-time (c f x) | |
| (labels ((calculate-time-helper (c f x n time-spent) | |
| (let* ((time-with-current (/ x (+ (* n f) 2))) | |
| (time-for-farm (/ c (+ (* n f) 2))) | |
| (time-with-farm (+ time-for-farm | |
| (/ x (+ (* (1+ n) f) 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
| #!/usr/bin/sbcl --script | |
| (load "~/quicklisp/setup.lisp") | |
| (require 'cl-ppcre) | |
| (defun read-rows (file) | |
| (loop for i from 0 to 3 | |
| collect (mapcar #'parse-integer | |
| (cl-ppcre:split " " (read-line file))))) |
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
| #include <stdio.h> | |
| double calculateTime(double c, double f, double x) { | |
| double totalTime = 0; | |
| int n = 0; | |
| double timeWithCurrent, timeForFarm, timeWithFarm; | |
| do { | |
| timeWithCurrent = x/((f*n)+2); | |
| timeForFarm = c/((f*n)+2); | |
| timeWithFarm = timeForFarm+(x/(((1+n)*f)+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
| extern mod extra; | |
| use extra::bigint::BigInt; | |
| use extra::bigint::Plus; | |
| use extra::bigint::Minus; | |
| use extra::bigint::Zero; | |
| use extra::bigint::ToBigInt; | |
| fn coefficients(p: uint) -> ~[BigInt] { | |
| if p==0 { | |
| ~[BigInt::new(Plus, ~[1])] |
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
| (defun palindrome (str) | |
| (loop | |
| for i from 0 | |
| for a across str | |
| for b across (reverse str) | |
| always (char= a b) | |
| until (> i (/ (length str) 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
| use std::vec::append_one; | |
| #[deriving(Clone)] | |
| struct Tree<T>(T, ~[Tree<T>]); | |
| impl<T: ToStr> ToStr for Tree<T> { | |
| fn to_str(&self) -> ~str { | |
| let &Tree(ref data, ref children) = self; | |
| data.to_str() + " -> " + children.to_str() | |
| } |
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
| (defun factorial (number) | |
| (labels ((factorial-helper (x accumulator) | |
| (if (zerop x) | |
| accumulator | |
| (factorial-helper (- x 1) (* accumulator x))))) | |
| (factorial-helper number 1))) |