Add alphametics exercise (#312) - #443
Conversation
Co-authored-by: Glenn Jackman <glenn.jackman@gmail.com>
Co-authored-by: Glenn Jackman <glenn.jackman@gmail.com>
Co-authored-by: Glenn Jackman <glenn.jackman@gmail.com>
…tava22/awk into exercise/alphametics
| @test "{{ case.description }}" { | ||
| run awk -f alphametics.awk <<< "{{ case.input.puzzle }}" | ||
| assert_success | ||
| assert_output "{% if case.expected %}{% for letter, digit in case.expected.items() | sort %}{{ letter }}={{ digit }}{% if not loop.last %} {% endif %}{% endfor %}{% endif %}" |
There was a problem hiding this comment.
If there is no output, we probably want to test for that explicitly with refute_output.
Co-authored-by: Isaac Good <IsaacG@users.noreply.github.com>
Co-authored-by: Isaac Good <IsaacG@users.noreply.github.com>
|
Please review and tell any more modifications required |
IsaacG
left a comment
There was a problem hiding this comment.
Was the template used to generate the tests?
| } | ||
| print out | ||
| } else { | ||
| print "" |
There was a problem hiding this comment.
We probably don't need to print an empty line when there's no solution :)
|
Fixed the {% %} → {{ }} typo and idx → loop.first in the template, removed the empty-line print in example.awk, and regenerated the bats file. @IsaacG — to your question, the .bats file wasn't in sync with the template before this push; it should be now. If you have the generator command handy, happy to confirm by rerunning it rather than my manual version. |
|
|
Fixed the template's idx/case unpacking and the null-output branch in example.awk, then regenerated test-alphametics.bats with bin/generate_tests — diff picked up both the skip-guard lines and the refute_output change as expected. |
|
I was just holding back on approving until I was at a machine where I could see how long this took to run. But then I realized I could just look at the check. 10 sec is reasonable. |
Closes #312
Implements the alphametics solver using a column-by-column backtracking
approach (right-to-left, with carry propagation), which prunes far more
aggressively than brute-force permutation — verified against all canonical
test cases including the 199-addend case.
I don't have gawk/bats set up locally on this machine — happy to fix
anything CI flags.