Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

75%
+4 −0
Challenges Output 256 in many different ways

Scala (-language:postfixOps), 4 solutions 1. Just 256: 256 2. Casting a character: +'Ā' The character Ā is 256 in decimal, and the unary + turns it into an Int. 3. Hashcode of a string: ...

posted 3y ago by user‭  ·  edited 3y ago by user‭

Answer
#2: Post edited by user avatar user‭ · 2021-04-02T21:38:50Z (over 3 years ago)
  • # Scala (`-language:postfixOps`), 4 solutions
  • ```scala
  • 256
  • +'Ā'
  • ""## (two backspace characters inside the string)
  • (44444&444^444444)&4444
  • ```
  • [Try them all in Scastie!](https://scastie.scala-lang.org/QAT0gr9cTTeMmYX2tsQn5A)
  • I don't have a lot right now, especially because I'm not great at bitwise stuff, but I will hopefully find more later.
  • Because of the `""##`, using the flag `-language:postfixOps`, importing `language.postfixOps`, or using Scala 2.12 is required.
  • # Scala (`-language:postfixOps`), 4 solutions
  • ### 1. Just 256:
  • ```
  • 256
  • ```
  • ### 2. Casting a character:
  • ```
  • +'Ā'
  • ```
  • The character `Ā` is 256 in decimal, and the unary `+` turns it into an `Int`.
  • ### 3. Hashcode of a string:
  • ```
  • ""##
  • ```
  • There are two backspace characters in the string (\u0008), so the hashcode is `31*8 + 8 = 256`. `##` is the same as `.hashCode`. Since we're not using `.`, enabling postfix operators is required.
  • ### 4. Bitwise stuff:
  • ```
  • (44444&444^444444)&4444
  • ```
  • I just messed around for a while until I got this one right. It wastes parentheses and two operators, but I couldn't find anything better.
  • [Try them all in Scastie!](https://scastie.scala-lang.org/QAT0gr9cTTeMmYX2tsQn5A)
  • I don't have a lot right now, especially because I'm not great at bitwise stuff, but I will hopefully find more later.
  • Because of the `""##`, using the flag `-language:postfixOps`, importing `language.postfixOps`, or using Scala 2.12 is required.
#1: Initial revision by user avatar user‭ · 2021-04-02T21:32:29Z (over 3 years ago)
# Scala (`-language:postfixOps`), 4 solutions
```scala
256
+'Ā'
""## (two backspace characters inside the string)
(44444&444^444444)&4444
```
[Try them all in Scastie!](https://scastie.scala-lang.org/QAT0gr9cTTeMmYX2tsQn5A)

I don't have a lot right now, especially because I'm not great at bitwise stuff, but I will hopefully find more later.

Because of the `""##`, using the flag `-language:postfixOps`, importing `language.postfixOps`, or using Scala 2.12 is required.