| Bytes | Lang | Time | Link |
|---|---|---|---|
| 073 | C | 240713T212534Z | danmcard |
| 015 | Julia 1.0 | 240713T195310Z | MarcMush |
| 038 | min | 240713T010129Z | chunes |
| 004 | Uiua SBCS | 231014T023404Z | chunes |
| 019 | Julia 1.0 | 230914T173439Z | Ashlin H |
| 005 | Pip p | 230914T183802Z | DLosc |
| 002 | Nekomata | 230912T081255Z | alephalp |
| 042 | Common Lisp | 230727T121209Z | coredump |
| 029 | PowerShell Core | 230727T072609Z | Julian |
| 044 | Java | 230727T070859Z | Top Golf |
| 077 | Desmos | 230726T182019Z | notaprot |
| 027 | Arturo | 230118T022408Z | chunes |
| 001 | Thunno 2 | 230726T110759Z | The Thon |
| 4745 | AWK | 210422T010853Z | Jonah |
| nan | 230128T093830Z | The Thon | |
| 103 | Go | 230128T063157Z | bigyihsu |
| 013 | TIBasic | 230128T043000Z | Youserna |
| nan | 230127T210747Z | noodle p | |
| 002 | Pyt | 230127T195258Z | Kip the |
| 032 | Matlab | 210513T183648Z | elementi |
| 023 | Zsh | 210424T144809Z | pxeger |
| 058 | Java | 210423T212417Z | Unmitiga |
| 006 | Arn | 210423T202722Z | ZippyMag |
| 045 | Excel | 210423T195252Z | Engineer |
| 036 | Pari/GP | 210423T003740Z | Joe Slat |
| nan | Excel 17 | 210422T225427Z | Axuary |
| 008 | Brachylog | 210421T235436Z | Unrelate |
| 022 | Perl 5 pa | 210422T163814Z | Xcali |
| 080 | TSQL | 210422T155927Z | Brian J |
| 075 | C clang | 210422T114959Z | Noodle9 |
| 002 | Neim | 210422T141426Z | LiefdeWe |
| 032 | C# Visual C# Interactive Compiler | 210422T140922Z | LiefdeWe |
| 056 | PHP | 210422T123700Z | Kaddath |
| 004 | Japt | 210422T092604Z | AZTECCO |
| 006 | J | 210422T075454Z | Galen Iv |
| 042 | Racket | 210422T074324Z | Galen Iv |
| 035 | JavaScript ES2021 | 210422T022145Z | tsh |
| 010 | Raku | 210422T025700Z | Sean |
| 027 | Ruby | 210422T005117Z | Sony San |
| 026 | R | 210422T005215Z | Giuseppe |
| 028 | Factor | 210422T002844Z | chunes |
| 012 | Wolfram Language Mathematica | 210422T003952Z | att |
| 001 | 05AB1E | 210422T003400Z | Makonede |
| 006 | APLDyalog Unicode | 210422T000202Z | hyper-ne |
| 022 | Scala | 210422T000200Z | user |
| 003 | MATL | 210422T000007Z | Luis Men |
| 002 | Vyxal | 210421T234205Z | lyxal |
| 002 | 05AB1E | 210421T234910Z | lyxal |
| 023 | Python 2 | 210421T234856Z | xnor |
| 003 | Pyth | 210421T234649Z | hakr14 |
| 026 | Python 3 | 210421T234625Z | caird co |
| 006 | Charcoal | 210421T234551Z | Neil |
| 036 | JavaScript ES6 | 210421T234522Z | Arnauld |
| 027 | Haskell | 210421T234403Z | Delfad0r |
| 002 | Jelly | 210421T233929Z | caird co |
C, 73 bytes
void f(int*p,int*o,int n){for(int i=0;i<n*n;++i)o[i/n]+=p[i/n]==p[i%n];}
Slightly more readable:
void f_pretty(int* p, int* o, int n) {
for (int i = 0; i < n * n; ++i)
o[i / n] += p[i / n] == p[i % n];
}
One trick I'm pulling is replacing nested for loops for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) with for (int k=0; k<n*n; ++k). In the second form, I can reconstruct the original i as k / n and the original j as k % n.
min, 41 38 bytes
(:q q((==)cons q swap filter size)map)
(...) ; a function
:q ; assign input to q
q ; push input to stack
()map ; map over input by...
(==)cons ; prepend current elt to (==), forming (1 ==) for instance
q swap ; push input and put it underneath
filter ; filter input by function we created
size ; get length of list
Uiua SBCS, 5 4 bytes
⊏⟜°⊚
Works with natural numbers.
°⊚ # inverse where (occurrences)
⊏⟜ # select from occurrences using input as indices
Julia 1.0, 19 bytes
~a=@.sum(==(a),[a])
Saved 2 bytes by substituting sum for count.
-3 bytes thanks to MarcMush: replace Ref(a) with [a]
Pip -p, 5 bytes
_NgMg
Explanation
g ; List of command-line args
M ; Map to each:
_N ; Number of occurrences of that argument in...
g ; ... the list of command-line args
Common Lisp, 42
(lambda(x)(mapcar(lambda(u)(count u x))x))
Java, 44 Bytes
n.stream().map(e->frequency(n1,e)).toList();
with n1 beeing a copy of n and static import of java.util.Collections.*
Desmos, 77 bytes
f(a)=\sum_{n=[1...a.length]}^{[1...a.length]}(total(\left\{a=a[n],0\right\}))
Try it online! Takes in a list as input, and outputs a new list as per the specifications. The linked graph uses an action to replace the list with the function's output.
Thunno, \$ 2\log_{256}(96)\approx\$ 1.65 bytes
Dc
Or, \$1 \log_{256}(96) \approx\$ 0.82 bytes with the D flag!: Attempt This Online!
D duplicates the (implicit) input, and c gets the count of each one (vectorises automatically).
Edit: Just realised that there's another Thunno answer here. I'll keep this undeleted, though, since it is different from the other answer.
Go, 103 bytes
func f(l[]int)[]int{m:=make(map[int]int)
for _,e:=range l{m[e]++}
for i,e:=range l{l[i]=m[e]}
return l}
TI-Basic, 13 bytes
seq(sum(I=Ans),I,1,dim(Ans
Takes input in Ans.
Thunno, \$ 2 \log_{256}(96) \approx \$ 1.65 bytes
ec
ec : implicit input array
e : map the input to the following:
c : count the occurrences of the number in the input
: implicit output
Thought I'd try an easy and short problem for my first Thunno answer.
Pyt, 2 bytes
Đɔ
Đ implicit input; duplicate
ɔ for each item in input, count occurrences in input; implicit print
Matlab, 32 bytes
@(x)table(histcounts(x)).Var1(x)
...assuming inputting only integer numbers from 1 to 50. Rules says I can choose a subset.
To work for integers from 1 to 65536 (216) you need few extra bytes and code like that:
@(x)table(histcounts(x,'BinMethod','int')).Var1(x)
Both solutions are anonymous functions.
The fragment of code table(...).Var1(x) is a trick allowing for indexing the function output without saving it to a variable. Normally one would do something like that:
y = histcounts(x);
return y(x)
but anonymous functions doesn't allow for that and full function would be longer.
The solution unfortunatelly doesn't work for Octave, because it doesn't have histcounts implemented. :(
Java, 58 bytes
l->l.stream().map(x->java.util.Collections.frequency(l,x))
Java, 56 bytes
l->l.stream().map(x->l.stream().filter(y->y==x).count())
This only works for integers in the Integer Cache (-128 to 127, by default).
Arn, 6 bytes
█Â(ÂÍL
Found some pretty major precedence bugs... so that's why I'm a day late
Explained
Unpacked: @a{/:=a
_ STDIN; implied
@ Bind following to each value
a{ Block with key of 'a'
/: Bind next arg with the arg after, use truthiness to filter and then count
_ Current value, implicit
= Equals
a Current value of map bind (defined by block)
_ It's binded to STDIN
}
Came up with some alternatives when I got bored from fixing the bug, here are some
Arn, 8 bytes
ñ=èÍù«Á&
Unpacked: @a{+{=a}\ (Replace each val with a mapped for equality + folded version of stdin)
Arn, 8 bytes
hLdŠÅk$'
Unpacked: @a{+\(@=a (Same as last one but written a different way)
Arn, 6 bytes
╔½†Œ#ç
Unpacked: @a{$=a&# (Very similar to the actual answer, but uses filter and a binded size suffix. Compression shaved two bytes off of this, instead of the one byte my real answer lost from compression, which is why they're the same length)
Excel, 45 bytes
=COUNTIF(A:A,INDEX(A:A,SEQUENCE(COUNT(A:A))))
Input is in column A. The formula goes anywhere not in column A.
COUNT(A:A) counts the numeric entries.
SEQUENCE(~) creates an array from 1 to whatever that count was.
INDEX(A:A,~) pulls the inputs one at a time, thanks to the sequence input.
COUNTIF(A:A,~) counts the inputs that match the one it just pulled.
Excel 17, bytes
=COUNTIF(A1#,A1#)
Assuming A1 = { .... } then this works. It's a longer, less flexible formula if the data in entered in individual cells.
Brachylog, 8 bytes
∋;?{∈ᵈ}ᶜ
Generates the output through the output variable.
∋; Pair some element of the input with
? the input.
{ }ᶜ In how many ways is
∈ᵈ the element an element of the input?
Using ọ comes out one byte longer:
Brachylog, 9 bytes
⟨ọ⟨∋h⟩∋⟩t
Also generates the output through the output variable.
∋ Choose an element of the input.
⟨ h⟩ It is the first element of
∋ an element of
⟨ọ ⟩ the list of pairs [element of input, how many times it occurs in input]
t the last element of which is the output.
T-SQL, 80 bytes
SELECT c FROM (SELECT a b,COUNT(*)c FROM @ GROUP BY a)x JOIN @ ON a=b ORDER BY i
Example Input
Requires something like this for input
DECLARE @ TABLE (a int, i int identity)
INSERT INTO @ VALUES (1), (2), (2), (4), (4), (4), (4)
Explanation
Group by the number and count them up. Then join back to the original list so that we can output in the correct order.
C (clang), 84 \$\cdots\$ 81 75 bytes
Saved 6 bytes thanks to AZTECCO!!!
b;i;j;f(*a,l){for(i=-1;++i<l;printf("%d ",b))for(b=j=l;j--;)b-=a[i]!=a[j];}
Inputs a pointer to an array and its length (because array pointers in C don't carry any length info) and prints the occurrence counts.
Neim, 2 bytes
Right language, right time.
Ψ𝕠
Explanation:
Ψ # Apply next token to all in list
𝕠 # Count element in list
PHP, 56 bytes
fn($a)=>array_map(fn($e)=>array_count_values($a)[$e],$a)
As usual, those "array_" PHP prefixes are ruining the golfing :P
JavaScript (ES2021), 35 bytes (not quite reasonable I/O)
a=>a.map(n=>a[++(a[n]||=[0])[0],n])
Accept an array of 1 element array of negative numbers. Return an array of 1 element array...
f([-1, -2, -2, -1, -4, -8, -1]) // [[3], [2], [2], [3], [1], [1], [3]]
f([[-1], [-2], [-2], [-1], [-4], [-8], [-1]]) // [[3], [2], [2], [3], [1], [1], [3]]
Just consider input / output as column vectors...
JavaScript (ES2021), 42 bytes
Add an extra .flat() to make it reasonable would cost +7 bytes (42 bytes in total)
a=>a.map(n=>a[++(a[n]||=[0])[0],n]).flat()
That's too long.
Raku, 10 bytes
{.Bag{$_}}
.Bag generates a Bag (a set with multiplicity) from the input argument $_. Then {$_} slices into that Bag with the original list, producing a list of the multiplicities of the elements of that list, in order.
Ruby, 27 bytes
f=->*a{a.map{|e|a.count e}}
Testing:
p f[4,3,4] #=> [2, 1, 2]
R, 26 bytes
ave(a,a<-scan(),FUN=table)
ave takes a vector x, an arbitrary number of grouping variables ..., and a function FUN, and replaces each element of x with the result of applying FUN to the group containing that element.
I've also found a number of 26 byte variants with FUN=sum; they differ only in the way they generate a vector of ones with length length(a).
ave(a^0,a<-scan(),FUN=sum)
ave(a,a<-scan(),FUN=sum)/a
ave(a|1,a<-scan(),FUN=sum)
Factor, 28 bytes
[ dup histogram substitute ]
It's a bit shorter than the version for squares:
[ dup [ '[ _ = ] count ] with map ]
Explanation:
It's a quotation (anonymous function) that takes a sequence from the data stack as input and leaves a sequence on the data stack as output. Assuming { 1 4 4 } is on the data stack when this quotation is called...
dupDuplicate an object.Stack:
{ 1 4 4 } { 1 4 4 }histogramCreate a histogram from a sequence.Stack:
{ 1 4 4 } H{ { 1 1 } { 4 2 } }substituteTake a sequence and an associative array and substitute elements in the sequence that have keys in the assoc with their values.Stack:
{ 1 2 2 }
05AB1E, 1 byte
¢
Try it online! Beats all other answers.
¢ # full program
¢ # number of times...
# (implicit) each element in...
# implicit input...
¢ # appears in...
# implicit input
# implicit output
APL(Dyalog Unicode), 6 bytes SBCS
+/∘.=⍨
+/∘.=⍨ dfn submission
∘.= product table using equality
⍨ applied to the input on the left and the right
+/ reduce by addition / sum
MATL, 3 bytes
&=s
Try it online! Or verify all test cases.
Explanation
% Implicit input: numeric row vector
&= % Matrix of all pairwise equality comparisons
s % Sum of each column
% Implicit display
Vyxal, 2 bytes
vO
Wow y'all using unicode in your golfing languages while I'm chilling in the ASCII zone.
Explained
vO # vectorise count over the input
# essentially, [input.count(n) for n in input]
Pyth, 3 bytes
/LQ
Explanation:
/LQ | Full program
/LQQ | with implicit variables
-----+-------------------------------------
L Q | replace each element d in input with
/ Q | the count of d in input
Charcoal, 6 bytes
IEθ№θι
Try it online! Link is to verbose version of code. Explanation:
θ Input array
E Map over elements
№ Count of
ι Current element in
θ Input arrray
I Cast to string
Implicitly print
Jelly, 2 bytes
ċⱮ
How it works
ċⱮ - Main link. Takes a list L on the left
Ɱ - For each element in L
ċ - Count the times it appears in L

