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
# -*- coding: utf-8 -*- | |
# answer_q684.py | |
# ===== DEFINITIONS ===== | |
# メモ化再帰のためのキャッシュ | |
cache = {} | |
# 与えられた数値のリストから、各文字がその数だけある場合の全パターン総数を計算(メモ化再帰) | |
def calc_count(num_list): |
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
"use strict"; | |
/* | |
PlayerName="E" | |
ネイピア数(自然対数の底, Math.E)を3進数表記したときの小数点以下100桁の数字に則って「パー」「グー」「チョキ」を出すだけ。 | |
*/ | |
/* | |
MEMO: |
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
;; CodeIQ q1026 Answer for Egison (http://www.egison.org/) | |
(define $fibs | |
(letrec {[$fibs-gen (lambda [$a $b] {a @(fibs-gen b (+ a b))})]} | |
(fibs-gen 0 1))) | |
(define $main | |
(lambda [$args] | |
(print (S.intercalate "," (map show (take 20 fibs)))) | |
; => 0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181 | |
)) |
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
;; rw3sat.egi | |
(define $reject | |
(lambda [$pred $xs] | |
(match xs (list something) | |
{[<nil> {}] | |
[<cons ?pred $ys> (reject pred ys)] | |
[<cons $y $ys> {y @(reject pred ys)}]}))) | |
(define $sample |
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
;; multi_args.egi | |
(define $l2 (lambda [$x $y] {x y})) | |
(define $l3 (lambda [$x $y $z] {x y z})) | |
(define $main | |
(lambda [$args] | |
(do { | |
[(print (show (l2 "x" "y")))] | |
; => {"x" "y"} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
# answer_q1282.jl | |
# ===== DEFINITIONS ===== | |
# 文字列を Rational にパースする関数 | |
function torational(s::String) | |
# `r"〜"` は Julia の正規表現リテラル | |
m = match(r"^(\d+)\.?(\d*)", s) | |
if m != nothing | |
return Rational(int(m.captures[1]*m.captures[2]), 10^length(m.captures[2])) |
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
# Rw3sat.jl | |
sample(a::Array) = a[rand(1:end)] | |
immutable Literal | |
index::Int | |
not::Bool | |
end | |
literal(index, not) = Literal(index, not) |
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
;; Save this code as a "tuple_util.egi" file | |
;; tuple-to-XXX | |
(define $tuple-to-array | |
(lambda [$t] | |
(match nats0 (list integer) | |
{[(loop $i [1 $n] <cons _ ...> <cons ?(tuple? $ t) _>) | |
(generate-array [$i] n ((read (S.concat {(show n) "#%" (show i)})) t))]}))) | |
; (define $tuple-to-array' ; faster `tuple-to-array` |
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
# GPIterator.jl | |
# ===== GPIterator Basics ===== | |
# === Type Definitions === | |
abstract AbstractIterator | |
immutable EmptyIterator <: AbstractIterator | |
end |
OlderNewer