Search Results
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 |
Code-golf is a competition to solve a particular problem in the fewest bytes of source code.
1
vote
Is it a doubling sequence?
Kotlin, 50 bytes
{a:IntArray->(0..a.size-2).first{a[it]*2>a[it+1]}}
Try it online!
Int for false and Nothing for true (throws NoSuchElementException)
0
votes
Sleep for 1000 years
Kotlin, 25 bytes
{Thread.sleep(7L shl 42)}
111 followed by 41 zeros (binary) is ~97.56% of 31556952000000 (decimal)
Try it online!
0
votes
Map key with value as standard
Kotlin, 35 bytes
{split('(',')').drop(1).chunked(2)}
Try on playground!
I mean, they are associated, you can find the value for a key:
val map = "(01)99012345670019(10)Ab1234(3102)00122515190521(337n …
3
votes
Pareto-optimal shortest paths
Kotlin, 248 228 211 bytes
fun Set<IntArray>.p(i:Int=0):Set<Pair<Int,Int>>
=if(i==maxOf{it[1]})setOf(0 to 0)else
filter{it[0]==i}.flatMap{p(it[1]).map{(a,b)->a+it[2]to b+it[3]}}.run{filter{(a,b)->all{( …
1
vote
Interpret PlusOrMinus
Kotlin, 76 bytes
{fold(0){a,c->when(c){'-'->{print(a.toChar());a-1}'+'->a+1 else->a}and 255}}
Try it online!
-1 byte thanks to ceilingcat.
1
vote
The shortest way to find one unique value when all other values are the same
Kotlin, 40 24 bytes
{minBy{r->count{r==it}}}
Try it online!
It doesn't seem to have a count function where you can simply pass the lambda parameter.
-16 bytes thanks to Seggan
2
votes
Convert binary to unary
Kotlin, 22 bytes
{"*".repeat(toInt(2))}
Try it online!
27
votes
6
answers
3k
views
How many cacti can I plant here?
Given a Minecraft terrain as a 2-dimensional array of integers or similar datastructure, determine the maximum number of cacti that can be planted on it.
The integers represent the height (y) of the t …
2
votes
Are the brackets fully matched?
Kotlin, 100 89 86 bytes
-11 bytes: Use any instead of firstOrNull
-3 bytes: Use chunked instead of split (thanks to @leo848)
fun f(s:String):Boolean="()<>[]{}".chunked(2).any{it in s&&f(s.replace(it," …
0
votes
Convert a string of digits from words to an integer
Kotlin, 64 bytes
{split(" ").fold(0){a,b->10*a+"rothuvsein".indexOf((b+b+b)[6])}}
Improving upon this answer.
Try it online!
1
vote
Diagonalize a vector
Kotlin, 65 bytes
{a:IntArray->Array(a.size){i->IntArray(a.size).also{it[i]=a[i]}}}
Try it online!