Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow day argument to be "0" padded #34

Merged
merged 6 commits into from
Dec 10, 2024

Conversation

YozuChris
Copy link
Contributor

@YozuChris YozuChris commented Dec 9, 2024

Currently, if you run a command with a "0" padded day argument for example: aoc exec 2024 01 you'll get an error:

2024 Day 03
no result for part 1
Submit solution?  (y/N)
y
We said y
/home/chris/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/aoc_rb-0.2.9/lib/aoc_rb/puzzle_solution.rb:25:in `submit': undefined method `content' for nil (NoMethodError)

      puts articles[0].content
                      ^^^^^^^^
        from /home/chris/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/aoc_rb-0.2.9/lib/aoc_rb/app.rb:118:in `exec'
        from /home/chris/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/thor-1.3.2/lib/thor/command.rb:28:in `run'
        from /home/chris/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/thor-1.3.2/lib/thor/invocation.rb:127:in `invoke_command'
        from /home/chris/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/thor-1.3.2/lib/thor.rb:538:in `dispatch'
        from /home/chris/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/thor-1.3.2/lib/thor/base.rb:584:in `start'
        from bin/aoc:37:in `<main>'

This is because the arguments are passed in as strings to the command and so when the API is called, puzzle_path returns /2024/day/01, which is incorrect. I didn't expect this, especially since the challenge folders are 0 padded.

Calling the command with options instead of arguments, for example: aoc exec -y=2024 -d=01, works as expected since type: :numeric normalises the option input to a numeric value.

This PR normalises the day input to a numeric value when generating the path, so aoc exec 2024 01 and aoc exec 2024 1 both work as expected.

Thanks!

@pacso
Copy link
Owner

pacso commented Dec 10, 2024

Hey @YozuChris - thanks for this submission.

It looks like we have the same issue with any of the commands, but the same fix will resolve each of them.

Could you write some specs to cover this behaviour, and update the changelog?

@YozuChris
Copy link
Contributor Author

@pacso Done!

@pacso
Copy link
Owner

pacso commented Dec 10, 2024

Hey @YozuChris - I was just testing this now that I'm able to, and I can't actually reproduce your error.

Using ruby 3.3.6 I get the following results with the latest version of the gem:

vscode ➜ /IdeaProjects/advent-of-code (main) $ aoc output 2024 08
Result for part 1:
392
(obtained in 0.0006846659816801548 seconds)

Result for part 2:
1235
(obtained in 0.0012198749464005232 seconds)
vscode ➜ /IdeaProjects/advent-of-code (main) $ aoc output 2024 8
Result for part 1:
392
(obtained in 0.0006988340173847973 seconds)

Result for part 2:
1235
(obtained in 0.0013187090517021716 seconds)

What version of ruby and aoc_rb are you using? I'd like to reproduce the error before making any changes.

@YozuChris
Copy link
Contributor Author

YozuChris commented Dec 10, 2024

@pacso I'm using Ruby 3.3.6 aoc_rb 0.2.9

I would guess that you're not encountering the issue since output doesn't call the API, whereas exec and then selecting y to submit does and definitely produces the error.

@pacso
Copy link
Owner

pacso commented Dec 10, 2024

Yep - spot on. Thanks for your help sorting this!

@pacso pacso merged commit b89d6a3 into pacso:main Dec 10, 2024
4 checks passed
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