Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 2960

Code-golf is a competition to solve a particular problem in the fewest bytes of source code.

1 vote

Jolly Jumper Sequence

Scala A quick stab - there are probably improvements possible. Easy: 77 def j(? :Int*)=(?tail,?).zipped.map(_-_).map(math.abs).sorted==(1 to?.size-1) Hard: 124 val? =args.map(_.toInt)toSeq;print …
Luigi Plinge's user avatar
9 votes

Generate Pascal's triangle

Scala, 81 78 72 70 characters 81 chars: first attempt, shamelessly copied from the Python version :) var x=Seq(1) for(i<-1 to args(0).toInt){println(x) x=(0+:x,x:+0).zipped.map(_+_)} Run it as a s …
Luigi Plinge's user avatar
10 votes

Tips for golfing in Scala

Use infix syntax to remove the need for . characters. You don't need spaces unless adjacent items are both in alphanumeric or both in operator characters (see here), and not separated by reserved char …
Luigi Plinge's user avatar
10 votes

Tips for golfing in Scala

You can usually use map instead of foreach: List("a","b","c") foreach println can be replaced with List("a","b","c") map println The only difference is the return type (Unit vs List[Unit]), whic …
Luigi Plinge's user avatar
14 votes

Tips for golfing in Scala

The shortest way of repeating something is with Seq.fill. 1 to 10 map(_=>println("hi!")) // Wrong! for(i<-1 to 10)println("hi!") // Wrong! Seq.fill(10)(println("hi!")) // Right!
Luigi Plinge's user avatar
21 votes

Obfuscated Hello World

Scala, 39 Solutions like print("Qnuux)`x{um"map(_-9 toChar)) (35 chars) fall foul of rules 1 and 2 ("toChar" contains both "h" and "r"), which makes this a bit tough. Finally came up with this: pri …
Luigi Plinge's user avatar