Wednesday 16 October 2013

MINCOUNT

%Erlang code for 1167. Move To Invert Problem code: MINCOUNT

-module(tested).
-export([main/0]).

main() ->
    {ok, [N]} = io:fread("","~d"),
    coin_moves(T).

coin_moves(T) when T==0 ->
    halt();
coin_moves(T) when T>0 ->
    {ok, [H]} = io:fread("","~d"),
   
    case H of
    0 -> io:format("0~n"),
    _ ->
        K = H div 3,
        io:format("~p~n", [3*K*(K+1)div 2 + ((H-1)rem 3)*(K+1)])
    end.