Skip to content

Instantly share code, notes, and snippets.

View ayato-p's full-sized avatar
💪

ayato-p ayato-p

💪
  • UZABASE, inc.
  • Tokyo, Japan
  • 03:04 (UTC +09:00)
View GitHub Profile
;;;
;;; http://d.hatena.ne.jp/ayato0211/20130221/1361438221
;;;
;; =========
;; quotation
;; =========
(define (ok? ls)
(let ((model-1 (list-ref ls 0))
(model-2 (list-ref ls 1))
(model-3 (list-ref ls 2))
@ayato-p
ayato-p / fizzbuzz.scm
Created February 22, 2013 09:10
なんとなくノリで書いた。
(use srfi-1)
(define (fizzbuzz)
(map
(lambda (x)
(cond
((zero? (modulo x 15)) "FizzBuzz")
((zero? (modulo x 5)) "Buzz")
((zero? (modulo x 3)) "Fizz")
(else x)))
(define value-list '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\A #\B #\C #\D #\E #\F))
;;10->16
(define (decimal->hex n)
(let ((base 16))
(let loop ((n n)
(o '()))
(cond
((zero? n) (list->string o))
(else
@ayato-p
ayato-p / baroque.scm
Last active December 14, 2015 00:49
ドラクエVIIのバロックタワーのパズルを解く ( http://d.hatena.ne.jp/torazuka/20130221/ddd ) を参考に問いてみたけど、出力結果が思うようにいかない…。
(define (baroque input)
(define (ok? ls)
(let ((model-1 (list-ref ls 0))
(model-2 (list-ref ls 1))
(model-3 (list-ref ls 2))
(model-4 (list-ref ls 3)))
(and (= model-1 2)
(= model-2 3)
(= model-3 0)
; 対応する括弧を表示する
(show-paren-mode t)
; デフォルトパスを~/にする
(cd "~/")
;起動するときに起動画面を表示しない
(setq inhibit-startup-message t)
; *.~ とかのバックアップファイルを作らない
(define (expt-of-ten x)
(expt 10 x))
(define (f c x)
(c x))
(f expt-of-ten 2)
(define (exp-of-ten x)
(expt 10 x))
(define (foo x context)
(print (context x)))
(define (bar list context)
(for-each
(lambda (listp) (foo listp context))
@ayato-p
ayato-p / str-parse.scm
Created February 13, 2013 00:04
Euler-11の為に。。。
(define (str-parse str)
(let loop ((ls (string->list str))
(tmp-acc '())
(acc '()))
(cond
((null? str) (reverse acc))
(let ((c (car ls))
(c2i (lambda (c)
(- (char->integer c) 48))))
((or (char-whitespace? c) (null? (cdr ls)))
@ayato-p
ayato-p / comp-tup.scm
Last active December 12, 2015 12:49
数のリストを合成する。 ex.) (1 2 3 4) ;;=> 1234 (1 0 0 0) ;;=> 1000 (0 0 0 1) ;;=> 1
(define (comp-tup tup)
(comp-tup-iter tup 0))
(define (comp-tup-iter tup comp)
(define (pow a b)
(if (zero? b)
1
(* a (pow a (- b 1)))))
(cond
((null? tup) comp)
@ayato-p
ayato-p / str-count.scm
Last active December 12, 2015 10:39
named-letの練習。 空白文字はカウントしない。
(define (str-count str)
(let loop ((ls (string->list str))
(count 0))
(let ((c (if (pair? ls)
(car ls)
ls))
(inc (lambda (x) (+ x 1))))
(cond
((null? ls) count)
((char-whitespace? c) (loop (cdr ls) count))