Skip to content

Instantly share code, notes, and snippets.

View pazworld's full-sized avatar

pazworld pazworld

View GitHub Profile
@pazworld
pazworld / mafovafo.erl
Created January 29, 2014 01:11
「山折り谷折り」をErlangで(横へな18参考) ref: http://qiita.com/pazworld/items/05c22ca8a3913b5b5b7e
-module(mafovafo).
-compile(export_all).
solve(Data) -> to_s(lists:foldl(fun unfold/2, [] , lists:reverse(Data))).
to_s(L) -> [case C of 0 -> $V; 1 -> $m end || C <- L].
unfold($L, L) -> rev(L) ++ [0] ++ L;
unfold($J, L) -> L ++ [0] ++ rev(L);
unfold($Z, L) -> L ++ [1] ++ rev(L) ++ [0] ++ L;
@pazworld
pazworld / foldcut.erl
Created January 17, 2014 08:57
「折って切る」をErlangとRubyで(横へな17) ref: http://qiita.com/pazworld/items/8ba64dcf900e0548f402
-module(foldcut).
-compile(export_all).
solve(Data) ->
integer_to_list(solve2(string:tokens(string:to_upper(Data), "-"))).
solve2([S, [AY, AX]]) ->
trunc(holenum(filter("LR", S), AX) * holenum(filter("TB", S), AY)).
filter([C1, C2], L) -> lists:filter(fun(X) -> (X =:= C1) or (X =:= C2) end, L).
@pazworld
pazworld / sheh.erl
Created January 3, 2014 10:47
「回文基数」をErlangとRubyで(横へな17参考) ref: http://qiita.com/pazworld/items/3b936680585b60ad82c3
-module(sheh).
-compile(export_all).
solve(Data) -> bases(list_to_integer(Data)).
bases(1) -> "-";
bases(X) -> to_s(lists:filter(fun(Base) ->
X =:= rev(X, Base, 0) end, lists:seq(2, X - 1))).
to_s([]) -> "-";
@pazworld
pazworld / zokugara.erl
Created January 1, 2014 01:15
「続柄」をErlangで(横へな6) ref: http://qiita.com/pazworld/items/f9a1c5df2c9de948e4d4
-module(zokugara).
-compile(export_all).
solve(Data) -> relation(
[moms(list_to_integer(X)) || X <- string:tokens(Data, "->")]).
relation([X, Y | _]) -> relation(X, Y).
relation({X, _, _}, {X, _, _}) -> "me";
relation({_, X, _}, {X, _, _}) -> "mo";
relation({X, _, _}, {_, X, _}) -> "da";
@pazworld
pazworld / xysort.erl
Created December 18, 2013 02:33
「XY-Sort」をErlangで(横へな7参考) ref: http://qiita.com/pazworld/items/8c2316f2a7feb0671040
-module(xysort).
-compile(export_all).
table() -> [
[4, 1, 4, 2, 1, 3], [7, 3, 2, 0, 5, 0], [2, 3, 6, 0, 6, 7],
[6, 4, 5, 7, 5, 1], [3, 1, 6, 6, 2, 4], [6, 0, 5, 5, 5, 1]].
solve(Data) -> [X + $0 || X <- hd(lists:foldl(fun(C, Tbl) ->
sort(C, Tbl) end, table(), Data))].
@pazworld
pazworld / boseg.erl
Created December 12, 2013 02:48
「境界線分」をErlangで(横へな16) ref: http://qiita.com/pazworld/items/90f060fb465ff44a7caf
-module(boseg).
-compile(export_all).
solve(Data) ->
string:join([integer_to_list(X) || X <- boundlen(oct2bin(Data))], ",").
oct2bin([]) -> [];
oct2bin([X, Y | T]) -> [string:right("00000" ++
integer_to_list(list_to_integer([X, Y], 8), 2), 6) | oct2bin(T)].
@pazworld
pazworld / delurlquery.js
Created December 10, 2013 04:19
URLの?以降を削除するブックマークレット
javascript:(function(){location.href=location.href.replace(/\?.*$/,'');})();
@pazworld
pazworld / lcove.erl
Created November 26, 2013 11:30
「L被覆」をErlangで(横へな16参考) ref: http://qiita.com/pazworld/items/b1f3797e2392a32d2d63
-module(lcove).
-compile(export_all).
%% 解く
solve(Data) ->
% 1の位と10の位に分ける関数
F = fun(SX) -> X = list_to_integer(SX), {X div 10, X rem 10} end,
area([F(SX) || SX <- string:tokens(Data, ",")]).
%% L字型の面積を求める
@pazworld
pazworld / selectchair.sed
Created November 25, 2013 04:24
「のんびり座りたい」をsedで(横へな7) ref: http://qiita.com/pazworld/items/580046584b76f08da7cb
# 数→椅子
s/1\([0-9]\)/55\1/
s/2\([0-9]\)/5555\1/
s/3\([0-9]\)/555555\1/
s/9/54/
s/8/53/
s/7/52/
s/6/51/
s/5/-----/g
s/4/----/
@pazworld
pazworld / elebubo.sed
Last active December 28, 2015 15:39
「異星の電光掲示板」をsedで(横へな15) ref: http://qiita.com/pazworld/items/ff45058501299089c198
# 16進数→2進数
s/0/0000/g
s/1/0001/g
s/2/0010/g
s/3/0011/g
s/4/0100/g
s/5/0101/g
s/6/0110/g
s/7/0111/g
s/8/1000/g