Skip to content

Instantly share code, notes, and snippets.

View Leonidas-from-XIV's full-sized avatar

Marek Kubica Leonidas-from-XIV

View GitHub Profile
module Main where
import System.Environment (getArgs)
multiplesOf :: Int -> [Int]
multiplesOf n = [n,2*n..]
getBiggerThan x n = case dropWhile (< x) (multiplesOf n) of
[] -> 0
(x:xs) -> x
slidingWindow :: [Int] -> [[Int]]
slidingWindow [] = []
slidingWindow [a] = []
slidingWindow (a:b:xs) = [a,b]:(slidingWindow (b:xs))
pascalTriangle :: Int -> [Int]
pascalTriangle 0 = []
pascalTriangle 1 = [1]
pascalTriangle n = 1:(map sum $ slidingWindow $ pascalTriangle $ n-1) ++ [1]
Tue Feb 25 11:21 2014 Time and Allocation Profiling Report (Final)
MajorElement +RTS -p -RTS fb27.txt
total time = 7.05 secs (7047 ticks @ 1000 us, 1 processor)
total alloc = 7,444,747,008 bytes (excludes profiling overheads)
COST CENTRE MODULE %time %alloc
processLine.entries.\ Main 47.8 32.9
breakNth _ [] = ([], [])
breakNth n lat = case splitAt (n-2) lat of
(skipped,r:rs) -> let (skipped', rest) = breakNth n rs in
(skipped ++ skipped', x:r:rest)
(skipped, []) -> (skipped, x:[])
@Leonidas-from-XIV
Leonidas-from-XIV / keybase.md
Created March 23, 2014 00:21
Keybase.io verification

Keybase proof

I hereby claim:

  • I am Leonidas-from-XIV on github.
  • I am leonidas (https://keybase.io/leonidas) on keybase.
  • I have a public key whose fingerprint is 2584 25CE B974 611B 6423 7553 5759 82D1 87A6 E2C5

To claim this, I am signing this object:

module Main where
input = [
"4", "S", "a", "t", "z", "0",
"3", "D", "a", "s", "17",
"3", "e", "i", "n", "1",
"3", "i", "s", "t", "12"
]
traverse :: [String] -> Int -> [String]
let mut buffer = [0, .. 8];
let read = match fdInput.read(buffer) {
Ok(num) => num,
Err(e) => fail!("Couldn't read"),
};
println!("read {} bytes", read);
let number = match u64::parse_bytes(buffer, 2) {
Some(n) => n,
None => fail!("Reading number"),
};
fn write_u64(to: &mut File, items: &Vec<u64>) {
let mut written: Vec<u8> = unsafe { cast::transmute(items) };
let written_len = written.len();
unsafe { written.set_len(written_len * 8)};
match to.write(written.as_slice()) {
Ok(_) => (),
Err(e) => fail!("writing failed: {}", e),
};
}
fn read_u64(mut from: File, n: uint) -> ~[u64] {
let mut buffer: Vec<u8> = Vec::with_capacity(n * 4);
let mut buf = buffer.as_mut_slice();
match from.read(buf) {
Ok(_) => (),
Err(e) => fail!("reading failed {}", e),
};
let v: ~[u64] = unsafe { std::cast::transmute(buf) };
v
sort.rs:179:5: 179:16 error: use of moved value: `write_cache`
sort.rs:179 write_cache.push(number);
^~~~~~~~~~~
sort.rs:181:31: 181:42 note: `write_cache` moved here because it has type `std::vec::Vec<u64>`, which is non-copyable (perhaps you meant to use clone()?)
sort.rs:181 write_u64(&mut fdOutput, write_cache);
^~~~~~~~~~~
sort.rs:180:8: 180:19 error: use of moved value: `write_cache`
sort.rs:180 if write_cache.len() >= items_per_run {
^~~~~~~~~~~
sort.rs:181:31: 181:42 note: `write_cache` moved here because it has type `std::vec::Vec<u64>`, which is non-copyable (perhaps you meant to use clone()?)