Skip to content

Commit cda3978

Browse files
rabestroJegors Cemisovsclaude
authored
Use binary literals in the secret-handshake example (#893)
* Use binary literals in the secret-handshake example 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> * Add rabestro to the secret-handshake contributors Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Jegors Cemisovs <jcemisovs@evolution.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent bf30773 commit cda3978

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

‎exercises/practice/secret-handshake/.meta/Example.scala‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
object SecretHandshake {
2-
private val reverseGestures = 16
3-
private def gestures = List((1, "wink"), (2, "double blink"),
4-
(4, "close your eyes"), (8, "jump"))
2+
private val reverseGestures = 0b10000
3+
private def gestures = List((0b00001, "wink"), (0b00010, "double blink"),
4+
(0b00100, "close your eyes"), (0b01000, "jump"))
55

66
def commands(s: String): List[String] = {
77
def isValid = s.count(c => c != '0' && c != '1') == 0

‎exercises/practice/secret-handshake/.meta/config.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"contributors": [
66
"ErikSchierboom",
77
"ppartarr",
8+
"rabestro",
89
"rajeshpg"
910
],
1011
"files": {

0 commit comments

Comments
 (0)