# Appearing a unique number of times

Your task is to write a program or function that takes as input a list of positive integers and determines if there are any two integers in the list, that both appear the same number of times.

For example the list

[1, 2, 3, 2]


Has one 1 and one 3 so it satisfies the condition.

But the list

[3, 2, 2, 1, 2, 3]


does not satisfy the condition since every member appears a unique number of times.

Additionally your program should not satisfy this condition when its source code is interpreted as a list of bytes.

For example

abcb


Would not be a valid submission since both a and c appear exactly once.

Here is a verifier you can use if your source is in ASCII.

## Output

Your submission when executed should output one of two possible values, one when the input satisfies the condition, one when the input does not.

This is so answers will be scored in bytes with fewer bytes being better.

• I feel like the scoring is going to be basically "minimize the number of distinct characters", since you can probably pad in useless copies to make them appear 1..n times for a triangular score. – xnor Mar 13 at 19:34
• @xnor That seems like a good strategy. – Ad Hoc Garf Hunter Mar 13 at 19:35
• How about providing a scoring program for the programs? In some languages, the program will not be able to evaluate itself as the inputs are specified as integers, not bytes or strings. – Xcali Mar 13 at 21:49
• @Xcali Scoring is just regular code-golf. – Ad Hoc Garf Hunter Mar 13 at 21:57
• @S.S.Anne I don't think I can provide a universal solution validator, but I can make one for ASCII. – Ad Hoc Garf Hunter Mar 14 at 16:58

# 05AB1E, 6 bytes

D¢DD¢Q


Outputs 1 if each item appears a unique number of times, 0 otherwise.

D           # duplicate the input
¢          # count occurences of each item in the input
DD        # triplicate the list of occurence counts
¢       # count occurences of each occurence count in the list of occurence counts
Q      # check whether this is equal to the list of occurence counts


Without the source restriction, this could be 4 bytes: ¢Ð¢Q.

• Nice one! I was about to post an answer (21 bytes though, 6 unique bytes.. so nvm, haha). Here a test suite of your answer. (Enjoy the weekend!) – Kevin Cruijssen Mar 13 at 22:50
• @KevinCruijssen Thanks :D – Grimmy Mar 13 at 23:02

# Jelly, 1+2+3+4 = 10 bytes

ĠQQẈQƑẈĠĠĠ


A monadic Link which accepts a list and returns an empty list, [], if the input satisfies the condition, or a list with a list containing a one, [[1]] if the input does not satisfy the condition.

Try it online!

### How?

Without the source code restriction we could do the four byte ĠẈQƑ: Ġ, group indices by value; Ẉlength of each; Ƒ, is invariant under; Q de-duplication.

So for the $$\1+2+3+4=10\$$:

ĠQQẈQƑẈĠĠĠ - Link: list, L
Ġ          - group indices by value -> list of lists (which when flattened would contain the integers 1 to len(L) inclusive)
Q         - de-duplicate (a no-op)
Q        - de-duplicate (again a no-op)
Ẉ       - length of each (group) 0> how many times each element appeared
Ƒ     - is invariant under?:
Q      -   de-duplication -> 0 if satisfies, 1 if not
Ẉ    - length of each -> [] if satisfies, [1] if not
Ġ   - group indices by value -> [] if satisfies, [[1]] if not
Ġ  - group indices by value (a no-op)
Ġ - group indices by value (another no-op)


# Python 2, 136126 120 bytes

A slight improvement of @xnor's solution, posted with permission. Source code has 15 distinct characters.

n=input()
print(not
sum(())==sum(sum(r==m
for
m
in
n)==sum(u==m
for
m
in
n)for
r
in
n
for(u)in(n)if(r==u)==(r==n)))#ouu)


Try it online!

Input: A string representation of a list/iterable, from stdin.
Output: True if the list has 2 elements with the same frequency, False otherwise.

### Base solution

n=input()  # read a list/iterable from stdin
# This is Python2, so the input string is implicitly evaluated
print(0 != sum(     # return True if sum is not 0 (aka at least one of the following is True)
sum(r==m for m in n)==sum(t==m for m in n) # check if frequency of r and t are the same
for r in n for t in n if r!=t              # ignore when r==t
))


## Old solution using exec

### Python 2, 158 bytes

e=s=110;"tt)e";exec"e=%c%x%c%x%c%x%cx:%ce%c(set(x))-%ce%c(set(%c%x%c(x%cc%c%c%ct,x)))"%(e-2,10,e-1,11,100,10,0x20,e-2,e,s-2,s,s-1,10,s--2,0x2e,s--1,120-2-1,s)


Try it online!

Input: a list or iterable.
Output: a positive number if the list has 2 elements with the same frequency. 0 otherwise.

### Base solution

e=lambda x:len(set(x))-len(set(map(x.count,x)))


Try it online!
My approach is inspired by this answer, which discussed how to construct any Python programs using only the characters exc="%\n. The idea is to convert the program into exec"<program>", then use string modulo (%x and %c) to build program string from number.

• I don't have time to develop it, but I got a solution with 16 distinct chars without exec: TIO If you're interested, you're welcome to try making it work w/ padding (renaming variables) and post it. – xnor Mar 14 at 6:23
• Oops, the code should be this: Try it online! – xnor Mar 14 at 6:31
• It's amazing that you managed with only 16 characters! Unfortunately, the exec approach doesn't work, as I will have to add the character set ecx="%(), and your code is too long for substitution to work. However, simply padding your code with the extra characters is enough to beat my solution! 153 bytes – Surculose Sputum Mar 14 at 8:37
• Nice! This works out simpler than I thought. Feel free to post it. I wonder if you can further avoid a distinct #. No-ops can be done as or stuff, where if the thing before the or is true, the stuff won't evaluate, so it can be any string of letters, though it does not be be syntactically valid. Like, (()is(a))) could probably do a or stuff. Another place to stuff letters is as for stuff in l. See the crack to this for ideas. The colon might be trickier -- could it be a singleton? Parens also have parity constraints. – xnor Mar 14 at 9:00
• The colon can be a singleton. However, I can't seem to figure out a way to have unbalanced parentheses :( – Surculose Sputum Mar 14 at 9:25

# Raku, 66 57 bytes

*.Bag{*}.Bag{*}.all≠'l.}}}}****{{{{{{{gggggBBBBBBB'.Bag


Try it online!

10 unique characters, *.Bag{}l' and the 3 byte character ≠. This uses .Bag{*} to get the number of times each element appears, then repeats that to get the number of times those appear and then confirms that not all of them are equal to one.

# Zsh, $$\\sum_{i=1}^{18} i = 171\$$ bytes

((f--))
for u (${(u)@})((n[$#-${#@:#$u}]--))
((f-(${${(@on)n}[f]})))
#              rrrrrr[[[[[[]]]]]]]nnnnnnnn@@@@@@@@@#########{{{{{{{{{{}}}}}}}}}}}-----------))))))))



Try it online!

Tricks used: We use subtraction instead of adding. We reuse characters we need from for, (on), and (u) as parameter names. ((f--)) gets us f=-1, which saves us from using 1.

# JavaScript (ES6), $$\\sum\limits_{i=1}^{16}i= 136\$$ bytes

Returns $$\1\$$ if the condition is satisfied or $$\0\$$ if it's not.

p=>p.map(aa=m=a=>aa|=1^(p[[,a]]||(m[p.map(m=>pp+=a==m,p[[,a]]=pp=1),pp]^=1)))|aa//((((((,,...........11111===>>>>>>>>>>>[[^mmmmmppp|||||


Try it online!

### How?

To minimize the number of distinct characters, we only use map() loops and variable names made with m, a and p.

Character usage breakdown:

  + |  / |  ^ |  ) |  ] |  , |  [ |  1 |  | |  ( |  m |  a |  . |  > |  = |  p
----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----
1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 16


### Commented

In the following source, the variables have been renamed for readability.

a =>                       // a[] = input array, also used to keep track of the
//       values that have already been counted
a.map(r = o = v =>       // r = result flag
// o = object used to keep track of the character counts
//     that have already been encountered
// for each value v in a[]:
r |=                   //   set r if ...
1 ^ (                //     ... the test below is false:
a[[, v]] || (      //       v has already been counted, or this is ...
o[               //         ... the first time this count is encountered:
a.map(V =>     //           for each value V in a[]:
n += v == V, //             increment n if V is equal to v
a[[, v]] =   //             mark v as counted
),             //           end of inner map()
n              //
] ^= 1           //         toggle o[n]
)                  //       end of count update
)                    //     end of test
) | r                    // end of outer map(); return r


# R, 78 bytes

all(table(table(scan()))==all(c()))#nss==bbbcccceeeeettttttaaaa(((()))))llllll


Try it online!

table(x) gives a table of the counts of each value in x (here x will be the input taken by scan); table(table(x)) counts how many times each count occurs. We therefore want to check whether all(table(table(x))==1). Adding # and all the necessary characters to obey the constraint would lead to a score of 91.

The trick is to avoid the character 1 by using instead all(c()), which is all of an empty vector, i.e. TRUE, which gets converted to 1.

I haven't looked yet into using octal codes for this challenge; they might lead to a better score.

# Haskell (No monomorphism), 245 bytes

import Data.List


Try it online!

Here is a work in progress towards a better answer, it solves the problem using 9 distinct characters. However currently there are some characters that appear the same number of times (e.g. ( and )). I'm going to take a break from this, if anyone wants to use this to make a more complete answer go ahead.

s+|(ss:sss)|s==ss=1+s+|sss|1==1=s+|sss
s+|ss=1
s|+(ss:sss)|s==ss=s|+sss|1==1=ss:s|+sss
s|+ss=ss
s(ss:sss)=ss+|sss:s(ss|+sss)
s(ss)=ss
ss(1:s)=ss(s)
ss(s:ss)=1==11
ss(s)=1==1
sss(sss)=ss(s(s(sss)))


Try it online!

# Wolfram Language (Mathematica), 253 bytes

(*!!!!!!!!!!!!!!!!!!!!!o*=L=L=L=L*Ln*n*n*nUUU))))))))))))))))))UUUUUUTTTTTTTTTTSSSSSSSSSSSrrnnrrrrrrrrrrLLLLLLLLiiiiiiiiiiiiii//ss&&########*#######@#####&&&&&&&&&&&&&&&&s/ss/ss/s/ss/ss/ss/ss//////((((((((((((((((a*aaaa*)Union@(l=Last/@Tally@#)!=Sort@l&


Try it online!

• ( and = both appear exactly once. – Jonathan Allan Mar 13 at 19:26
• @JonathanAllan fixed – J42161217 Mar 13 at 21:32

# Python 3, 406$$\\sum\limits_{i=1}^{26}i= 351\$$ bytes

Saved $$\27+28=55\$$ bytes thanks to Surculose Sputum!!!

lambda l:all(l.count(a)^l.count(p)for a,p in itertools.combinations(set(l),2))


Try it online!

A veritable triple double super-sized whopper!!!
Returns False if the input (any sequence) satisfies the condition, True otherwise.

• 351 bytes by reducing the number of distinct characters by 2 – Surculose Sputum Mar 14 at 0:36
• @SurculoseSputum Wow that's sweet - thanks! :-) – Noodle9 Mar 14 at 1:07

# JavaScript (Node.js), 253 bytes

n=>new(Set)(n).size>new(Set)(n.map(e=>n.filter(r=>r==e).length)).size//(======ghgmmmmmmmaaaaaaaapppppppppppwwwwwwwwwwwllllllllllllhhhhhhhhhhhhhrrrrrrrrrrrrrggggggggggggggzzzzzzzzzzzzzzzzSSSSSSSSSSSSSSSSSttttttttttttttttnnnnnnnnnnnnnnssssssssssssssssssss


Try it online!

unavoidable new Set size length map filter

# Charcoal, 40 23 bytes

⁼№θＥθι⁼Ｅθ№θιＥθ№Ｅθ№θλ№θι


Try it online! Link is to verbose version of code. Outputs - only if the condition is satisfied. Port of @Grimmy's 05AB1E answer. Explanation: The leading ⁼№θＥθι exists to consume characters to meet the source layout restrictions and also happens to complement the result. The rest of the code is as follows:

 Ｅθ№ ι              List of counts of elements
θ               In list
⁼                   Equals
Ｅθ№     №θι   List of counts of counts
Ｅθ№θλ      In list of counts


# Japt-!, 36 bytes

ü mÊ
e       UUâââmÊmÊmÊmÊÊ

eUâ


Try it