Posts by user
Making a function with val can be shorter than with a def If you're pattern matching, you can use Scala's special syntax and omit match when assigning an anonymous function to a val. As you can se...
Zsh, 61 bytes n=2;s=s=%q\;printf\ n=\$n\$n\\\;\$s\ \$s;printf n=$n$n\;$s $s Attempt This Online! A trivial modification of this quine: s=s=%q\;printf\ \$s\ \$s;printf $s $s. n goes from 2 to 22 ...
Scala, 50 bytes Stream.iterate(_)(x=>Seq(x/2,3*x+1)(x%2))indexOf 1 Try it in Scastie!
Scala, 25 bytes a=>_.flatMap(a map _.min) Try it in Scastie! Pretty trivial solution, but here's a bad explanation anyway: //a is the first string a =>_.flatMap(a map _.min) //b is th...
Python 3.8 (pre-release), 39 bytes print(x:=input(),y:=input()) print(y,x) Try it online!
Scala, 42 bytes object>extends App{print("Hello, World!")} Attempt This Online!
Scala, 18 bytes x=>_.:\(.0)(_+_*x) Try it online! Not too complicated. Takes the list of coefficients and folds from the right, multiplying the accumulator by x each time and adding the nex...
Verbosity, 512 bytes, cracked by Moshi Include<Integer> Include<MetaFunctions> Include<Output> Include<String> Integer:DefineVariable<IntegerOne; 1> Output:Def...
APL (Dyalog Unicode), 22 bytes ⎕←∘.((1+⍳9)⌽⍨⊣+3×⊢)⍨⍳3 Try it online! Requires zero-indexing. ⎕←∘.((1+⍳9)⌽⍨⊣+3×⊢)⍨⍳3 ⍳3 ⍝ Make the range [0, 2] (row and cols of 3×3 box...
JavaScript (Node.js), 41 40 bytes Saved 1 byte thanks to Shaggy x=>x.map(e=>e?a.push(e):a.pop(),a=[])&&a Try it online! x => //x is the input x.map(e=> //For every...
APL (Dyalog Unicode), 30 29 bytes Saved 1 byte thanks to Razetime (could've saved 1 more with a tradfn, but I didn't feel like it) {∧/(0=1|+/÷≢)¨1↓¨g¨(g←∪⊢∨⍳)⍵} Try it online! This answer w...
Scala 3, 50 44 bytes ? => ?.indices zip?map(?take _+1 count _.==) Try it in Scastie! This is an annoying, stupid approach. The more elegant one using inits was much longer (x=>x.inits.to...
APL (Dyalog Unicode), 32 bytes (SBCS) {⊃(⊢(/⍨)⍵=+/¨),∘.,⍨(⊢~∘.×)⍨1↓⍳⍵} Try it online! {⊃(⊢(/⍨)⍵=+/¨),∘.,⍨(⊢~∘.×)⍨1↓⍳⍵} ⍳⍵ ⍝ Range from 1 to n ...
What general tips do you have for golfing in Scala? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Scala (e.g. "remove comments" i...
Rust, 47 bytes fn main(){unsafe{print!("{}",*(0 as*mut i8));}} Try it online!
Libraries are removed when "merge variants" is on. For example, this answer written in C (clang) uses a library called BMPL, so its header is C (clang) + BMPL. While there's nothing wrong with usin...
- ← Previous
- 1
- 2
- 3
- Next →