Skip to content

Instantly share code, notes, and snippets.

View pazworld's full-sized avatar

pazworld pazworld

View GitHub Profile
@pazworld
pazworld / eq2.erl
Created June 29, 2013 08:16
「エイト・クイーン問題」をErlangで その2 ref: http://qiita.com/pazworld/items/b3316f32fc14d1774087
% solve 8-queens problem.
-module(eq2).
-export([solve/0, solve_count/0, solve_display/0]).
% Solve and return answer as a list of lists.
solve() -> solve(1, [], []).
% Solve and return count of answers.
solve_count() -> length(solve()).
@pazworld
pazworld / bus.erl
Last active December 19, 2015 08:38
第9回オフラインリアルタイムどう書く Erlang による実装 ref: http://qiita.com/pazworld/items/e641fd71af82a99f92e2
-module(bus).
-compile(export_all).
solve(Data) -> adult_fee(Data) + child_fee(Data) + infant_fee(Data).
adult_fee(Data) -> lists:sum(fees($A, Data)).
child_fee(Data) -> lists:sum(fees($C, Data)).
infant_fee(Data) -> lists:sum(dropn(num_adult(Data) * 2, rev_sort(fees($I, Data)))).
@pazworld
pazworld / dice.erl
Created July 9, 2013 05:37
「サイコロを転がす」をErlangで(横へな12) ref: http://qiita.com/pazworld/items/53d3bf2ca4216cae27f0
-module(dice).
-export([tests/0, test/2, solve/1]).
solve(Data) ->
{_Dice, L} = lists:foldl(fun rotate_add/2, {{1,2,3}, [1]}, Data),
[Digit + $0 || Digit <- lists:reverse(L)].
rotate_add(Dir, {Dice, L}) ->
NewDice = rotate(Dir, Dice),
{NewDice, [element(1, NewDice) | L]}.
@pazworld
pazworld / combi.scm
Last active December 20, 2015 01:59
「数を作る」をSchemeで(横へな9参考) ref: http://qiita.com/pazworld/items/226324031ed86a6b284c
;; 与えられた整数リストから4つを使った全組み合わせを返す
(define (combi4 unselected selected)
(define (delete-one x ls) ;; xを1つだけ削除したリストを返す
(cond
((null? ls) '())
((= x (car ls)) (cdr ls))
(else (cons (car ls) (delete-one x (cdr ls))))))
(define (if6append9 x f) ;; xが6以外ならf(x)を、6ならf(6)とf(9)を連結して返す
(if (= x 6)
(append (f 6) (f 9))
@pazworld
pazworld / bitbomb.erl
Created August 9, 2013 10:42
ビットボンバーマンをErlangで(横へな8) ref: http://qiita.com/pazworld/items/73b8392c5972b8c7db2c
-module(bitbomb).
-compile(export_all).
%% 問題を解く
solve(Data) ->
{Wall, Bomb} = list_to_tuple([list_to_integer(X, 16)
|| X <- string:tokens(Data, "/")]),
DirInfo = [ % シフト方向とシフト時マスクのデーター
{-6, 2#00000011111111111111111111111100}, % 上
{-1, 2#01111101111101111101111101111100}, % 左
@pazworld
pazworld / auto_backup.cmd
Last active December 21, 2015 05:18
BunBackupを使ったバックアップスクリプト。 このスクリプトファイルのショートカットを作成し、実行時サイズを「最小化」に設定して、ファイルのフルパスをWindowsのタスクスケジューラに登録する。
@echo off
rem 名前
rem 自動バックアップ.cmd - BunBackupを使って自動バックアップをする
rem 書式
rem 自動バックアップ.cmd
rem 説明
rem BunBackupを使って自動バックアップを実行する。
@pazworld
pazworld / updown.erl
Last active December 21, 2015 11:59
「増やす減らす二倍する」をErlangで(横へな13参考) ref: http://qiita.com/pazworld/items/aea5a92b0825f7e3072d
-module(updown).
-compile(export_all).
solve(Data) ->
integer_to_list(op_count(list_to_integer(Data), 0)).
%% 結果が1か3になるまで2で割るか1を増減し、その回数を返す
op_count(1, Count) -> Count + 1;
op_count(3, Count) -> Count + 3;
op_count(Num, Count) ->
@pazworld
pazworld / file0.txt
Created August 27, 2013 01:55
「増やす減らす二倍する」をCASL IIで(横へな13参考) ref: http://qiita.com/pazworld/items/c7e31e73af1ef33c5b4a
UPDOWN START TEST ;TESTからスタートする
;解くルーチン
;GR1=値, GR2=カウンタ, GR0=戻り値
SOLVE OR GR1,DC0 ;値が0ならカウンタ値を返す
JNZ NOT0
LAD GR0,0,GR2
RET
NOT0 CPL GR1,DC3 ;値が3ならカウンタ値に3を加えて返す
JNZ NOT3
@pazworld
pazworld / blocktub.erl
Created September 7, 2013 06:14
「積み木の水槽」をErlangで(横へな13) ref: http://qiita.com/pazworld/items/6a43a085fba30c584a9f
-module(blocktub).
-compile(export_all).
%% 問題を解く
solve(Data) ->
integer_to_list(pit_count([Digit - $0 || Digit <- Data])).
%% 窪みの数を計算する
pit_count(Data) ->
Max = lists:max(Data), % 壁の最大高さ
@pazworld
pazworld / crosscircle.erl
Created October 4, 2013 03:53
「円周上のCrossing」をErlangで(横へな14参考) ref: http://qiita.com/pazworld/items/a6a29d5d95200c0379b7
-module(crosscircle).
-compile(export_all).
%% 解く
solve(Data) ->
integer_to_list(solve([{X, 0} || X <- Data], 0)).
solve([], Total) ->
Total;
solve([{FirstChar, _} | Rest], Total) ->