Skip to content

Instantly share code, notes, and snippets.

View antimon2's full-sized avatar

GOTOH Shunsuke antimon2

View GitHub Profile
@antimon2
antimon2 / answer_q684.py
Created February 12, 2014 14:16
CodeIQ の アルゴリズム問題「ジェムストリング問題」( https://codeiq.jp/ace/yuki_hiroshi/q684 )の解答出力プログラム。提出したのは answer_q684.py 、同じ処理を Ruby でも書いたのが answer_q684.rb 。
# -*- coding: utf-8 -*-
# answer_q684.py
# ===== DEFINITIONS =====
# メモ化再帰のためのキャッシュ
cache = {}
# 与えられた数値のリストから、各文字がその数だけある場合の全パターン総数を計算(メモ化再帰)
def calc_count(num_list):
@antimon2
antimon2 / E.js
Created May 25, 2014 14:08
JavaScript じゃんけん大会 ( https://codeiq.jp/ace/nabetani_takenori/q888 )用 疑似乱数表ユーザ。
"use strict";
/*
PlayerName="E"
ネイピア数(自然対数の底, Math.E)を3進数表記したときの小数点以下100桁の数字に則って「パー」「グー」「チョキ」を出すだけ。
*/
/*
MEMO:
@antimon2
antimon2 / answer_q1026.egi
Created October 10, 2014 13:47
CodeIQ の #右仮面 問題を Egison で解いてみた。
;; 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
))
@antimon2
antimon2 / rw3sat.egi
Last active August 29, 2015 14:12
「充足可能性問題(3-SAT)を解く乱択アルゴリズム」 by Egison ref: http://qiita.com/antimon2/items/c55a31a1bbd1f98360f0
;; 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
;; 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"}
@antimon2
antimon2 / python_tokai_201501_antimon2_1.ipynb
Last active August 29, 2015 14:14
Python東海 第26回勉強会 発表内容(変換結果はこちら→ https://nbviewer.jupyter.org/gist/antimon2/c180a49222659c64a9b9
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@antimon2
antimon2 / answer_q1282.jl
Created January 31, 2015 13:34
CodeIQ の 数学問題「中学入試から:概数と計算」( https://codeiq.jp/ace/nabetani_takenori/q1282 ) の求解プログラム by Julia。
# 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]))
@antimon2
antimon2 / Rw3sat.jl
Last active August 29, 2015 14:14
「充足可能性問題(3-SAT)を解く乱択アルゴリズム」 by Julia ref: http://qiita.com/antimon2/items/96e3bd6e452e03cf98db
# Rw3sat.jl
sample(a::Array) = a[rand(1:end)]
immutable Literal
index::Int
not::Bool
end
literal(index, not) = Literal(index, not)
@antimon2
antimon2 / tuple_util.egi
Created February 8, 2015 12:17
こんなことできま<del>せん</del><ins>した</ins> Tuple 編 ref: http://qiita.com/antimon2/items/fce05887befddc31583f
;; 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`
@antimon2
antimon2 / GPIterator.jl
Created April 30, 2015 14:05
Juliaで汎用イテレータ型作ってみた ref: http://qiita.com/antimon2/items/25d65f5baff458dccd88
# GPIterator.jl
# ===== GPIterator Basics =====
# === Type Definitions ===
abstract AbstractIterator
immutable EmptyIterator <: AbstractIterator
end