Skip to content

Conversation

@Duxy1996
Copy link
Collaborator

@Duxy1996 Duxy1996 commented Dec 9, 2017

Duxy's solution for day 9 challenge

Description

Given a string, get the score of the groups generated(avoiding the garbage sequences )
Get the number of chars of the garbage sequences

Solution

I iterate the string, and I have 3 flags (for the groups, for the rubbish and for the jump characters ) every time I see a the indicates character i add one or substract one to the flags. Depending of the number of each flag the program do some operations; ej: if the flag of garbage is > 0 I cant modify the groups's tag.

Tests battery

I have donde test for each example given in the AOC day 9, and then other extra mixing it all together.

{}, score of 1.
{{{}}}, score of 1 + 2 + 3 = 6.
{{},{}}, score of 1 + 2 + 2 = 5.
{{{},{},{{}}}}, score of 1 + 2 + 3 + 3 + 3 + 4 = 16.
{<a>,<a>,<a>,<a>}, score of 1.
{{<ab>},{<ab>},{<ab>},{<ab>}}, score of 1 + 2 + 2 + 2 + 2 = 9.
{{<!!>},{<!!>},{<!!>},{<!!>}}, score of 1 + 2 + 2 + 2 + 2 = 9.
{{<a!>},{<a!>},{<a!>},{<ab>}}, score of 1 + 2 = 3.

I use the engine of ruby. This tests were very useful, I recommend to see them.

Happy Advent of Code!

Copy link
Member

@Cotel Cotel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The algorithm is quite similar to mine 💯

end
return score
end
end No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, big file here. I would recommend you to separate and reuse code. Follow the DRY principle 😉

end
numofgroups = 0
groups_open = 0
novalid = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see you are using novalid as a boolean. Using int flags can be quite tough to read.

numofgroups = 0
groups_open = 0
novalid = 0
garbage_open = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

return score
end

end No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better spacing in this file 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants