Skip to content

Instantly share code, notes, and snippets.

@plaster
plaster / gacha.scm
Last active March 18, 2018 16:18
チョコエッグ16種のうち残り4種をコンプしたいんだけどいくつ買ったらどのくらいの確率でコンプできるか
(use srfi-27)
(use util.match)
(define (play-out n N x)
;; x times trial
;; n species to get
;; N species supplied
(let1 C (- (ash 1 n) 1) ;; 1111... [n times]
(let loop [[ c 0 ]
[ x x ]
FINISHED --2018-04-18 05:48:59--
Total wall clock time: 2m 38s
Downloaded: 435 files, 1.7G in 2m 21s (12.3 MB/s)
ル╹ヮ╹ルɔ cymbal:/mnt/hgfs/MIKA/plaster/mod-diary-2018-04-16/pdfs
% file *.pdf | sed -e 's/.*://' | sort | uniq -c
175 PDF document, version 1.3
260 PDF document, version 1.4
ル╹ヮ╹ルɔ cymbal:/mnt/hgfs/MIKA/plaster/mod-diary-2018-04-16/pdfs
% wc -l ../pdf-list.txt
435 ../pdf-list.txt
@plaster
plaster / gacha.md
Last active March 20, 2020 16:26
1/8のガチャに3つほしいものがあるとき「コンプするまで」vs「1個でもあたるまで」の回数のシミュレーション

試行回数: 10万回

EVERY ANY
25% 9 1
50% 13 2
75% 19 3
90% 26 5
99% 43 10
99.9% 60 15
(use srfi-42)
(use math.prime)
(define (solve N)
(let* [[v (make-vector N)]
[%%solve (^ (n k) (let [[x (vector-ref v k)]
[y (vector-ref v (- n k 1)) ]]
(max (+ x y) (* x y))))]
[%solve (^ (n) (if (zero? n) 1
(max-ec (: k n) (%%solve n k))))]