Osaka Erlang Meeting #1
03-Jun-2007, Toyonaka, Hotarugaike
1. RTFM
Most of the time was just reading the japanese translation of the “Programming Erlang” book. 53 pages full of japanese ;) Pretty difficult task. All people divided in 2 groups – have already started erlang at least once, still not. The beginners – needed to read all pages as fast as possible and merge with the first group – also difficult task ;)
fun function_name/args_num %% for example %% fun fizzbuzz/1. <=> fun(X)-> fizzbuzz(X) end.
interesting: soap – ajax – comet relation :)
2. roman2integer or integer2roman
In the last 30-40 minutes we’ve got an interesting task to code – convert old roman to/from integer. I decided to go with the integer to roman part of the problem. There was not enough time on the meeting, so I continued in the nearest Starbucks, and in home…Hm, Erlang is catchy ;) OK. so about the initial approximation of the solution:
%% convert integer to old roman %% usage: %% convert:to_roma(555) -> "DLV" %% convert:to_roma(999) -> "DCCCCLXXXXVIIII" -module(convert). -compile(export_all). -define(R,[1000,500,100,50,10,5,1]). i2r(1) -> "I"; i2r(5) -> "V"; i2r(10) -> "X"; i2r(50) -> "L"; i2r(100) -> "C"; i2r(500) -> "D"; i2r(1000) -> "M". repeat(Times,X) -> lists:duplicate(Times,i2r(X)). to_roma(X) -> lists:flatten(to_roma(X,?R)). to_roma(_,[]) -> []; to_roma(X,[H|T]) -> {Div, Rem} = {X div H, X rem H}, if Div > 0 -> [repeat(Div,H)|to_roma(Rem,T)]; true -> to_roma(Rem,T) end.
Still don’t like the first part. Need more efficient i2r() implementation. All advices, suggestions for improving are welcome.