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 Data.Char (chr, ord) | |
import System.Environment (getArgs) | |
cycleRange :: Char -> Int -> Char -> Char | |
cycleRange start n c | a <= x && x < a+26 = chr $ ((x - a + n) `mod` 26) + a | |
| otherwise = c | |
where x = ord c | |
a = ord start | |
caesarCypher :: Int -> String -> String |
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.Monad | |
import Control.Arrow | |
splitListInHalf :: [a] -> ([a], [a]) | |
splitListInHalf = splitAt =<< flip div 2 . (+1) . length | |
checkOneDifferent :: Eq a => [a] -> [a] -> Bool | |
checkOneDifferent a b = 1==(length . filter not . map (uncurry (==)) $ zip a b) | |
transformTuple :: ((a,b),(c,d)) -> ((a,c),(b,d)) |
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
module type PERMUT_CONTAINER = sig | |
type 'a t | |
val append: 'a t -> 'a t -> 'a t | |
val empty: 'a t | |
val cons: 'a -> 'a t -> 'a t | |
val rev: 'a t -> 'a t | |
val hd: 'a t -> 'a | |
val tl: 'a t -> 'a t | |
val fold_left: ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a | |
end |
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 Data.Maybe | |
import Prelude hiding (drop, head, tail, (++), mapM_, zip, length, null) | |
import Data.Vector | |
import qualified Data.List as L | |
import System.Environment | |
import Control.Applicative | |
calculate :: (Int, Int, Vector Int) -> (Int, Int) | |
calculate (c, _, vec) = aux 0 | |
where aux i = let p = vec ! i in |
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 Data.List | |
import Control.Monad | |
import Control.Arrow | |
qsort :: (a -> a -> Bool) -> [a] -> [a] | |
qsort _ [] = [] | |
qsort comp (x:xs) = smaller ++ [x] ++ bigger | |
where (smaller, bigger) = join (***) (qsort comp) $ comp x `partition` xs | |
main :: IO () |
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::collections::HashMap; | |
use std::num::abs; | |
pub struct Preference { | |
name: String, | |
flavors: HashMap<String, int> | |
} | |
impl Preference { | |
pub fn compare_preference<'a>(&'a self, preferences: &'a[Preference]) -> Option<&'a 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
(* I'm using the new syntax sugars on 4.08, which are (let+), (and+) and ( let* ) *) | |
module type FUNCTOR = sig | |
type 'a t | |
val map : ('a -> 'b) -> 'a t -> 'b t | |
val (let+): 'a t -> ('a -> 'b) -> 'b t | |
end | |
module DefaultLetPlus(M: sig | |
type 'a t |
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 crate rustc; | |
use rustc::util::sha2::{Sha256, Digest}; | |
struct File { | |
path: String, | |
contents: Vec<u8> | |
} | |
impl 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
import Control.Applicative | |
import Data.List.Split | |
import Data.List | |
main :: IO () | |
main = do | |
content <- lines <$> readFile "massa.txt" | |
let lasts = last . splitOn "." <$> content | |
let counting = (\xs@(x:_) -> (length xs, x)) . group . sort <$> lasts | |
let output = sortBy (flip compare) counting |
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
#![crate_id = "dojo"] | |
#![crate_type = "lib"] | |
use std::iter::range_step_inclusive; | |
fn prime_number_list(number: uint) -> Vec<uint> { | |
let mut prime_list:Vec<uint> = vec!(2); | |
for i in range_step_inclusive(3, number, 2) { | |
if !prime_list.iter().any(|x| i % *x == 0) { |