2011-06-01から1ヶ月間の記事一覧

10 進数を平衡三進数に変換する haskell ワンライナー: bt x = aux [] x where aux ts x = let (q, r, y, ts') = (div y 3, mod y 3, x + 1, r - 1 : ts) in if (0 == q) then ts' else aux ts' q

世の中に平衡三進数、あるいは対称三進数、英語で言えば balanced ternary というものがあると知ったのが昨日のこと。(「http://www.amazon.co.jp/gp/product/4622075482/ref=as_li_ss_tl?ie=UTF8&tag=ryohji-22&linkCode=as2&camp=247&creative=7399&creat…

今日の単語:shock

あたらしいカーペットはジョーイをショック状態におとしいれた。 信じられない。 黄色だって? このカーテンと? なんてくs The new carpet sent Joey into shock. It sent him into a state of disbelief. Yellow? With those curtains? What the fu My Fi…

この数値より小さいことをテストする

パフォーマンス調査用のテストケースで if (timeDiff > 200) fail(); のように書かれていたのを assertTrue(timeDiff どうせならテストの結果で expected: but was: と表示されるようにしたいなあ…ってんでつくってみました。 class LessThanEqualTo { priva…

コマンドラインのプリプロセッサー定義で文字列を渡す

$ cc -o hello hello.c -DHELLO="\"hello, world!\"" $ ./hello hello, world!などと、コンパイルオプションで渡した文字列をソースコードで使うにはどうしたらいいか?解答編: #define quote(x) q(x) #define q(x) #x #include <stdio.h> int main() { puts(quote(H</stdio.h>…