Repository navigation
Use binary literals in the secret-handshake example - #893
Merged
Merged
Conversation
The exercise's instructions give the gesture values in binary:
00001 = wink
00010 = double blink
00100 = close your eyes
01000 = jump
10000 = Reverse the order of the operations in the secret handshake.
while the example gave them in decimal, so reading the two side by side
meant converting between representations.
Binary literals need Scala 3.5 or later, which the track only got in #888
(3.9.0 LTS). This is the readability improvement #882 asked for, and the
track's first use of the syntax.
allergies was considered and deliberately left alone: its instructions
list the allergen values in decimal, so the same change would make its
example diverge from its spec rather than match it. variable-length-quantity
already names its masks (0x7f, 0x80) and reads fine as it is.
Verified with `bin/test secret-handshake` (11 tests) and
`bin/verify-exercises-in-docker secret-handshake` against the published
test runner image.
Fixes #892
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
IsaacG
approved these changes
Sep 23, 2026
Member
|
Eh. The example just shows this exercise can be solved. So long as it works, it doesn't matter too much how it's done :D |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #892.
#882 bumped the track to Scala 3.9.0 LTS specifically to unlock binary integer literals, citing
secret-handshakeas the motivating case. The bump shipped, but nothing used the syntax —grep -rn '0b[01_]\+' exercises/ --include='*.scala'had no matches until this PR.Why this one exercise
The instructions give the gesture values in binary, while the example gave them in decimal, so checking one against the other meant converting representations:
.docs/instructions.md.meta/Example.scala(before)00001 = wink(1, "wink")00010 = double blink(2, "double blink")00100 = close your eyes(4, "close your eyes")01000 = jump(8, "jump")10000 = Reverse the order…reverseGestures = 16After this change the two line up character for character.
Exercises checked and deliberately not changed
The issue asked for a sweep of other bitwise exercises. Two were close enough to look at:
allergies— has the same shape (eight power-of-two values combined with&), but its instructions list them in decimal (eggs (1),peanuts (2), …cats (128)). Converting the example to binary would make it diverge from its own spec, which is the opposite of the argument here. Left alone.variable-length-quantity— already names its masks (sevenBitsMask = 0x7f,eightBitMask = 0x80). Hex is the right representation for byte masks and it reads fine. Left alone.So this stays a one-exercise change.
Verification
bin/test secret-handshake— 11 tests pass.bin/verify-exercises-in-docker secret-handshake— exit 0 against the publishedexercism/scala-test-runnerimage, so the syntax works in the environment students are graded in, not just locally.🤖 Generated with Claude Code