The 2024 Developer Survey results are live! See the results

# Tag Info

## Hot answers tagged counting

Accepted

### Count trailing truths

Dyalog APL, 6 2 bytes ⊥⍨ Test it on TryAPL. How it works ⊥ (uptack, dyadic: decode) performs base conversion. If the left operand is a vector, it performs ...
• 210k

### Covering a Skyline with brush strokes

JavaScript (Node.js), 38 bytes a=>a.map(v=>(n+=v>p&&v-p,p=v),p=n=0)|n Try it online! Simply a greedy algorithm which scan from left to right, ...
• 35k

### Counting and so on

Python 3, infinity points ...
• 3,311

### Covering a Skyline with brush strokes

05AB1E,  8 7  5 bytes Saved 2 bytes thanks to @Adnan 0š¥þO Try it online! How? This is using the algorithm that was first found by @tsh. If you like this answer, ...
• 194k

### Slash the matrix

MATL, 21 bytes 3XytPJ*-X*Xj~4&1ZIunq The input is a matrix with 1 for \ and ...
• 105k

### How many lights are on?

MATL, 19 18 17 13 bytes 5 bytes off thanks to @LeakyNun's idea (see his answer) of using the imaginary unit as a base for exponentiation. Jj11\^Ys8#uos Try it ...
• 105k
Accepted

### Detriplicate a string

Jelly, 6 bytes Qx2œ&@ Try it online! or verify all test cases. How it works ...
• 210k
Accepted

### Find the "unwrapped size" of a list

Retina, 1 byte ] Try it online! (The first line enables a linefeed-separated test suite.) By default, Retina counts the number of matches of the given regex in ...
• 197k

### Cantor's unspeakable numbers

Python 2, 77 75 74 70 bytes Thanks to @MartinEnder for suggesting the limit of 9e5 which enderd up working after a change.Thanks to @mschauer for suggesting an ...
• 17.9k
Accepted

### How much do I have to write?

05AB1E, 3 bytes Code: ÝJg Uses the CP-1252 encoding. Try it online! Explanation: ...
• 44.5k
Accepted

### Checkmate (aka the urinal problem)

Oasis, 5 bytes Code cd+2V Extended version cd+211 Explanation ...
• 44.5k

### GET your dubs together

Mathematica, 29 bytes How about an arithmetic solution? IntegerExponent[9#+#~Mod~10]& I'm very pleased to see that this beats the straight-forward ...
• 197k

### A scene of Jimmy diversity

Python 3.8 (pre-release), 51 bytes lambda s:((c:=s.count)('o')-c('/'),c('/o'),c('/-')) Try it online!
• 40.6k

### Prime Wednesdays

Python 2, 95 93 68 67 bytes lambda y:0x10ea2c8dbb06c5619/5**((y+((y-22)/99-y/2002)*16)%28)%5+16 Thanks to @Josay for golfing off 1 byte! Test it on Ideone.
• 210k

### How many lights are on?

Python, 68 bytes 25 bytes thanks to Sp3000. 2 bytes thanks to Luis Mendo's idea of taking modulus with 11. 17 bytes thanks to xnor. ...
• 49.9k

### Count trailing truths

JavaScript (ES6), 21 bytes f=l=>l.pop()?f(l)+1:0 Test cases ...
• 194k

### A penny saved is a penny

Haskell, 37 34 bytes s#l@(c:d)|s>=c=(s-c)#l+s#d s#_=0^s Usage example: 26 # [1,5,10,25] -> ...
• 35.9k

### How long is a Welsh word?

Retina, 23 bytes i[cprt]h|dd|ff|ng|ll|. Try it online! Even moar regex.
• 1,542

### Count forth and back then double up

JavaScript (ES7),  59 ... 44  43 bytes Saved 1 byte thanks to Titus Expected input: 1-indexed. n=>(n-=(r=(~-n/2)**.5|0)*r*2)<++r*2?n:r*4-n Initially inspired ...
• 194k

### Replace all items with their counts

Python 2, 23 bytes lambda l:map(l.count,l) Try it online!
• 146k

### Detriplicate a string

JavaScript (ES6), 42 48 Edit A whopping 6 bytes saved thx @Neil s=>s.replace(k=/./g,c=>(k[c]+=c)[11]?'':c) Explanation: I use the properties 'a'...'z' of ...
• 32.2k

### Count to 100 in Danish

JavaScript (ES6), 347 336 326 325 308 bytes ...
• 50.1k

### A penny saved is a penny

Mathematica, 35 22 bytes Thanks to miles for suggesting FrobeniusSolve and saving 13 bytes. Length@*FrobeniusSolve Evaluates ...
• 197k

### GET your dubs together

Retina, 9 bytes &(.)\1*$Try it online! Counts the number of overlapping matches of (.)\1*$ which is a regex that ...
• 197k

### Detriplicate a string

Python 2, 48 bytes lambda s:reduce(lambda r,c:r+c*(r.count(c)<2),s) c[r.count(c)/2:] is a same-length alternative to ...
• 146k

### Count to 100 in Danish

Fourier, 7028 bytes The bounty will go to Paul Schmitz's answer This was golfed programmatically using issacg's golfing program ...
• 23.4k
Accepted

### How Many Holes?

MATLAB / Octave, 18 bytes @(g)1-bweuler(g,4) Try it online! This is an anonymous function taking a logical matrix as input. The object is formed by the ...
• 43.9k