[erlang-questions] Re: [erlang-questions 41] Re: A sudoku solver in Erlang compared to Python
Andreas Pauley
apauley@REDACTED
Tue Mar 29 15:13:59 CEST 2011
Thanks!
https://github.com/apauley/sudoku-in-erlang/commit/9c69a9d813a9c5e0b6e41471eb3e3df5ea284a4d
The 3 inlined functions are now dead, so I just removed them.
On Tue, Mar 29, 2011 at 1:40 PM, Kresten Krab Thorup <krab@REDACTED> wrote:
> Hi,
>
> On Mar 28, 2011, at 15:22 , Andreas Pauley wrote:
>
>> I'd love to use atoms as square names, just because it looks cleaner.
>> However, I'm getting a severe performance hit when I use
>> list_to_atom/1 on each square name.
>>
>> Can you show me how you did it in conjunction with ct_expand?
>
> These are the changed functions, [and then the unit tests need to be updated accordingly]... ct_expand doesn't like function applications, so the function unitlist() needs to have the other definitions inlined.
>
> Kresten
>
>
> squares() ->
> %% Returns a list of 81 square names, including "a1" etc.
> ct_expand:term([erlang:list_to_atom([X,Y]) || X <- ?rows, Y <- ?cols]).
> col_squares() ->
> %% All the square names for each column.
> ([[erlang:list_to_atom([X,Y]) || X <- ?rows, Y <- [C]] || C <- ?cols]).
> row_squares() ->
> %% All the square names for each row.
> ct_expand:term([[erlang:list_to_atom([X,Y]) || X <- [R], Y <- ?cols] || R <- ?rows]).
> box_squares() ->
> %% All the square names for each box.
> ct_expand:term([[erlang:list_to_atom([X,Y]) || X <- R, Y <- C] ||
> R <- ["abc", "def", "ghi"],
> C <- ["123", "456", "789"]]).
>
> unitlist() ->
> %% A list of all units (columns, rows, boxes) in a grid.
> ct_expand:term( [[erlang:list_to_atom([X,Y]) || X <- ?rows, Y <- [C]] || C <- ?cols]
> ++ [[erlang:list_to_atom([X,Y]) || X <- [R], Y <- ?cols] || R <- ?rows]
> ++ [[erlang:list_to_atom([X,Y]) || X <- R, Y <- C] ||
> R <- ["abc", "def", "ghi"],
> C <- ["123", "456", "789"]]).
>
>
More information about the erlang-questions
mailing list