JEG2 / advent_of_code_2016

My solutions to the 2016 Advent of Code problems: http://adventofcode.com/
11 stars 1 forks source link

String.next_grapheme vs Regular Expression #1

Closed billc closed 7 years ago

billc commented 7 years ago

I love the simplicity of your code over mine. You have great organizational structure and the code is easy to follow.

A question for you: String.next_grapheme/1 was a function I was unfamiliar with and perfect for the job. Yet, in the second problem you switched to a regular expression. What was the reason?

JEG2 commented 7 years ago

I did like String.next_grapheme/1, but it gave me a structure like [{"L", "2"}, {"R", "13"}, …] and I wanted to get to a flat stream of events: ["L", "2", "R", "13", …]. It may not have been a wise trade though.

billc commented 7 years ago

Gotcha! I used a pattern match on the function to break up the string binary into direction and distance i.e '"L" <> distance'. The grapheme method appears simpler.

Hopefully I can stop wrestling with Spacemacs on Windows not tabbing in the Elixir layer and catch up on Day 2. Look forward to comparing your solutions.

-- Bill Christian

On December 3, 2016 at 1:00:04 AM, James Edward Gray II ( notifications@github.com) wrote:

I did like String.next_grapheme/1, but it gave me a structure like [{"L", "2"}, {"R", "13"}, …] and I wanted to get to a flat stream of events: ["L", "2", "R", "13", …]. It may not have been a wise trade though.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/JEG2/advent_of_code_2016/issues/1#issuecomment-264619672, or mute the thread https://github.com/notifications/unsubscribe-auth/AAXzox4McsRVJn-cnvwsYQ2ubqVotKfYks5rEQVkgaJpZM4LDKvW .