New answers tagged counting
0
votes
0
votes
Determine the depth of an array
Uiua, 11 bytes
-2⧻{⍥⊸/◇⊂∞}
Try it!
Repeatedly reduce with conjoin (/◇⊂) until a fixed point (...
2
votes
Display number of occurrences for every character in an input string
Red 0.6.5, 71 bytes
m: #[]foreach c input[m/:c: 1 + any[m/:c 0]]foreach[k v]m[print[k":"v]]
Note: The 71-bytes version works in Red 0.6.5. The Red ...
2
votes
Display number of occurrences for every character in an input string
Ruby, 42 bytes
->s{s.chars.tally.map{puts _1+" : #{_2}"}}
Attempt This Online!
If the output format wasn't so strict you could go way shorter
Ruby, 20 ...
3
votes
Count /[^a-z]/ig with /[a-z]/ig
Jelly, score 0, 366 68 bytes
LdLYYTYYJSpppppJLdLdLdLdLdLNCNCNCNCSSSSRUFNMHpOIFACHHNCHNCNCRTLrLLCN
Try it online!
Uses a New and Exciting™️ construction for ...
1
vote
Count up forever
BrainChild, 108 bytes
include *;while(int a~-1|int b~-1|int c~-1|int d~-1){if(!++a)if(!++b)if(!++c)d++printf("$0$1$2$3 ",d,c,b,a)}
Brainchild doesn't ...
1
vote
Count up forever
punchcode, 6 bytes
[RS][ESC][VT][GS][CR][LF]
uncompiled:
-START |
---OOOO-|
---OO-OO|
----O-OO|
---OOO-O|
----OO-O|
1
vote
1
vote
Count the fish in a school
Haskell + hgl, 36 bytes
ca"1"<<tx<m(gkY$rX">{1_<>|<><{1_|.")
Attempt This Online!
Explanation
...
0
votes
Count the fish in a school
APL+WIN, 70 bytes
Prompts for school as a 2 dimension array.
m←((i←(⍴i)÷3),3)⍴i←(n←v≠' ')/v←,j←⎕⋄+⌿(⍴j)⍴n\,(m[;1]='>'),0,m[;,3]='<'
Try it online! Thanks to ...
1
vote
Count the fish in a school
Pip -r, 22 bytes
$+^gR`\S`*3{'<Q@a?Rhh}
Takes input from stdin; requires it to be padded to a rectangle with spaces. Attempt ...
1
vote
Count the fish in a school
Uiua, 30 bytes
+@0/+⬚0⊜(=-:@>◿3+2\+≠@ .)⊸≠@\n
Try it online!, inspired by ovs's K solution
Explanation:
...
1
vote
2
votes
1
vote
Count the fish in a school
05AB1E, 12 bytes
ðÊ€ηOIÇ+3ÖøO
Similar as a bunch of other answers.
Takes the input as a list of lists of characters, including trailing spaces to make all lines ...
3
votes
3
votes
Count the fish in a school
Ruby, 83 79 bytes
->s{a=[c=x=0]*w=s=~/\n/
s.bytes{|i|c+=i/60
i>10?a[(i-62+x+=1)%w]+=c%3/2:x=0}
a}
Try it online!
Function that takes a newline separated ...
4
votes
Count the fish in a school
Python + NumPy, 79 bytes
lambda s:sum((cumsum((X:=c_[s].view("i4")%-8)<0,1)+X)%3>1,0)
from numpy import*
Attempt This Online!
Takes a list of rows ...
3
votes
Count the fish in a school
Scala 3, 178 161 bytes
Saved 17 bytes thanks to @corvus_192
Golfed version. Attempt This Online!
...
13
votes
Accepted
Count the fish in a school
Vyxal, 8 bytes
C<v¦+3Ḋ∑
Try it Online!
I/O as a matrix of charcodes. Inspired by ovs's K answer (and then backported to that to save two bytes)
...
8
votes
3
votes
Count the fish in a school
JavaScript (ES6), 69 bytes
-2 thanks to @l4m2
Expects an array of arrays of characters (which may be of different lengths). Returns an array of integers.
...
5
votes
Count the fish in a school
Perl 5 -F, 57 50 bytes
s/(>)<>|<></$1?100:aa1/ge;s/./$;[pos]+=$&/ge}{say@
Try it online!
1
vote
Count the fish in a school
Python, 142 126 122 bytes
lambda s:[*map([m.start()+2*(m[0]<'>')for r in s for m in re.finditer(r'\S..',r)].count,range(max(map(len,s))))]
import re
Attempt ...
4
votes
Count the fish in a school
Japt, 24 21 16 bytes
Takes input as a 2D array of codepoints.
Ëí+DËgHÃå+ÃÕËxv3
Try it
...
2
votes
6
votes
Count the fish in a school
Jelly, 14 bytes
>⁶Ä3ḍk⁸Ġ€F=2)S
A monadic Link that accepts a list of lists of < > characters and yields a list of the ...
2
votes
Count the fish in a school
Charcoal, 40 35 28 26 bytes
WSP⭆ι⁺¬﹪⁺℅κL⁻…ι⊕λ ³Σ⊟KD⊕λ→
Try it online! Link is to verbose version of code. Takes input as a list of newline-terminated strings. ...
3
votes
Count the fish in a school
Retina, 97 bytes
N$^`
$.&
(\S)(\S)\1
$2
<
1
>
1
+`(?<=^(.)*)(.)((.*¶)+(?<-1>.)*)1(?(1)^)
$.(_$2*)$3
0
0G`
Try it ...
Top 50 recent answers are included
Related Tags
counting × 128code-golf × 117
string × 33
number × 17
grid × 12
sequence × 11
array × 11
ascii-art × 10
combinatorics × 9
math × 7
code-challenge × 5
geometry × 4
permutations × 4
restricted-source × 3
primes × 3
game × 3
binary × 3
base-conversion × 3
image-processing × 3
subsequence × 3
ragged-list × 3
arithmetic × 2
popularity-contest × 2
date × 2
matrix × 2