# Compute the conjugate of a partition

We will think of a partition as a sequence of non-increasing integers. For a given partition into $$\n_1, n_2, \dots, n_k\$$ with $$\n_1 \geq n_2 \dots n_{k-1} \geq n_k = n\$$ we write it out with $$\n_i\$$ dots on row $$\i\$$. So for $$\6, 1, 1\$$ we would write six dots on the first row, one on the second and one on the third

Given a partition, you should output its conjugate. That is you should output how many dots there are in each column of the dot diagram. For the input $$\6, 1, 1\$$ the output should be $$\3, 1, 1, 1, 1, 1\$$.

# Examples

5, 2, 1 gives output 3, 2, 1, 1, 1
4, 3, 1 gives output 3, 2, 2, 1
4, 2, 2 gives output 3, 3, 1, 1
3, 3, 2 gives output 3, 3, 2
4 gives output 1, 1, 1, 1

• How is the fact that it's a partition relevant? Oct 30 at 14:39
• @Simd The "context" seems to only make the challenge confusing Oct 30 at 14:41
• will input always come in desc sorted order? Oct 30 at 15:40
• Can the input contain only one number? If so, please add a test case for that Oct 31 at 0:05
• Related
– att
Oct 31 at 0:44

# BQN, 3 bytes

⊒⌾/


Try it here.

Explanation via example:

   / 4‿3‿1         # use each element as a count to replicate its index
⟨ 0 0 0 0 1 1 1 2 ⟩

⊒/ 4‿3‿1        # take a running occurrence count
⟨ 0 1 2 3 0 1 2 0 ⟩

/⁼⊒/ 4‿3‿1      # the inverse of /, applied via ⌾, counts occurrences
⟨ 3 2 2 1 ⟩


# 05AB1E, 5 bytes

L˜{Åγ


Attempt This Online!

L        # range, so [6,1,1] is [[1,2,3,4,5,6],,]
˜        # flatten, [1,2,3,4,5,6,1,1]
{        # sort, [1,1,1,2,3,4,5,6]
Åγ       # run length encode, [3, 1, 1, 1, 1, 1]


If we can have extraneous zeros in the output, then by porting @frasiyav's great BQN answer we have:

# 05AB1E, 4 bytes

L˜ā¢


Attempt This Online!

L˜        # same as previously
ā         # length range, [1, 2, 3, ..., len(arr)] (without popping)
¢         # count each


# Octave / MATLAB, 17 bytes

@(x)sum(1:x<=x,1)


Anonymous function that inputs a column vector and outputs a row vector.

Try it online!

### Explanation

@(x)              % Define anynomous function of x: column vector
1:x       % Range from 1 to (first entry of) x. Gives a row vector
<=x    % Less than/equal to x? Element-wise with broadcast. Gives a matrix
sum(      ,1) % Sum of each column



# Jelly, 3 bytes

b1S


Try it online!

For some reason, I almost feel like I've seen this even shorter as part of a different solution...

b1     Convert each element of the input to base 1.
S    Sum across columns.


# 05AB1E (legacy), 4 bytes

Å1ζO


Doesn't work in the new version of 05AB1E, unless we add 0 or ¾ before the ζ.

Explanation:

Å1    # Convert each value in the (implicit) input-list into a list of that many 1s
ζ   # Zip/transpose; swapping rows/columns,
# implicitly using a space " " as filler for unequal length rows
O  # Sum each inner list, which ignores the spaces in the legacy version of 05AB1E
# (after which the resulting list is output implicitly)


# R, 26 bytes

\(x)Map(\(z)sum(x>=z),1:x)


Attempt This Online!

A function taking a vector of integers and returning a list of integers.

# R, 28 22 bytes

Edit: -6 bytes thanks to @Giuseppe.

\(x)table(sequence(x))


Attempt This Online!

Port of Based on @Command Master's 05AB1E answer.

• table(sequence(x)) is 22 bytes? You get a named vector, but I think that's fair. Oct 31 at 18:23
• Yeah, me too. Thanks! Oct 31 at 19:02

# Python, 52 50 bytes

-2 thanks to @mousetail

lambda a:[sum(i<x for x in a)for i in range(a)]


Attempt This Online!

# J, 7 bytes

I.i.@{.


Attempt This Online!

• I. What is the "insert before" index when inserting into the input...
• i.@{. Of each of the numbers 0 through n-1, where n is the first input element.

## J, straightforward alternate, 9 bytes

[:+/#"0&1


Attempt This Online!

# Python, 45 bytes

def f(a,j=0):
for c in-1,*a:a[:c]=c*[j];j+=1


Attempt This Online!

Takes a list and modifies it in place.

# Python, 34 bytes

lambda a:sum(a[:,1>0]>range(a))


Attempt This Online!

### -4 thanks to @att.

Expects a NumPy array.

Ports @Command Master's pure Python.

• second just lambda a:sum(a[:,1>0]>range(a))
– att
Nov 3 at 6:55

# R, 30 bytes

\(l)rowSums(outer(1:l,l,"<="))


Attempt This Online!

Slightly longer compared to pajonk's, based on this other answer of mine.

• I had something like this drafted, but with apply instead of (better) rowSums. Oct 30 at 18:37

# sclin, 18 bytes

1X>b tpose \+/ map


Try it on scline!

1 repeated by n, transpose, sum each.

# Uiua, 8 bytes

⍘⊚⊐/⊂⊐∵⇡


Try it!

⍘⊚⊐/⊂⊐∵⇡  # [5 2 1]
⊐∵⇡  # [⟦0 1 2 3 4⟧ ⟦0 1⟧ ⟦0⟧] range of each
⊐/⊂     # [0 1 2 3 4 0 1 0]       join
⍘⊚        # [3 2 1 1 1]             occurrences


f a=[sum[1|j<-a,i<=j]|i<-[1..a!!0]]


Attempt This Online!

-1 byte thanks to matteo_c

Basically a port of Command Master's python answer

• 35 bytes Oct 30 at 23:47

# JavaScript (ES6), 44 bytes

a=>a.map(g=v=>v&&g(--v,b[v]=-~b[v]),b=[])&&b


Try it online!

### Commented

a =>              // a[] = input array
a.map(g = v =>    // for each value v in a[], using a recursive
// callback function g:
v &&            //   stop if v = 0
g(              //   otherwise do a recursive call:
--v,          //     decrement v
b[v] = -~b[v] //     increment b[v] (set it to 1 if undefined)
),              //   end of recursive call
) && b            // end of map(); return b[]


# Rust, 58 bytes

|a|(0..a).map(move|i|a.iter().filter(|x|i<**x).count())


Attempt This Online!

Basically a port of Command Master's python answer

# Japt v2.0a0 -Q, 5 bytes

-2 bytes from @AZTECCO

mo yl


# Japt v2.0a0 -Q, 7 bytes

There must be a shorter way

co ü ml


Try it

• You can use y method.. mo yl for 5 Bytes Oct 30 at 18:38
• Note that if the flag you're using is for output visualisation purposes only then it can instead be entered in the input field in my interpreter so that it doesn't change the language when you copy the complete markdown directly from the interpreter. Nov 1 at 12:32

# PARI/GP, 37 bytes

a->Vecrev(vecsum([x^i-1|i<-a])/(x-1))


Attempt This Online!

# PARI/GP, 37 bytes

a->[vecsum([t>=n|t<-a])|n<-[1..a]]


Attempt This Online!

# Wolfram Language (Mathematica), 26 bytes

Plus@@PadRight[1^Range@#]&


Try it online!

-12 bytes from @att

• 28 bytes
– att
Oct 31 at 0:45
• 26
– att
Oct 31 at 0:47

# Google Sheets, 92 86 bytes

=join(",",byrow(map(split(A1,","),lambda(n,sequence(n,1,,))),lambda(r,len(join(,r)))))

Put the input in as a text string in cell A1 and the formula in B1.

# Vyxal, 3 bytes

ẋ∩@


Try it Online!

ẋ    Repeat (each value in list times value)
∩   Transpose list
@  Length of each item in list


# Charcoal, 10 bytes

ＩＥ⌈θΣＸ⁰÷ιθ


Try it online! Link is to verbose version of code. Explanation:

   θ        Input list
⌈         Maximum
Ｅ          Map over implicit range
⁰     Literal integer 0
Ｘ      Vectorised raise to power
ι   Current value
÷    Vectorised integer divided by
θ  Input list
Σ       Take the sum
Ｉ           Cast to string
Implicitly print


# Retina 0.8.2, 44 bytes

\d+
$*_ \G_(?<=(?=(\2_*,?)+)(_+))$#1,
\D+$ Try it online! Takes I/O as comma-separated integers but test cases removes and reinserts spaces for convenience. Explanation: \d+$*_


Convert to unary.

\G_(?<=(?=(\2_*,?)+)(_+))
$#1,  For 1 up to the first array entry, count how many entries are less than or equal the value. \D+$



Remove the trailing junk.

# APL(Dyalog Unicode), 6 bytes SBCS

+⌿≤⌸∘⍸


Try it on APLgolf!

# Ruby, 37 bytes

->l{l.times.map{|x|l-=[x];l.size}}


Try it online!

# Desmos, 36 bytes

f(l)=[l[l>=i].lengthfori=[1...l]]


Try It On Desmos!

Try It On Desmos! - Prettified

This works because we can assume that the input is always in descending order as per OP's comment.

# K (ngn/k), 9 bytes

.#'=,/!:'


Try it online!

# Scala 3, 41 bytes

Saved some bytes thanks to the comment of @Kjetil S

a=>(1to a(0)).map{i=>a.count(_>=i)}.toSeq


Attempt This Online!

• One less: a=>(1 to a.head).map{i=>a.count(_>=i)}.toSeq Nov 1 at 11:54

# C (clang), 59 53 bytes

i;f(*a,z){for(i=0;z;i+=i<a[--z]&&printf("%d ",++z));}


Try it online!

• -1 thanks to @ceilingcat
i<=*a; -> *a/i

• Golfed another 5 Bytes by @att.

for(i=1;i<=*a;) loops until we print a times

i>a[z-1]? check i against last value in input

z-- move to previous position in input if greater

:printf("%d ",z else print position in input ,i++) and increment printed count

I think there can be a way to iterate i backwards.. e.g. for(i=*a;i.. but my brains are cooking.

• I was hoping for a C answer. Thank you.
– Simd
Oct 31 at 12:31
• There you are! We were close to 30 answers without it, I felt sad Oct 31 at 12:38
• 53 bytes
– att
Nov 3 at 7:15
• @att that's a great golfing! Thank you! Nov 3 at 20:11

# Pip, 9 bytes

#*<|ZJ1Xg


Try It Online!

• This is really clever! It doesn't quite work as written, since ZJ is intended for use with strings (try an input of 14, for instance; the output should be fourteen 1's, with no 2's). However, ZD should do what you want. You'll have to find a different way to get rid of the dummy values, though. Nov 15 at 18:28
• Oh, or here's a better way that lets you still use ZJ: #*<|ZJ1Xg (9 bytes). Nov 15 at 20:41
• @DLosc Thanks for the fix! The docs said ZJ operated on iterables, which I thought also included lists lol Nov 16 at 5:52
• It does also work with lists and ranges, but the "join each group of values into a string" part is the problem. If the items in each of the iterables are all the same length, it's fine, but if they're different lengths, you might not get the result you were expecting. Nov 16 at 20:05