Skip to content

Instantly share code, notes, and snippets.

View nyuichi's full-sized avatar

Yuichi Nishiwaki nyuichi

View GitHub Profile
@nyuichi
nyuichi / gist:2239499
Created March 29, 2012 16:31
letが動かない
(define cadr (lambda (obj) (car (cdr obj))))
(define cddr (lambda (obj) (cdr (cdr obj))))
(define caddr (lambda (obj) (car (cddr obj))))
(define cdddr (lambda (obj) (cdr (cddr obj))))
(define map
(lambda (f lst)
(if (null? lst)
'()
(cons (f (car lst))
@nyuichi
nyuichi / gist:2319715
Created April 6, 2012 13:21
de bruijn index
(define n-0 '(L (L (V 0))))
(define n-1 '(L (L (A (V 1) (V 0)))))
(define n-2 '(L (L (A (V 1) (A (V 1) (V 0))))))
(define n-3 '(L (L (A (V 1) (A (V 1) (A (V 1) (V 0)))))))
@nyuichi
nyuichi / gist:2319798
Created April 6, 2012 13:30
de bruijn index -> number
(define n-0 '(L (L (V 0))))
(define n-1 '(L (L (A (V 1) (V 0)))))
(define n-2 '(L (L (A (V 1) (A (V 1) (V 0))))))
(define n-3 '(L (L (A (V 1) (A (V 1) (A (V 1) (V 0)))))))
(define (unwrap n) (cadr (cadr n)))
@nyuichi
nyuichi / gist:2392634
Created April 15, 2012 12:52
LazyK with Scheme
;---------------------------------------------------------------
; debug print
(define (show-recursion1 f)
(let ([*nest* 0])
(lambda (arg)
(dotimes (i *nest*) (display " "))
(print arg)
(set! *nest* (+ *nest* 1))
(let ([result (f arg)])
;---------------------------------------------------------------
; debug print
(define (show-recursion1 f)
(let ([nest 0])
(lambda (arg)
(dotimes (i nest) (display " "))
(print arg)
(set! nest (+ nest 1))
(let ([result (f arg)])
@nyuichi
nyuichi / iota.scm
Created April 19, 2012 15:08
Iota by hiromu1996
#!/usr/bin/env gosh
(define (usage)
(format (current-error-port)
"Usage: ~a [source file]\n" *program-name*)
(exit 2))
(define s
(lambda (x) (lambda (y) (lambda (z) ((x z) (y z))))))
(global-set-key "\C-h" 'delete-backward-char)
(tool-bar-mode 0)
(show-paren-mode 1)
(menu-bar-mode 0)
(set-scroll-bar-mode 'right)
(setq column-number-mode t)
(setq make-backup-files nil)
(setq auto-save-default nil)
(setq x-select-enable-clipboard t)
(setq inhibit-startup-message t)
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
if [ "$PS1" ]; then
complete -cf sudo
fi
/*
@utatakiyoshi: 友達がSkypeで「0~9を1回ずつ使い,?????/?????=1/9となるように?を埋めよ」って算数パズルを出してきたからC++でサクッと書いてドヤ顔してやった
ちなみにこうなった
result: 6381 57429
result: 6471 58239
result: 8361 75249
result: 10638 95742
result: 10647 95823
result: 10836 97524
@nyuichi
nyuichi / Mygame.java
Created June 20, 2012 11:54
じゃんけん
import java.util.Scanner;
class Mygame {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("じゃんけんしましょー。ぱーなら0 ぐーなら1 ちょきなら2 を入力して: ");
int a = sc.nextInt();
int b = (int)(Math.random()*3);
sc.nextLine();