2010-12-29から1日間の記事一覧

だいぶ慣れてきた。「4 ? 4 ? 4 ? 4 = 2」

よくあるクイズ。計算機の力を使わずに解きたくない。 [{'expr': ((4, '*', 4), '/', (4, '+', 4)), 'ans': 2}, {'expr': ((4, '/', 4), '+', (4, '/', 4)), 'ans': 2}, {'expr': (4, '-', ((4, '+', 4), '/', 4)), 'ans': 2}, {'expr': (4, '/', ((4, '+', …

problem43

import itertools def is_ok(ns): for i, x in zip(range(1, 9), (2, 3, 5, 7, 11, 13, 17)): if not ((100*ns[i]+10*ns[i+1]+ns[i+2]) % x == 0): return False return True cnt = 0 for ns in itertools.permutations(range(10), 10): if is_ok(ns): cnt +…

problem42

アルファベットを数字に対応させた際の単語の和が三角数になるものの数を数える問題。 まだ、どのように書けば十分なのかというのが把握できていない。これはクラスにした方が良かったかもしれない。 def _str_to_val(offset): def _calc(s): n = 0 for c in…

sibilant

ちょっと癖のあるnode.js上のlisp->jsトランスレータ http://sibilantjs.info/#welcomecombinationsとか作ってみた。 (puts '(1 2 3 4)) (puts (append-map '(1 2 3 4) (lambda (x) (list x (* x x))))) (puts (combinations (list 1 2 3 4) 2)) result sibi…