Add tags

Add tags to the following comment
erl_evalと Erlang特有のN進法表記(N#M, 基数Nは36以下)を
使ってみたらどうだろうと思って書いてみました。
基数に上限があるので汎用性に欠けると思います。

プログラムを bai13.erl というファイル名で保存して、
$ erl -noshell -s bai13 getfirst -s init stop
のようにして起動します。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
-module(bai13).
-export([getfirst/0]).

getfirst() ->
    loop(10).

loop(N) ->
    case (eval("13#" ++ integer_to_list(N) ++ ".") rem N) of
        0 -> io:format("~p~n",[N]);
        true -> loop(N + 1)
    end.

eval(Expr)->
    {ok, Tokens, _}=erl_scan:string(Expr),
    {ok,[Expression]} = erl_parse:parse_exprs(Tokens),
    {value, Ret,_} = erl_eval:expr(
        Expression ,erl_eval:bindings(erl_eval:new_bindings())
        ),
  Ret.

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...