Skip to content

Instantly share code, notes, and snippets.

View pazworld's full-sized avatar

pazworld pazworld

View GitHub Profile
@pazworld
pazworld / sleepmonster.erl
Last active December 24, 2015 21:19
「眠れるモンスターを狩る」をErlangで(横へな14) ref: http://qiita.com/pazworld/items/b93f1a7a84ebadf22ab4
-module(sleepmonster).
-compile(export_all).
%% 武器・モンスター対応表 {武器, 倒せるモンスター, 得られる武器}
table() -> [{$a, $B, $c}, {$c, $D, $e}, {$e, $F, $g},
{$g, $H, $i}, {$i, $J, $k}, {$k, $L, $a}].
%% 解く
solve(Data) ->
Arms = lists:usort([X || X <- Data, X > $Z]), % 小文字のみ集める
%% トップクラスだけが知る「このアルゴリズムがすごい」 - 「探索」基礎最速マスター
%% http://www.itmedia.co.jp/enterprise/articles/1002/06/news001_3.html
-module(cutsticks).
-compile(export_all).
%% 最大試行回数
-define(MAXTRIALS, 100).
%% 解く
@pazworld
pazworld / subpalin.erl
Created November 16, 2013 02:00
「回文の発掘」をErlangで(横へな15参考) ref: http://qiita.com/pazworld/items/f8d7e7f9c7a29e9b38ab
-module(subpalin).
-compile(export_all).
%% 解く
solve(Data) -> integer_to_list(palinnum(Data)).
%% 回文の最大長を返す
palinnum([]) -> 0;
palinnum(L) -> lists:max([palinnum2(S) || S <- tailcombi(L)]).
@pazworld
pazworld / showpiximg_iphone.js
Last active December 28, 2015 11:59
Bookmarklet to show deleted images in pix page.
javascript:var e,i,p,u,m,k="1e100.link/";e=document.getElementsByTagName("a");for(i=0;i<e.length;i++){u=e[i].getAttribute("href");if(u&&u.indexOf(k)>=0){e[i].setAttribute("href",u.replace(k,""));}if(u&&u.match(/jpg|jpeg|png|gif/i)){e[i].setAttribute("target","_blank");}if(u&&u.indexOf("amazon.jp/")>=0){e[i].firstChild.style.border="dashed 2px red";}}e=document.getElementsByTagName("i");for(i=0;i<e.length;i++){if((e[i].textContent=="DELETED")||(e[i].textContent=="CHECKING")){p=e[i].parentNode;u=p.getAttribute("href");m=document.createElement("img");p.appendChild(m);m.setAttribute("src",u.replace("newpage:",""));m.style.border="solid 1px yellow";}};
@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
@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 / 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 / delurlquery.js
Created December 10, 2013 04:19
URLの?以降を削除するブックマークレット
javascript:(function(){location.href=location.href.replace(/\?.*$/,'');})();
@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 / 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))].