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


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.


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.

  • \$\begingroup\$ 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. \$\endgroup\$
    – xnor
    Mar 13 '20 at 19:34
  • \$\begingroup\$ @xnor That seems like a good strategy. \$\endgroup\$
    – Grain Ghost
    Mar 13 '20 at 19:35
  • \$\begingroup\$ 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. \$\endgroup\$
    – Xcali
    Mar 13 '20 at 21:49
  • \$\begingroup\$ @Xcali Scoring is just regular code-golf. \$\endgroup\$
    – Grain Ghost
    Mar 13 '20 at 21:57
  • 1
    \$\begingroup\$ @S.S.Anne I don't think I can provide a universal solution validator, but I can make one for ASCII. \$\endgroup\$
    – Grain Ghost
    Mar 14 '20 at 16:58

13 Answers 13


05AB1E, 6 bytes


Try it online! or validate more test cases.

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.

  • \$\begingroup\$ 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!) \$\endgroup\$ Mar 13 '20 at 22:50
  • \$\begingroup\$ @KevinCruijssen Thanks :D \$\endgroup\$
    – Grimmy
    Mar 13 '20 at 23:02

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


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!


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, 136 126 120 bytes

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


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                    

Try it online!

Old solution using exec

Python 2, 158 bytes


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.

  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – xnor
    Mar 14 '20 at 6:23
  • \$\begingroup\$ Oops, the code should be this: Try it online! \$\endgroup\$
    – xnor
    Mar 14 '20 at 6:31
  • \$\begingroup\$ 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 \$\endgroup\$ Mar 14 '20 at 8:37
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – xnor
    Mar 14 '20 at 9:00
  • \$\begingroup\$ The colon can be a singleton. However, I can't seem to figure out a way to have unbalanced parentheses :( \$\endgroup\$ Mar 14 '20 at 9:25

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

for u (${(u)@})((n[$#-${#@:#$u}]--))
#              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.


Raku, 66 57 bytes


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.


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

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


Try it online!


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


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
              n = 1        //             and start with n = 1
            ),             //           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


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
g1L=all o111111111LLLLLLLLLLaaaaaaaeeeeeeeegggggggghhhhhhhiiiiillllnnnnoooooppppprrrrsssstuu.map length.group.sort.map length.group.sort
o111111111LLLLLLLLLLaaaaaaaeeeeeeeegggggggghhhhhhhiiiiillllnnnnoooooppppprrrrsssstuu i=i==1

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.


Try it online!


Wolfram Language (Mathematica), 253 bytes


Try it online!

  • \$\begingroup\$ ( and = both appear exactly once. \$\endgroup\$ Mar 13 '20 at 19:26
  • \$\begingroup\$ @JonathanAllan fixed \$\endgroup\$
    – ZaMoC
    Mar 13 '20 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))
import itertools##22:::^^^^dddddffffff,,,,,,bbbbbbbuuuuuuuu........ccccccccceeeeeeeeeemmmmmmmmmmmpppppppppppprrrrrrrrrrrrsssssssssssss             (((((((((((((()))))))))))))))nnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaiiiiiiiiiiiiiiiiilllllllllllllllttttttttttttttttoooooooooooooooo

Try it online!

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

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

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 ⁼№θEθι 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:

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

JavaScript (Node.js), 253 bytes


Try it online!

unavoidable new Set size length map filter


Japt -!, 36 bytes

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


Try it


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.