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 / lisp.c
Created August 14, 2010 04:16
Lisp
#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
enum type {
NIL,
@sanxiyn
sanxiyn / toy.py
Created September 19, 2010 08:23
Python subset
"""
a = 1
b = 1
i = 2
n = 10
while i < n
c = a + b
a = b
b = c
i = i + 1
@sanxiyn
sanxiyn / build.sh
Created February 26, 2011 08:48
ANTLR3 C sample
#!/bin/sh
antlr3 test.g
g++ *.cc *.c -o t -lantlr3c
@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 / 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 / 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 / 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):
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 / 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 /
@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())