Skip to content

Instantly share code, notes, and snippets.

View nyuichi's full-sized avatar

Yuichi Nishiwaki nyuichi

View GitHub Profile
@nyuichi
nyuichi / HyakuninIsshu.py
Created January 6, 2011 11:44
百人一首
# -*- coding: utf-8 -*-
import re
o = re.compile(r'<TD><A HREF="page[0-9]+\.html"\s*?style="text-decoration:none"\s?>([0-9]+?)</a></TD>\W*?<TD><A HREF="page[0-9]+?\.html"\s*?style="text-decoration:none">(.*?)\s</a></TD>\W*?<TD><A HREF="page[0-9]+?\.html"\s?style="text-decoration:none">([\W\w]*?)</TD>', re.I)
dat = u'''
<TR>
<TD><A HREF="page1.html" style="text-decoration:none">001</a></TD>
<TD><A HREF="page1.html" style="text-decoration:none">秋の田の かりほの庵の 苫をあらみ わが衣手は 露にぬれつつ
from math import *
import struct
import pyaudio
from multiprocessing import Process, Pipe
import threading
import sys, pygame
start = 0
@nyuichi
nyuichi / Match.py
Created January 12, 2011 16:46
Match
'''
Pass
Reborn
Self-kill
'''
from math import ceil
def expand(n):
a = n/1000
@nyuichi
nyuichi / Lifegame.scm
Created February 7, 2011 21:46
The Game of Life on Gauche
(use srfi-1)
(use srfi-42)
(use math.mt-random)
(define *screen-width* 500)
(define *screen-height* 500)
(define *field-width* 100)
(define *field-height* 100)
(define field
@nyuichi
nyuichi / H-Tokenizer.scm
Created March 15, 2011 08:11
H Tokenizer
(use srfi-13)
(define (token type data)
(cons type data))
(define (normalize source)
(let loop ([acc ()]
[dat (string-split source #\newline)])
(cond [(null? dat)
(string-join (reverse acc) #\newline)]
@nyuichi
nyuichi / H-BNF.scm
Created March 15, 2011 08:20
H-BNF
;;; Syntax Rules (in BNF)
;;;
;;; <program> ::= <main> | <definition> <program>
;;; <main> ::= <statement> <eof> | <statement> <main>
;;; <statement> ::= 's' | 'r' | 'l' | <call> | <parameter>
;;;
;;; <call> ::= <procname> | <procname> '(' <arguments> ')'
;;; <arguments> ::= <argument> | <argument> ',' <arguments>
;;; <argument> ::= <expression> | <body>
;;; <body> ::= <statement> <body> | ''
@nyuichi
nyuichi / Event.java
Created April 4, 2011 15:23
Spriteライブラリを自作してみた。
package sprite;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class Event {
private static Queue<AWTEvent> queue = new LinkedList<AWTEvent>();
public static AWTEvent peek() {
return queue.peek();
@nyuichi
nyuichi / Main.java
Created April 25, 2011 14:52
Launcher
import java.awt.GraphicsEnvironment;
import java.awt.GraphicsDevice;
import java.awt.DisplayMode;
import java.awt.GraphicsConfiguration;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.Image;
import java.awt.Font;
@nyuichi
nyuichi / sisoku.clj
Created May 14, 2011 16:31
四則ソルバー
(use 'clojure.contrib.combinatorics)
(def seeds [7 7 7 9 11 11])
(def result 218/100)
(def inject-pos
(memoize
@nyuichi
nyuichi / sisoku.clj
Created May 17, 2011 15:16
四則ソルバー in Clojure
(use 'clojure.contrib.combinatorics)
(def seeds [7 7 7 9 11 11])
(def answer 218/100)
(defn drop-nth [n coll]
(concat (take n coll)
(drop (inc n) coll)))