We say a string is non-discriminating if each of the string's characters appears the same number of times and at least twice.


  • "aa!1 1 !a !1" is non-discriminating because each of the characters , !, a and 1 appear three times.
  • "abbaabb" is not non-discriminating because b appears more often than a.
  • "abc" is also not non-discriminating because the characters don't appear at least twice.


Write a non-discriminating program or function which returns a truthy value if a given string is non-discriminating, and a falsy value otherwise.

That is, the program run on its own source code should return a truthy value.

Each submission must be able to handle non-empty strings containing printable ASCII, as well as all characters appearing in the source code of the submission.

Test Cases


<your program's source code>
"aa!1 1 !a !1"
"1Q!V_fSiA6Bri{|}tkDM]VjNJ=^_4(a&=?5oYa,1wh|R4YKU #9c!#Q T&f`:sm$@Xv-ugW<P)l}WP>F'jl3xmd'9Ie$MN;TrCBC/tZIL*G27byEn.g0kKhbR%>G-.5pHcL0)JZ`s:*[x2Sz68%v^Ho8+[e,{OAqn?3E<OFwX(;@yu]+z7/pdqUD"


"bQf6ScA5d:4_aJ)D]2*^Mv(E}Kb7o@]krevW?eT0FW;I|J:ix %9!3Fwm;*UZGH`8tV>gy1xX<S/OA7NtB'}c u'V$L,YlYp{#[..j&gTk8jp-6RlGUL#_<^0CCZKPQfD2%s)he-BMRu1n?qdi/!5q=wn$ora+X,POzzHNh=(4{m`39I|s[+E@&y>"
  • 4
    \$\begingroup\$ @Laikoni are we able to abuse comments to get this to work? \$\endgroup\$ Mar 1, 2018 at 14:36
  • 8
    \$\begingroup\$ As a side note, I love challenges where I can use other entries to test my entry's validity. \$\endgroup\$ Mar 1, 2018 at 14:38
  • 3
    \$\begingroup\$ @MagicOctopusUrn I think that he did say in the sandbox that's allowed, since it can't be observably determined. \$\endgroup\$ Mar 1, 2018 at 14:38
  • 12
    \$\begingroup\$ Exactly. Even if you somehow manage to ban comments in an objective fashion, then what about unused string literals ect? Anyway, I think the scoring gives incentive to avoid comments as much as possible. \$\endgroup\$
    – Laikoni
    Mar 1, 2018 at 14:42
  • 4
    \$\begingroup\$ I get it's just a puzzle, but the conflation of "non-discriminating" with "all identifiable labeled member types existing in exactly equal parts" is mildly disturbing... To "discriminate" means "to tell the difference between", and to unfairly do this means to treat or judge someone unfairly based on seeing them as different from another class of people. Of course, keep going with the fun! \$\endgroup\$
    – ErikE
    Mar 1, 2018 at 22:06

38 Answers 38


Brachylog, 10 bytes


Try it online!


=ᵍ                Group all equal elements together
  bᵐbᵐ            Remove the first element of each group twice. This fails if
                  there are fewer than 2 elements
      lᵍ          Group elements together that have the same length
        =         Are all elements of that list equal? This only succeeds if the
                  list has one element
         l        Length. This will always succeed

Java 8, 198 192 186 174 168 165 160 bytes (char-count 6 5)

o->{byte x[]=new byte[+333-3|2],u=-0,i,fe,fi,w; s:w:no0r3sswwyyy:for(int s:o){{u=++x[s];}};for(int b:x){if(!!!(2>b||u==b)|2>u|2>2){x[0]++;}}return!!(0>--x[0]);}

Try it online.
Code used to verify the occurrences of the characters, which was my answer for this challenge.

-5 bytes thanks to @OlivierGrégoire again by getting rid of the comment and making a mess. ;)

Old 168 bytes (char-count 6) answer:

o->{int w[]=new int[2222],u=0,f=0;for(int r:o)u=++w[r];for(int e:w)if(!(2>e|u==e)|2>u)f++;return!(f>0);}//[[[]]]  !!!!e(i)++,,,,-----oo////000tuww::::{{{{{;;||||}}}}}>>

Try it online.
Code used to verify the occurrences of the characters excluding comment, which was my answer for this challenge.

-6 bytes thanks to @OliverGrégoire removing < by swapping the checks to >.

Explanation of the base golfed program (98 bytes):
Try it online.

s->{                     // Method with character-array parameter and boolean return-type
  int a[]=new int[256],  //  Occurrences integer-array containing 256 zeroes
      t=0,               //  Temp integer, starting at 0
      f=0;               //  Flag integer, starting at 0
  for(int c:s)           //  Loop over the input
    t=++a[c];            //   Increase the occurrence-counter of the current character
                         //   And set the temp integer to this value
  for(int i:a)           //  Loop over the integer-array
    if(i>1               //   If the value is filled (not 0) and at least 2,
       &i!=t             //   and it's not equal to the temp integer
       |t<2)             //   Or the temp integer is lower than 2
      f++;               //    Increase the flag-integer by 1
  return f<1;}           //  Return whether the flag integer is still 0

Some things I did to reduce the amount of characters used:

  • Variable names o, w, u, f, r, and e were chosen on purpose to re-use characters we already had (but not exceeding 6).
  • 2222 is used instead of 256.
  • Changed the if-check e>0&u!=e|u<2 to !(e<2|u==e)|u<2 to remove 6x &.
  • Removed the two separated returns and used a flag f, and we return whether it is still 0 in the end (this meant I could remove the 6x by from byte now that we only use n in int 6 times instead of 8).
  • e<2 and u<2 changed to 2>e and 2>u to remove 6x <.

What I did to reduce the char-count 6 to 5:

  • 2x int to byte so the amount of n used is 4 instead of 6.
  • Used x[0] instead of a new variable f=0 so the amount of = used is 5 instead of 6.
  • Changed 2222 to 3333 so the amount of 2 used is 2 instead of 6.
  • Changed variables f and r again so they aren't 6 anymore either.

What @OlivierGrégoire did to get rid of the comment, and therefore the 5x /:

  • Adding unused variables ,i,fe,fi,w;.
  • Adding unused labels: s:w:no0r3sswwyyy:.
  • Adding unused |2>2
  • Adding {} around the for-loops and ifs, and added an unused {}-block.
  • Changing ! to !!!.
  • Changing | to ||.
  • Changing 333 to +333-3|2to get rid of leftover arithmetic operators +-| and the 2.
  • Changing !(x[0]>0) to !!(0>--x[0]).

Jelly, 18 16 12 10 bytes


Try it online!

How it works

Ġ¬zḊḊ¬zĠȦȦ  Main link. Argument: s (string)

Ġ           Group the indices of s by their corresponding elements.
            "abcba" -> [[1, 5], [2, 4], [3]]

 ¬          Take the logical NOT of each 1-based(!) index.
            [[1, 5], [2, 4], [3]] -> [[0, 0], [0, 0], [0]]

   Ḋ        Dequeue; yield s without its fist element.
            "abcba" -> "bcba"

  z         Zip-longest; zip the elements of the array to the left, using the
            string to the right as filler.
            ([[0, 0], [0, 0], [0]], "bcba") -> [[0, 0, 0], [0, 0, "bcba"]]

    Ḋ       Dequeue; remove the first array of the result.
            This yields an empty array if s does not contain duplicates.
            [[0, 0, 0], [0, 0, "bcba"]] -> [[0, 0, "bcba"]]

    ¬       Take the logical NOT of all zeros and characters.
            [[0, 0, "bcba"]] -> [[1, 1, [0, 0, 0, 0]]]

      Ġ     Group.

     z      Zip-longest. Since all arrays in the result to the left have the same
            number of elements, this is just a regular zip.
            [[1, 1, [0, 0, 0, 0]]] -> [[1], [1], [[0, 0, 0, 0]]

       Ȧ    Any and all; test if the result is non-empty and contains no zeroes,
            at any depth. Yield 1 if so, 0 if not.
            [[1], [1], [[0, 0, 0, 0]] -> 0

        Ȧ   Any and all.
            0 -> 0

Brachylog, 14 12 bytes


Try it online!


ọ   Occurrences. Gives a list of [char, count] pairs for the entire input.
tᵐ  Map "tail" over this list, giving each character count.
ℕ₂ᵐ Make sure that each count is at least 2.
=   Make sure that all counts are equal.
    At this point we're done with the actual code, but we need another copy
    of each character (except ᵐ). We can just put them after this, as long as
    we make sure that they can never cause the predicate to fail.
=   Make sure that all counts are equal, again...
t   Extract the last count.
ℕ₂  Make sure that it's at least 2, again...
ọ   Get the digit occurrences in that count, this can't fail.

Alternative 12-byte solution that reuses t instead of :


T-SQL, 320 bytes (32 chars x 10 each)

Input is via pre-existing table FILL with varchar field STEW, per our IO standards.

WHeRe GYP<=1000)SeLeCT
OPTION(MAXRECURSION 0)----------<<<<<<

I have never been more pleased, yet horrified, by a piece of code.

Must be run on a server or database set to a case-sensitive collation. There are 10 each of 32 different characters, including upper and lowercase E (SQL commands are case-insensitive, so flipped a few as needed), spaces and tabs (tabs are shown as line breaks in the code above, for readability).

I found ways to include 10 each of the other symbols + = , in the code, but unfortunately couldn't find a way to do that with <, so I had to add the comment character -.

Here is the formatted code before I crammed in all the extra filler:

SELECT IIF(MIN(w)<MAX(w) OR MAX(w)<1+1,0,1)
    SELECT w=COUNT(1), --extra constant fields here are ignored
    FROM b, fill
    WHERE g < 1+LEN(stew)
    GROUP BY SUBSTRING(stew,g,1)

The top line is a recursive CTE that generates a number table b, which we join to the source string to separate by character. Those characters are grouped and counted, and the IIF statement returns 0 or 1 depending on whether the input string is non-discriminating.


05AB1E, 20 18 16 14 bytes


Try it online!

The program is essentially divided into 2 parts where the goal of the first part is to do the actual task and the goal of the second part is to use the same functions as the first part without altering the result.

Explanation (first part)

S          # push input split into list of chars
 ¢         # count the occurrence of each char in input
  Z≠       # check that the max count is not 1
    sË     # check if all counts are equal
      *    # multiply

Explanation (second part)

s          # swap input to top of stack
 Z¢        # count the number of occurrences of the largest element
   ≠       # check that the count isn't 1
    SË     # split into list and check that each element are equal (always true)
      *    # multiply (as it is with 1, the original result is left unchanged)
  • \$\begingroup\$ {γ€gDË*P≠qq{γ€gDË*P≠ is another for 20 ;). \$\endgroup\$ Mar 1, 2018 at 14:34
  • 1
    \$\begingroup\$ @MagicOctopusUrn: Nice! I had a couple of others at 20 as well. I do have one at 18 now as well :) \$\endgroup\$
    – Emigna
    Mar 1, 2018 at 14:34
  • 2
    \$\begingroup\$ WITCHCRAFT! No other explanation! \$\endgroup\$ Mar 1, 2018 at 14:36
  • 1
    \$\begingroup\$ ¢... good idea man, also I'm glad to see was as useful as I thought it may be haha! \$\endgroup\$ Mar 1, 2018 at 16:03

C (gcc),  333  168 bytes

Thanks to @Kevin Cruijssen for saving 9 bytes and thanks to @Laikoni for saving 45 bytes!


Try it online!

C, 333 bytes


Even the bytecount is non-discriminating!

Try it online!

  • \$\begingroup\$ Awwhh... I wanted to be the first comment abuser. Nice one though, I like how you sorted the chars for the comment ^_^ \$\endgroup\$ Mar 1, 2018 at 14:38
  • 1
    \$\begingroup\$ You can lower it to 324 bytes by changing both the 128 to 222 so the 8 can be dropped. \$\endgroup\$ Mar 1, 2018 at 16:44
  • 1
    \$\begingroup\$ 279 bytes by renaming i, v, S, s and L to characters which already appear in the keywords char, for and return: Try it online! \$\endgroup\$
    – Laikoni
    Mar 2, 2018 at 11:24
  • \$\begingroup\$ @Laikoni Thanks! I didn't have the time to properly golf this yesterday. \$\endgroup\$
    – Steadybox
    Mar 2, 2018 at 20:10
  • \$\begingroup\$ @MagicOctopusUrn They are sorted because I was too lazy to add them by hand. \$\endgroup\$
    – Steadybox
    Mar 2, 2018 at 20:16

Husk, 14 bytes


Try it online!


The two short lines are no-ops, since the main function never calls them.

§<ε#εu§m#u  Implicit input, say S = "asasdd"
         u  Remove duplicates: "asd"
      §m#   For each, get number of occurrences in S: [2,2,2]
     u      Remove duplicates: L = [2]
   #ε       Number of elements in L that are at most 1: 0
  ε         1 if L is a singleton, 0 otherwise: 1
§<          Is the former value smaller than the latter?
  • \$\begingroup\$ But this has ‘u’ more than ‘m’, so it doesn’t meet the requirements. \$\endgroup\$
    – WGroleau
    Mar 2, 2018 at 12:34
  • \$\begingroup\$ @WGroleau m also occurs twice: on the first line and on the second line. The explanation doesn't include the two short lines because they don't affect the behavior of the program. \$\endgroup\$
    – Zgarb
    Mar 2, 2018 at 12:39
  • \$\begingroup\$ I guess the OP should clarify whether an explanation of the program can be scanned along with the program.but actually, if you include that, then you have four ‘u’ and two ‘m’ \$\endgroup\$
    – WGroleau
    Mar 2, 2018 at 12:41
  • \$\begingroup\$ Never mind; this confused me the same way another answer did. \$\endgroup\$
    – WGroleau
    Mar 2, 2018 at 12:50

Python 2, 75 69 bytes

def f(s):len({2<<s.count(c)-2for c,in s})<2or{{e.dil:-tu,r.dil:-tu,}}

Output is via presence or absence of an error. The error is either a ValueError (one or more characters occur only once) or a NameError (the character counts are unequal).

Try it online!

  • \$\begingroup\$ The negative shift error trick is neat! I like how it takes advantage of the shift operator low precedence. \$\endgroup\$
    – Vincent
    Mar 2, 2018 at 14:55
  • 1
    \$\begingroup\$ {{e.dil:-tu,r.dil:-tu,}} Good lord what is that? \$\endgroup\$ Mar 5, 2018 at 14:45
  • 1
    \$\begingroup\$ @AdamBarnes Syntactically valid gibberish that throws a NameError if evaluated. \$\endgroup\$
    – Dennis
    Mar 5, 2018 at 14:53
  • \$\begingroup\$ I don't get it. I tried swapping it out for a and everything broke. Could you explain further please? \$\endgroup\$ Mar 5, 2018 at 15:01
  • \$\begingroup\$ @AdamBarnes That should work, as long as you leave a space after the or. I'll add an explanation when I'm at a computer. \$\endgroup\$
    – Dennis
    Mar 5, 2018 at 16:19

Brachylog v2, 8 bytes (in Brachylog's character set)


Try it online!

Looks like there's been a golfing war going on on this question in Brachylog, so I thought I'd join in, saving a couple of bytes over the next best answer.

This is a full program that takes input as a list of character codes. (This is partly because Brachylog appears to have some very bizarre bugs related to backslashes in strings, and partly because the \ command doesn't work on lists of strings.)


o          Sort {standard input}
 ḅ         Group identical adjacent values
  \        Assert rectangular; if it is, swap rows and columns
   k       Delete last element
    \      Assert rectangular; (rest of the program is irrelevant)

The koḅ at the end is irrelevant; k will always have an element to act on and o and cannot fail if given a list as input.

The reason for the starting oḅ should be clear; it partitions the input list by value, e.g. [1,2,1,2,4,1] would become [[1,1,1],[2,2],[4]]. In order for each character to appear the same number of times, each of these lists must be the same length, i.e. the resulting list is a rectangle. We can assert this rectangularity using \, which also transposes the rows and columns as a side effect.

We now have a current value consisting of multiple copies of the character set, e.g. if the input was [4,2,1,2,4,1] the current value would be [[1,2,4],[1,2,4]]. If we delete a copy, the resulting matrix is still rectangular, so we can turn it back using \. However, if the reason the matrix was rectangular was that all the input characters were distinct, the resulting matrix will have no elements left, and \ does not treat a "0×0" matrix as rectangular (rather, it fails). So oḅ\k\ effectively asserts that each character that appears in the input appears the same number of times, and that number of times is not 1.

That's the entire functionality of our program (as a full program, we get true if no assertion failures occurred, false if some did). We do have to obey the source layout restriction, though, so I added an additional koḅ that has no purpose but which cannot fail (unlike \, o and are happy to act on empty lists).


Python 2, 84 80 bytes

print max(c)==min(c)>1
1. or our>ram>>utopia,
1., 1.,

Try it online!

  • \$\begingroup\$ +1 for non-error-producing short Python code and our ram utopia ;) \$\endgroup\$ Mar 5, 2018 at 4:40

JavaScript (Node.js), 144 ... 100 96 bytes


Try it online!

24 different characters * 6 times each

28 different characters * 5 times each

27 different characters * 5 times each

27 different characters * 4 times each

26 different characters * 4 times each

25 different characters * 4 times each

24 different characters * 4 times each


 a=o.split``.map(                            // Split the input into character array and
  i=>o.split(i||aeehhhlmmnnnpst)[`length`]-1 // count the occurrences of each character.
).some(                                      // Then check
 g=>![g>1][-!1]                              // If each character appears at least twice
 ||a[-!1]-g                                  // and the counts are all the same number.

More to add:
1. Using {s.split``} instead of {[...s]} is to reduce the number of {.} that dominates
   the count.
2. Using {!c.some} instead of {c.every} to reduce the number of inefficient characters 
   (v,r,y in every)
3. Still one unavoidable inefficient character left ({h}).

1. Got rid of one {.} by replacing {.length} by {["length"]}.
2. Got rid of one {=} by replacing {c[-!1]!=g} by {c[-!1]-g}.
3. Got rid of one {()} by replacing {!(g>1)} by {![g>1][-!1]}.
4. Finally, because count per character is now 4, the backslashes can be taken out.

1. Got rid of all {"} by replacing {"length"} by {`length`} and exploiting shortcut
   {aaaeehhhlmmnnnpst} is not defined but is not evaluated either because of {c} which
   must be evaluated to true.

1. Got rid of all {c} by shortcutting the undefined variable at {split(i)} and replacing 
   all {c} by {a}.
   Since {i} is never an empty string, it is always evaluated true (except compared 
   directly to true).

1. Got rid of all {,} by moving the assignment after the argument list. The {()} at the
   front can therefore be moved to the assignment, retaining same number of {()}s.
  • \$\begingroup\$ what on golf's green is "aaaeehhhlmmnnnpst"? \$\endgroup\$ Feb 6, 2022 at 0:27
  • 1
    \$\begingroup\$ @thejonymyster a dummy filler that's never evaluated \$\endgroup\$ Feb 13, 2022 at 8:19

Brachylog, 18 bytes


Try it online!

Unfortunately, I can't remove the linefeeds, since on a number triggers a fail.

  • \$\begingroup\$ It is definitely possible to do something shorter that doesn't require linefeeds (but you might need to change some things) ;) \$\endgroup\$
    – Fatalize
    Mar 1, 2018 at 14:20
  • \$\begingroup\$ @Fatalize No time to currently, and yes I did read that discussion. :) \$\endgroup\$ Mar 1, 2018 at 14:20

PowerShell, 104 bytes

($qe=$args[0]| group |sort count|% count)[0]-eq$qe[-1]-and$qe[0]-gt1####((()))%%%pppddd===aaccss11nu|0gr

Try it online!

This was great fun to golf. The limitation was $, which we need four of at minimum (one for the input $args, one for assigning the computation result $qe, one for checking the last character $qe[-1] and one for checking the first character $qe[0], so that was the working maximum number of characters.

From there, it was a matter of golfing (and not-golfing, like having a two-letter variable name) to get the program nicely divisible by four. Note that we have a small comment (everything following the #) to account for some missing elements, but I tried to keep the comment as small as possible.


Haskell, 90 75 72 bytes


Each character appears 6 times. The input string is taken as a singleton list.

Try it online!

For reference, old versions:

75 bytes, each char 5 times


Try it online!

90 bytes, each char 3 times:

a x|h:u<-[sum[1|d<-x,not(d/=c)]|c<-x],"  \"\\&,../1::>acdlmmnosst">[]=h>1&&all(not.(/=h))u

Try it online!


Python 2, 108 104 92 88 bytes

-12 bytes thanks to Rod
-4 bytes thanks to Kevin Cruijssen

s=input();c=s.count;print[all(c(s[[]>[1]])==c(o)>1. for o in s)];aaafffillpprrtuu>1.>1.;

Try it online!


MATL, 12 bytes


The input is a string enclosed in single quotes. Single quotes in the string are escaped by duplicating.

The output is a non-empty matrix, which is truthy if it doesn't contains zeros, and is falsy if it contains at least a zero.

Try it online! Or verify all test cases, including the standard truthiness/falsiness test for convenience.

How it works

Statements marked with (*) are neither necessary nor harmful, and have been included only to make the source code non-discriminating.

q     % Implicit input. Convert chars to code points and subtract 1 from each (*)
&=    % Square matrix of all pairwise equality comparisons
s     % Sum of each column. Gives a row vector
q     % Subtract 1 from each value. An entry equal to 0 indicates the input string
      % is discriminating because some character appears only once
t     % Duplicate
&=    % Square matrix of all pairwise equality comparisons. An entry equal to 0
      % indicates the input string is discriminating because some character is
      % more repeated than some other
t     % Duplicate (*)
s     % Sum of each column (*) (all those sums will be positive if the previous
      % matrix doesn't contain zeros)
v     % Vertically concatenate the matrix and the vector of its column sums
v     % Vertically concatenate the resulting matrix with nothing (*)
      % Implicit display

Ruby, 87 78 bytes

c=->m{y=m.chars;x=y.map{|d|y.count d}|[];x[-1]>1and not x[1]};->{pushrortpush}

26 characters repeated 3 times each

Try it online!

  • \$\begingroup\$ @nimi Thanks for pointing it out, I think that was some weirdness with gets and ;. Changed it, it's shorter as a lambda anyway \$\endgroup\$ Mar 1, 2018 at 18:00

Perl 5, -p 57 bytes

Each character appears 3 times. Only a single 1 doesn't do anything

12 bytes added to a basic 45 character solution to make in non-discriminating


Try it online!


R, 90 bytes


Try it online!

Outputs TRUE for a non-discriminating string, and FALSE for a discriminating string. I have written a lot of ugly code for challenges on this site, but I think this is the ugliest so far.

45 characters, used twice each (including a few in a comment). The previous best R answer was 116 bytes, with 29 characters used 4 times each; I am posting this separately since it is substantially different.

The code is equivalent to

y = table(utf8ToInt(readLines()))
z = y[1]
all(y == z) & (z > 1)

which converts the input to a vector of integers, computes a contingency table y of the values, then checks that all counts in that table are equal to the first count, and that the first count is greater than 1.

The initial difficulty was in using only 2 pairs of brackets. This is achieved by redefining the unary functions ! and ? to be utf8ToInt and prod respectively. (I can't use all because I need the a). There are four assignments: two with = and two with <-. This means that the equality test between y and z cannot use y==z nor y-z; y%in%z comes to the rescue.

Defining these functions uses up all the possible quotes: two double quotes, two single quotes, and I'll need the two backticks in the next paragraph, so I had to resort to readLines() instead of scan(,""). (The other options, such as scan(,letters) or scan(,month.abb) all used a precious t which I couldn't spare.)

At this point, I had most of the building blocks: utf8ToInt, prod, table, readLines, %in%. Three characters appear three times in those names: ent. First, I discovered that table(foo) is equivalent to xtabs(~foo), saving the e. I can rescue the n and the t with the hex/octal code trick; the golfiest solution is to use u\164f8ToI\x6Et (in backticks) for utf8ToInt.

  • \$\begingroup\$ It's impressive you can discriminate the two cases in 90 bytes (and nice abuse of the help operator), but alas NA is not considered a truthy value (in R, if(NA) x else y causes an error, so NA is neither truthy nor falsey) \$\endgroup\$
    – JDL
    Sep 5, 2019 at 16:03
  • 1
    \$\begingroup\$ @JDL Thanks, you're right. The latest edit fixes this issue. \$\endgroup\$ Sep 6, 2019 at 3:57
  • 1
    \$\begingroup\$ @JDL the comments suggest that consistent, distinct answers are ok for truthy and falsy. \$\endgroup\$
    – Giuseppe
    Sep 6, 2019 at 3:57
  • \$\begingroup\$ @Giuseppe Actually, I solved this issue seconds ago (see new version, which is quite different but same byte count); now outputs TRUE and FALSE. \$\endgroup\$ Sep 6, 2019 at 3:58

R, 132 116 bytes


It doesn't contain any comments or superfluous strings, either, though this will probably be my only time in code golf calling a function crudcardounenforceableuploads. There's probably a great anagram in there somewhere for the function name!Thanks to John Dvorak for pointing out a nice anagram solver, which I used for the name.

Character table:

- , ; ! " ( ) [ ] { } & < 1 a b c d e f i l n o p r s t u 
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4


> crudcardounenforceableuploads("aaabbbccc")
[1] TRUE
> crudcardounenforceableuploads("aaabbbcc")
> crudcardounenforceableuploads("abc")
> crudcardounenforceableuploads("crudcardounenforceableuploads<-function(b){{pi&&pi[[1-!1]];;;\"\";{1<{f<<-table(strsplit(b,\"\",,,)[[1]])}}&&!!!sd(-f)}}")
[1] TRUE
  • \$\begingroup\$ don't know if byte count is important but we can probably remove the 2s and the >s, by switching round the comparison with f. Also can use = instead of <<-. strsplit is probably unavoidable though, which is the source of most of the other characters. \$\endgroup\$
    – JDL
    Mar 1, 2018 at 17:25
  • \$\begingroup\$ do you need the spaces? you could also try utf8ToInt instead of strsplit, but not sure if that'll help. Also maybe include a link to TIO? \$\endgroup\$
    – Giuseppe
    Mar 1, 2018 at 17:59
  • \$\begingroup\$ also all the . seem to be superfluous. \$\endgroup\$
    – Giuseppe
    Mar 1, 2018 at 18:02
  • \$\begingroup\$ This is code-golf, so byte count is important, per your comment. \$\endgroup\$
    – Giuseppe
    Mar 1, 2018 at 18:09
  • 2
    \$\begingroup\$ some possible anagrams: no pip-bonded cupboard bureaucracies; RIP carbonaceous barbecued pound dip. Found using wordplays.com/anagrammer \$\endgroup\$ Mar 2, 2018 at 8:32

C (gcc), 153 bytes


Try it online!

Returns address of string as truthy value, and zero as falsy.

h,                              Address of string.
a,                              # instances of previous character
c,                              # instances of current character
f                               Return value
char*o=f=h,*r;                  Point o to string, while giving f a non-zero value.
for(a=!h;*o;o++){               Set previous char count to 0, and then traverse the string.
for(c=!h,r=h;*r;                Set current char count to 0 and r to string,
                                and start counting instances of current character.
c+=!(*r++^*o))                  Add to counter if current character matches.
{}                              Lower the amount of semi-colons
f*=                             Multiply (AND) return value with:
   !!(c^!!h)                    Is current count not 1? (Must be 2 or above.)
            *(!a+!(a^c));       AND, is previous count valid (meaning this is not the first
                                character counted), and matches current count?
a=c;}                           Previous count = current count.
(a^c^c^f^f^h)+o,a+r,o,o,+h^*r;  Spend surplus characters to make source code valid.
(a=f);}}}}}}}                   Return value.

BASH 144 bytes

grep -o .|sort|uniq -c|awk '{s=$1}{e[s]=1}END{print((s>1)*(length(e)==1))}##>>>#|'#wwwuuutrqqqppooNNNnlllkkkiihhhggEEEDDDcccaaa1***{}[[[]]]...--''

This line of code takes an stdin string as input. "grep -o ." puts each character on a new line. "uniq -c" counts each chacter's usage. The awk script creates an array with each usage as a different element, and outputs true when there is only 1 array index and the value is at least 2. Each character is used 4 times, so this source returns true


Stax, 26 24 18 bytes


Try it online!

Shortest solution so far that only uses printable ASCIIs Beaten by MATL.

Guess I was approaching the problem the wrong way. Repeating a working block is neither golfy nor interesting. Now at least it looks better ...


:u{m* produces some garbage that does not affect the output.

_{y#m           map each character to its number of occurences in the string
     :u         all counts are equal (result 1)
       _hy#     get the count of appearance for the first character
           h    halve it and take the floor, so that 1 becomes 0(result 2)
            *   multiply the two results
  • \$\begingroup\$ @WGroleau which characters appear once? Did you read my answer carefully enough? \$\endgroup\$ Mar 2, 2018 at 12:41
  • \$\begingroup\$ ‘#’ appears more often than ‘:’ (just one example). Oops, misreading (see other comment) \$\endgroup\$
    – WGroleau
    Mar 2, 2018 at 12:44
  • \$\begingroup\$ @WGroleau There are exactly two #'s and two :s, did you read my answer on the second line? Did you just skip the first paragraph in my "Explanation"? \$\endgroup\$ Mar 2, 2018 at 12:45
  • \$\begingroup\$ Sorry, thought the line above the explanation was the whole thing. \$\endgroup\$
    – WGroleau
    Mar 2, 2018 at 12:48

Pip, 22 bytes


Try it online!


Each character occurs twice.

                        a is first command-line argument
I1&MY$=_                No-ops to make the program non-discriminating
            Ma          Map this function to the characters of a:
         _Na             Count occurrences of each character in a
        Y               Yank the result into y
              $=y       Fold y on equals: truthy if all elements are equal
                 &      Logical and
                  1NIy  1 is not in y
                        Autoprint the result of the last expression

Alternate 22-byte version with fewer no-ops:


SmileBASIC, 164 152 148 140 bytes

INC w[ASC(x)]X[n]=""wEND
FOR F=e#TO--nOT-LEN(W)U=w[F]H=H||U&&U<MAx(W)neXT-!!!AASSS#&&Oxx||CCLL<<wIM#

35 different characters, repeated 4 times each.

No comments were used (but the expression after neXT is never actually evaluated)

Script to check answers:

//javascript is a convenient language that I love using!
var input=document.getElementById("input");
var button=document.getElementById("button");
var output=document.getElementById("output");

  var text=input.value;
  var freqs={};
  for(var i=0;i<text.length;i++){
    var letter=text.charAt(i);
    if (freqs[letter]==undefined) freqs[letter]=0
  sorted=Object.keys(freqs).sort(function(a,b){return freqs[b]-freqs[a]})
  var out="";
  var min=Infinity,max=0;
  for (var i in sorted) {
    var letter=sorted[i];
    var count=freqs[letter];
<textarea id="input" placeholder="code here"></textarea>
<button id="button"butt>count</button>
<pre id="output">...</pre>


Retina 0.8.2, 168 90 bytes

The output will be empty if false, or non-empty if true.



Try it online

Core program (39 bytes)



The entire core program is in a silent loop. The first stage sorts the input. The second stage will print the current string if it consists of successive pairs of different characters. The third stage removes the last occurrence of every character (removing one of each character in the string).

About the junk at the top: the order is important. In addition to needing to be syntactically valid, a semicolon must be after the asterisks and before the backticks, so long as * is in the config string, in order for it to not print.

  • \$\begingroup\$ Nice, my answer is shorter but I'm not sure it scales well to being fixed for 0/1 as output, so I'm just going to add it here in case it helps you: tio.run/##K0otycxLNPz/… \$\endgroup\$ Mar 2, 2018 at 4:40
  • \$\begingroup\$ @FryAmTheEggman I was looking for a pure regex solution to match character groups of same lengths all in a row, but I couldn't figure it out. \$\endgroup\$
    – mbomb007
    Mar 2, 2018 at 14:26
  • \$\begingroup\$ @FryAmTheEggman Made a big improvement! I didn't really use what you had, but I started from scratch trying to think of a better method. \$\endgroup\$
    – mbomb007
    Mar 2, 2018 at 15:30
  • \$\begingroup\$ Nicely done! And I hadn't thought enough about my program it seems, but at least you found a better one :) \$\endgroup\$ Mar 2, 2018 at 19:18

CoffeeScript 1, 96 93 90 bytes

(q,a=q.split(h).length-1for h in[q][0])->a.every (w,s,pplitnggffoorsvvyy)->w>1&&a[0&10]==w

Try it online!

Started from my ES6 answer but walked back to using Array.every. 32 31 30 tokens @ 3 each


Pyth, 30 bytes


Leading spaces necessary.

Try it online!

The actual program is just &q1lJ{hMrSz8<1hJ. I just prepended the string "&8<MQSlqr{" to make it non-discriminating. But to make the string not print itself, I had to add a space, so I added 2 spaces.


 q1l                (1 == len(
    J{                  J = deduplicate(
      hM                  map(lambda a: a[0],
        r  8                length_encode(
         Sz                   sorted(input())
&                     and
            <1hJ    (1 < J[0])

length_encode here (r <any> 8) takes a sequence and outputs the length of each run of the same character, ex. "aaabbcc" becomes [[3, "a"], [2, "b"], [2, "c"]].

So this takes the input, sorts it to put in length encode, and takes the first element of each list in the resulting list (e.g. the earlier example would become [3, 2, 2]). This gives a count of how many times characters occur. Then it's deduplicated (the earlier example would become [3, 2]), and J is set to that.

Then it checks if the length is 1, i.e. there is only 1 unique number of times a character occurs, and if that is > 1, i.e. >= 2.

There might be a built-in to replace rSz8 or hMrSz8 but I can't find one.


Perl 6, 58 57 bytes

{.max==.min>()**()}o{(bag .comb){*}}###=>>abccggiinnoxx  

Try it online!

Turns out the three character version is slightly shorter than the two character one.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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