Skip to content

Instantly share code, notes, and snippets.

View Eckankar's full-sized avatar

Sebastian Paaske Tørholm Eckankar

View GitHub Profile
datatype ('s, 'r) state = S of 's -> ('s * 'r)
infixr $
fun f $ x = f x
fun return v = S (fn s => (s, v))
infix >>=
fun (S sf) >>= f = S (fn s =>
let
@Eckankar
Eckankar / J.cpp
Created October 6, 2013 09:31
Fwnies' solution to NCPC 2013 problem J
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
#define p 1000
double sigma;
double PI;
@Eckankar
Eckankar / D.cpp
Created October 6, 2013 09:21
Fwnies' solution to NCPC 2013 problem D
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
typedef double T;
const T EPS = 1e-8;
@Eckankar
Eckankar / B.cpp
Created October 6, 2013 09:11
Fwnies' solution to NCPC 2013 problem B
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int main() {
double t;
int n;
@Eckankar
Eckankar / E.py
Created October 6, 2013 09:04
Fwnies' solution to NCPC 2013 problem E
xs = raw_input()
ys = raw_input()
lxs = len(xs)
lys = len(ys)
d = lys - lxs
i = 0
while True:
if i >= min(lxs, lys):
@Eckankar
Eckankar / F.py
Created October 6, 2013 09:00
Fwnies' solution to NCPC 2013 problem F
ls = [raw_input() for _ in range(5)]
nums = [
[['*', '*', '*'],
['*', ' ', '*'],
['*', ' ', '*'],
['*', ' ', '*'],
['*', '*', '*']],
[[' ', ' ', '*'],
[' ', ' ', '*'],
@Eckankar
Eckankar / G.py
Created October 6, 2013 08:57
Fwnies' solution to NCPC 2013 problem G
n = int(raw_input())
l1 = raw_input()
l2 = raw_input()
flipped = all(x <> y for x, y in zip(l1, l2))
if n % 2 == 0:
res = l1 == l2
else:
@Eckankar
Eckankar / A.py
Created October 6, 2013 08:55
Fwnies' solution to NCPC 2013 Problem A
import sys
sys.stdin.readline()
line = sys.stdin.readline()
xs = [int(x) for x in line.split()]
xs = sorted(xs)[::-1]
res = max(x + y + 2 for x, y in enumerate(xs))
print res
datatype 'a lazylist = Cons of 'a * (unit -> 'a lazylist)
| Nil
fun take (_, 0) = []
| take (Nil, _) = raise Subscript
| take (Cons (x, xs), n) = x :: take (xs (), n-1)
local
fun primes' 2 ps = Cons(2, fn () => primes' 3 (2 :: ps))
| primes' n ps = if List.exists (fn p => n mod p = 0) ps
#!/usr/bin/env python
from urllib import urlopen
from random import randint
id_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
def gen_id():
id = ""
for i in range(5):
id += id_chars[randint(0, len(id_chars)-1)]