Skip to content

Instantly share code, notes, and snippets.

View sanxiyn's full-sized avatar

Seo Sanghyeon sanxiyn

  • Seoul, South Korea
View GitHub Profile
@sanxiyn
sanxiyn / db.c
Created January 15, 2013 12:26
DB
typedef unsigned int sz;
typedef unsigned short ix;
int compare(const char* a, const char* b, sz n) {
while (n) {
if (*a != *b) {
return (unsigned char)*a - (unsigned char)*b;
}
if (*a == 0) {
return 0;
@sanxiyn
sanxiyn / lt.idr
Last active December 10, 2015 03:58
Idris
module lt
data lt : Nat -> Nat -> Set where
succ : lt x (S x)
widen : lt x y -> lt x (S y)
next : lt x y -> lt (S x) (S y)
next succ = succ
next (widen p) = widen (next p)
@sanxiyn
sanxiyn / brute.py
Created September 13, 2012 10:24
Movement
import sys
import itertools
def read(filename):
graph = {}
f = open(filename)
n = int(f.readline())
for i in range(n-1):
line = f.readline()
numbers = map(int, line.split())
@sanxiyn
sanxiyn / stupid.php
Created July 22, 2012 10:08
Plain Simple Stupid Language
<?php if ($_SERVER["REQUEST_METHOD"] == "GET") { ?>
<form action="stupid.php" method="post">
<textarea name="source" cols="80" rows="15">
input n
i = 1;loopi;if i &gt; n fini
j = 1;loopj;if j &gt; n finj
product = i * j
output i * j = product
if j == n last
output /
void move_robot(int direction);
int pick(void);
void put(void);
#define SIZE 1000
enum { LEFT, RIGHT, UP, DOWN };
enum { NOTHING, TREASURE, BOMB };
static int current_x;
@sanxiyn
sanxiyn / parser.py
Created July 6, 2011 17:15
Lambda calculus parser
class Lambda(object):
pass
class Var(Lambda):
def __init__(self, var):
self.var = var
def __repr__(self):
return "Var(%r)" % self.var
class Abs(Lambda):
@sanxiyn
sanxiyn / bigint.c
Created April 18, 2011 19:53
2^100000
#include <stdio.h>
#include <stdlib.h>
#define BASE 10000
struct number {
int n;
int *a;
};
typedef struct number *N;
@sanxiyn
sanxiyn / euler.ml
Created March 27, 2011 09:58
Project Euler in OCaml
#load "nums.cma";;
#load "prime.cmo";;
open Big_int;;
let p1 () =
let sum = ref 0 in
for i = 1 to 1000 - 1 do
if i mod 3 = 0 || i mod 5 = 0 then sum := !sum + i
done;
@sanxiyn
sanxiyn / solve.hs
Created March 17, 2011 04:26
Newton's method
dx = 1e-10
eps = 1e-3
derive f x = (f (x+dx) - f x) / dx
improve f guess x = guess - (f guess - x) / derive f guess
good f guess x = abs (f guess - x) < eps
iter f guess x = if good f guess x then guess else iter f (improve f guess x) x
solve f x = iter f 1.0 x
square x = x*x
cube x = x*x*x
main = do print (solve square 2); print (solve cube 3)
@sanxiyn
sanxiyn / build.sh
Created February 26, 2011 08:48
ANTLR3 C sample
#!/bin/sh
antlr3 test.g
g++ *.cc *.c -o t -lantlr3c