省略
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Pervasives | |
(* | |
例えば、掛け算は、「足し算をn回繰りかえす」と定義できる | |
*) | |
let rec mul1 x n = | |
if n == 1 | |
then x | |
else x + (mul1 x (n - 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# もっといい方法があるが、サンプルのために、このままにする | |
def exchange_node x, coin | |
return 1 if x == 0 | |
return 1 if x < 5 | |
return 0 if x < 0 | |
sum_coin = 0 | |
case coin | |
when 10 | |
sum_coin += exchange_node(x - 5, 5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def exchange x | |
exchange_node x, 50 | |
end | |
# proto exchange node example | |
def proto_exchange_node x, coin | |
return 1 if x == 0 | |
return 1 if x < 5 | |
return 0 if x < 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# M_kを、k番目までの素数の積を合計したものとする。 | |
# 例えばM2ならば2 * 3で6となる。これがホイールの | |
# 周期として定義される。 | |
# M2の場合、最初の素数以降、確率的に2, 4, 2, 4... | |
# の間隔で、素数の候補が表われる。これらは、自分の理解 | |
# するところによれば、2と3の倍数が表れない周期性を利用 | |
# している。 | |
M2_CYCLE_LENGTH = 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SieveHelper | |
def initialize(limit, x, y) | |
@limit = limit | |
@x = x | |
@y = y | |
end | |
def invalid? | |
(@x ** 2) + (@y ** 2) >= @limit | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require rackunit) | |
;; factor x y | |
;; | |
;; 割りきれるとき ->引き数と割った後の数 | |
;; 割りきれないとき ->空リストを返す | |
(define (factor x y) | |
(if (= 0 (modulo x y)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let hello = print_string ("Hello, World." ^ "\n") | |
let () = hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Str.split (Str.regexp_string ",") line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; sample | |
;; http://quil.info/sketches/show/example_hyper | |
(ns shussha-kanryo.hyper | |
(:require [quil.core :as q :include-macros true] | |
[quil.middleware :as m])) | |
(defn setup [] | |
(q/frame-rate 60) | |
(q/background 255) |