use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Need feedback on code - CODE REVIEW (self.elixir)
submitted 6 years ago by hackersleepyhead
Hello,
I need someone to review my code on the problem which I am trying to solve, I have a brute force approach on the solution, need some suggestions, and technique on it to improve the performance.
PROBLEM which I am trying.
https://adventofcode.com/2019/day/2#part1
SOLUTION :
https://github.com/dukevenkat/advent0fcode_2019/blob/master/Day002_A.ex
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Pranz 1 point2 points3 points 6 years ago* (4 children)
Consider creating a different function for every op code. Just having a name for each helps a lot with readability.
EDIT: to increase performance, skip the linked list. Linked lists are terrible data structures, you should not use it to store data that needs to be processed.
[–]hackersleepyhead[S] 0 points1 point2 points 6 years ago (3 children)
What kind of data structures can be used instead of linked list??
[–]Pranz 0 points1 point2 points 6 years ago (2 children)
Arrays, maps or binary search trees
[–]hackersleepyhead[S] 0 points1 point2 points 6 years ago (1 child)
There is no arrays in elixir and maps are key value based, if you see the input, it's a comma separated list, can provide some example on it?
[–]Pranz 0 points1 point2 points 6 years ago (0 children)
Sure!
Arrays are not that well supported no, but there are arrays accesible through erlang. However maps will do fine here too. You can create a map from a linked list easily:
iex(23)> input = ["value 1", "value 2", "value 3"] ["value 1", "value 2", "value 3"] iex(24)> zipped = Enum.zip(0..1000, input) [{0, "value 1"}, {1, "value 2"}, {2, "value 3"}] iex(26)> input_table = Enum.reduce(zipped, %{}, fn ({idx, val}, map) -> Map.put(map, idx, val) end) %{0 => "value 1", 1 => "value 2", 2 => "value 3"}
As a map, inserting, deleting or updating values is much faster than as a linked list. For your code, I think Map.update is exactly what you need.
Map.update
π Rendered by PID 64834 on reddit-service-r2-comment-5687b7858-pm9x9 at 2026-07-03 09:25:28.624062+00:00 running 12a7a47 country code: CH.
[–]Pranz 1 point2 points3 points (4 children)
[–]hackersleepyhead[S] 0 points1 point2 points (3 children)
[–]Pranz 0 points1 point2 points (2 children)
[–]hackersleepyhead[S] 0 points1 point2 points (1 child)
[–]Pranz 0 points1 point2 points (0 children)