Skip to content

Use binary literals in the secret-handshake example - #893

Merged
rabestro merged 2 commits into
mainfrom
binary-literals-secret-handshake
Sep 23, 2026
Merged

rabestro merged 2 commits into
mainfrom
binary-literals-secret-handshake

Conversation

@rabestro

Copy link
Copy Markdown
Member

Fixes #892.

#882 bumped the track to Scala 3.9.0 LTS specifically to unlock binary integer literals, citing secret-handshake as 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 = 16

After 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 published exercism/scala-test-runner image, so the syntax works in the environment students are graded in, not just locally.

🤖 Generated with Claude Code

Jegors Cemisovs and others added 2 commits September 23, 2026 18:13
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>
@rabestro rabestro self-assigned this Sep 23, 2026
@rabestro rabestro added x:rep/tiny Tiny amount of reputation and removed x:rep/tiny Tiny amount of reputation labels Sep 23, 2026
@IsaacG

IsaacG commented Sep 23, 2026

Copy link
Copy Markdown
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

@rabestro
rabestro merged commit cda3978 into main Sep 23, 2026
12 checks passed
@rabestro
rabestro deleted the binary-literals-secret-handshake branch September 23, 2026 21:59
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.

Use binary literals in the secret-handshake example now that the track is on Scala 3.9

2 participants