read numbers

Roger Lipscombe roger@REDACTED
Thu Dec 9 15:24:28 CET 2021


On Thu, 9 Dec 2021 at 13:29, Java House <java4dev@REDACTED> wrote:
> Thank you Roger for the answer
> I thought about it but since I have to parse all digits for every row that would mean a lot of entries as I have to create all possible combinations of 0/1 for every position of the row.

parse(Data) -> parse(Data, [], []).

parse(<<"0", Rest/binary>>, Line, Lines) ->
    parse(Rest, [false | Line], Lines);
parse(<<"1", Rest/binary>>, Line, Lines) ->
    parse(Rest, [true | Line], Lines);
parse(<<$\n, Rest/binary>>, Line, Lines) ->
    parse(Rest, [], [lists:reverse(Line) | Lines]);
parse(<<>>, [], Lines) -> lists:reverse(Lines);
parse(<<>>, Line, Lines) -> lists:reverse([lists:reverse(Line) | Lines]).

...results in...

[[true,true,true,false,true,true,false,false,true,false,true,false],
 [false,true,false,false,true,true,true,false,true,true,true,false],
 [true,true,false,false,false,true,false,false,true,false,true,false],
 [false,false,true,true,false,true,false,true,true,true,false,true],
 [true,true,false,true,false,false,false,false,false,false,true,true],
 [false,true,false,true,true,false,true,true,false,false,true,false]]


More information about the erlang-questions mailing list