Non-discriminating Programming

75

10

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

Examples

  • "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.

Task

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

Truthy:

<your program's source code>
"aaaa"
"aa!1 1 !a !1"
"aabbccddeeffgg"
"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"

Falsy:

"a"
"abbaabb"
"abc"
"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>"

Laikoni

Posted 2018-03-01T14:02:57.473

Reputation: 23 676

4@Laikoni are we able to abuse comments to get this to work? – Magic Octopus Urn – 2018-03-01T14:36:09.623

6As a side note, I love challenges where I can use other entries to test my entry's validity. – Magic Octopus Urn – 2018-03-01T14:38:15.520

3@MagicOctopusUrn I think that he did say in the sandbox that's allowed, since it can't be observably determined. – Erik the Outgolfer – 2018-03-01T14:38:39.050

11Exactly. 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. – Laikoni – 2018-03-01T14:42:52.807

I wrote a program in Retina, a language that doesn't really have a conditional construct (it sort of does, but it is based on matching a regex, so the default of matching an empty string would mean everything is truthy?). Could I submit my answer if it outputs 1 for non-discriminating input and 2 otherwise? – FryAmTheEggman – 2018-03-01T16:50:13.283

4I 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! – ErikE – 2018-03-01T22:06:03.563

@mbomb007 I don't understand what you mean, I was only asking about the output of our programs. – FryAmTheEggman – 2018-03-01T23:20:57.543

@FryAmTheEggman Looking at recent Retina submissions to [tag:decision-problem] challenges suggests that zero or one are acceptable as truthy/falsy values. – Laikoni – 2018-03-01T23:25:18.453

@Laikoni For several, including the most recent, they assume 0 is falsy and positive is truthy. This is the problem with using this convention, I think it's actually rather bad for languages that don't have traditional if/else constructs. There was a discussion about this not too long ago, but I don't think it got enough visibility.

– FryAmTheEggman – 2018-03-01T23:32:59.920

Is accepting an array of integers that are the ASCII decimal values of the input okay? – Okx – 2018-03-02T09:46:42.147

@FryAmTheEggman Then that's also fine with me. – Laikoni – 2018-03-02T11:08:10.120

@Okx I'd say that's only acceptable if the language has no way of processing strings or arrays of characters. – Laikoni – 2018-03-02T11:09:27.980

Apparently you need to emphasise that the program also needs to be non-discriminating too. Since you've already bolded and italicized it, I'm not sure what else you could do... Maybe ALL CAPS – Jo King – 2018-03-05T05:38:31.450

"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." -- I missed this in my initial comment. The expected result for the empty string was otherwise well-defined. Is there a particular reason you're not requiring any particular result for that? Existing answers vary in the results they give, so it's probably too late to change now. – hvd – 2018-03-05T11:27:34.380

@hvd While the definition covers the empty string it is still likely to be an edge case for many approaches to solve the challenge, and handling edge cases which are not important to the challenge is usually not fun.

– Laikoni – 2018-03-05T12:09:07.213

@Laikoni The link you give is about not adding special cases. Excluding edge cases is actually adding special cases. If you think it's more fun like this, that's a good reason, but it's not supported by your link. :) – hvd – 2018-03-05T12:48:20.253

@hvd I don't see how saying that only non-empty strings need be handled, which is equivalent to saying that your program can do whatever it want when receiving the empty string as input, is in any way adding a special case. Requiring the empty string to be handled might lead to answers like ... or empty(s) in which the empty string is a special case. Dropping this requirement still leaves all answers valid but also allows to drop the code only needed for the special case. – Laikoni – 2018-03-05T13:07:32.830

@Laikoni You're trying to avoid special cases in the answers but I think the link you provided was about special cases in the challenges. But yeah, already agreed that changing the challenge now is not an option. – hvd – 2018-03-05T13:18:28.467

Answers

37

Brachylog, 10 bytes

=ᵍbᵐbᵐlᵍ=l

Try it online!

Explanation

=ᵍ                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

H.PWiz

Posted 2018-03-01T14:02:57.473

Reputation: 10 962

25

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]).

Kevin Cruijssen

Posted 2018-03-01T14:02:57.473

Reputation: 67 575

1180 bytes: changed all < into >. – Olivier Grégoire – 2018-03-01T15:54:38.297

@OlivierGrégoire Sorry, I'm already at 174 :) But will see if your trick can still be applied. – Kevin Cruijssen – 2018-03-01T15:55:27.420

The change can still apply to save 6 bytes. – Olivier Grégoire – 2018-03-01T15:55:55.783

Closest I am to 162 characters (161 characters). I'm trying to remove the comment, but I still need to put a comma somewhere. I just can't find any place. – Olivier Grégoire – 2018-03-01T16:44:23.950

@OlivierGrégoire Isn't it possible to change the char-count from 6 to 5 somehow like I did in my current 165-bytes answer? – Kevin Cruijssen – 2018-03-01T16:48:12.983

Since you only care about printable ascii, making the array size 222 works in theory to remove the 3s, but in practice that runs into an overflow issue due to the byte array which 3333 manages to cleanly avoid since it's 13*256+5 (I was looking into this before you changed it back to a byte array) Didn't know if there was anything you could do with that information – PunPun1000 – 2018-03-01T18:59:06.433

1160 bytes (proof). Very likely more golfable. – Olivier Grégoire – 2018-03-01T19:02:37.073

All 3s should be able to be removed by using "2220", also. Untested, though. – Aidan F. Pierce – 2018-03-01T20:30:07.940

@AidanF.Pierce Hmm, might indeed be possible. Only problem in the current implementation where we increase the flag x[0] is that byte can only hold up to 127, and will wrap-around (127 + 1 = -128). So the check if the flag is larger than 0 in the end will return false because 2220 is too big. But perhaps there is indeed a way to remove those 333s using the three leftover 2s. – Kevin Cruijssen – 2018-03-01T20:40:12.060

@KevinCruijssen Sorry, missed the edit. I can't see any way to do that now, but maybe there still is one. – Aidan F. Pierce – 2018-03-01T20:44:57.830

Sorry for the mess I put here! xD Hint for further golfing: start from version at 165 bytes, golf that, then use @KevinCruyssen's analysis of my mess to remove the comments. Be ready to spend time on it! – Olivier Grégoire – 2018-03-02T08:26:09.630

15

Jelly, 18 16 12 10 bytes

Ġ¬zḊḊ¬zĠȦȦ

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

Dennis

Posted 2018-03-01T14:02:57.473

Reputation: 196 637

13

Brachylog, 14 12 bytes

ọtᵐℕ₂ᵐ==tℕ₂ọ

Try it online!

Explanation

ọ   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ᵐ==tℕ₂ℕ₂ọᵐ

Martin Ender

Posted 2018-03-01T14:02:57.473

Reputation: 184 808

13

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

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

WITH BUMPF AS(SeLeCT GYP=1
UNION ALL
SeLeCT GYP+1FROM BUMPF
WHeRe GYP<=1000)SeLeCT
IIF(MIN(WAXBY)<MAX(WAXBY)OR
MAX(WAXBY)<=1,+0,+1)FROM(SeLeCT
WAXBY=COUNT(1),WHICH=+1+0,HEXCHANGE=+01,HUNG=+0+1,CHLUB=+0,GEFF=+0FROM
BUMPF,FILL WHERE
GYP<=LEN(STEW)GROUP BY
SUBSTRING(STEW,GYP,1))CHEXX
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:

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

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.

BradC

Posted 2018-03-01T14:02:57.473

Reputation: 6 099

11

C (gcc),  333  168 bytes

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

f(r,h,a){char*o=r,c[222]={!o};for(a=!o;*o;)++c[*o++];for(h=!o;222/++h;c[h]&&c[h]!=a&&(a=!*c))!a&&c[h]&&(a=c[h]);r=!(2/2/a);}/////!(())****++,,,,,[[]]fffffrr{{{{{{}}}}}}

Try it online!

C, 333 bytes

i,v;f(S){char*s=S,L[128]={0};for(v=0;*s;)++L[*s++];for(i=-1;++i<128;L[i]&&L[i]-v?v=-1:0)!v&&L[i]?v=L[i]:0;return-v<-1;}/////////!!!!!!!!&&&&&(((((())))))******+++,,,,,,,----00000111122222228888888:::::::<<<<<<<===???????LLLSSSSSSS[[[]]]aaaaaaaacccccccceeeeeeeeffffffhhhhhhhhiinnnnnnnnooooooorrrrssssssttttttttuuuuuuuuvv{{{{{{{}}}}}}}

Even the bytecount is non-discriminating!

Try it online!

Steadybox

Posted 2018-03-01T14:02:57.473

Reputation: 15 798

Awwhh... I wanted to be the first comment abuser. Nice one though, I like how you sorted the chars for the comment ^_^ – Magic Octopus Urn – 2018-03-01T14:38:50.477

1

You can lower it to 324 bytes by changing both the 128 to 222 so the 8 can be dropped.

– Kevin Cruijssen – 2018-03-01T16:44:14.540

1

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!

– Laikoni – 2018-03-02T11:24:02.280

@Laikoni Thanks! I didn't have the time to properly golf this yesterday. – Steadybox – 2018-03-02T20:10:24.580

@MagicOctopusUrn They are sorted because I was too lazy to add them by hand.

– Steadybox – 2018-03-02T20:16:37.483

You might be able to drop the comment entirely including all / by somehow putting everything inside useless variables. OlivierGrégoire did something similar in my Java answer, and I also did something similar in ovs' Python 2 answer. I don't have time right now to try it though, and I'm not too skilled in C either..

– Kevin Cruijssen – 2018-03-02T20:22:00.543

@KevinCruijssen Perhaps, but I need those /s there anyway, because otherwise I would need a lot of <s. – Steadybox – 2018-03-02T20:28:48.857

9

05AB1E, 20 18 16 14 bytes

S¢Z≠sË*sZ¢≠SË*

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)

Emigna

Posted 2018-03-01T14:02:57.473

Reputation: 50 798

{γ€gDË*P≠qq{γ€gDË*P≠ is another for 20 ;). – Magic Octopus Urn – 2018-03-01T14:34:04.387

1@MagicOctopusUrn: Nice! I had a couple of others at 20 as well. I do have one at 18 now as well :) – Emigna – 2018-03-01T14:34:54.673

2WITCHCRAFT! No other explanation! – Magic Octopus Urn – 2018-03-01T14:36:31.063

1¢... good idea man, also I'm glad to see was as useful as I thought it may be haha! – Magic Octopus Urn – 2018-03-01T16:03:36.533

9

Husk, 14 bytes

§<ε#εu§m#u
m
<

Try it online!

Explanation

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?

Zgarb

Posted 2018-03-01T14:02:57.473

Reputation: 39 083

But this has ‘u’ more than ‘m’, so it doesn’t meet the requirements. – WGroleau – 2018-03-02T12:34:49.203

@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. – Zgarb – 2018-03-02T12:39:11.917

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’ – WGroleau – 2018-03-02T12:41:08.183

Never mind; this confused me the same way another answer did. – WGroleau – 2018-03-02T12:50:40.403

9

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!

Dennis

Posted 2018-03-01T14:02:57.473

Reputation: 196 637

The negative shift error trick is neat! I like how it takes advantage of the shift operator low precedence. – Vincent – 2018-03-02T14:55:29.313

1{{e.dil:-tu,r.dil:-tu,}} Good lord what is that? – Adam Barnes – 2018-03-05T14:45:21.497

1@AdamBarnes Syntactically valid gibberish that throws a NameError if evaluated. – Dennis – 2018-03-05T14:53:15.200

I don't get it. I tried swapping it out for a and everything broke. Could you explain further please? – Adam Barnes – 2018-03-05T15:01:22.913

@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. – Dennis – 2018-03-05T16:19:04.970

Doesn't seem to work, The True disappears from the end of the Self test: True line in the output. – Adam Barnes – 2018-03-05T16:23:29.183

@AdamBarnes That because the resulting source code is no longer non-discriminating. Tje program itself still works as intended. – Dennis – 2018-03-05T16:25:21.573

Good lord I didn't even notice that was a requirement. Thanks, that makes sense. – Adam Barnes – 2018-03-05T16:27:05.910

9

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

oḅ\k\koḅ

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.)

Explanation

oḅ\k\koḅ
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).

ais523

Posted 2018-03-01T14:02:57.473

Reputation: 11

1

It's the language of this month!

– Erik the Outgolfer – 2018-03-18T09:42:57.213

7

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

o=>!(a=o.split``.map(i=>o.split(i||aeehhhlmmnnnpst)[`length`]-1)).some(g=>![g>1][-!1]||a[-!1]-g)

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

Explanation

o=>!(
 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}).

Update:
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.

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

Update:
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).

Update:
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.

Shieru Asakoto

Posted 2018-03-01T14:02:57.473

Reputation: 4 445

7

Python 2, 84 80 bytes

x=input()
c=map(x.count,x)
print max(c)==min(c)>1
1. or our>ram>>utopia,
1., 1.,

Try it online!

Vincent

Posted 2018-03-01T14:02:57.473

Reputation: 601

+1 for non-error-producing short Python code and our ram utopia ;) – Shieru Asakoto – 2018-03-05T04:40:19.103

6

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!

ovs

Posted 2018-03-01T14:02:57.473

Reputation: 21 408

1Your program must be non-discriminating. – user202729 – 2018-03-01T14:27:17.680

1The program itself must be non-discriminating. – HyperNeutrino – 2018-03-01T14:27:24.143

@user202729 Thanks for telling me, I updated my answer. – ovs – 2018-03-01T14:39:00.233

@HyperNeutrino updated my answer – ovs – 2018-03-01T14:39:18.770

1s=input();c=s.count;print[all(c(s[[]>[1]])>=c(o)>1. for o in s)];aaafffillpprrtuu=1.>1.; 88 bytes by getting rid of the comment. – Kevin Cruijssen – 2018-03-01T21:25:52.610

1aaabb seems to yield True – Vincent – 2018-03-02T11:58:11.207

@Vincent fixed it. – ovs – 2018-03-02T15:21:54.983

6

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.

AdmBorkBork

Posted 2018-03-01T14:02:57.473

Reputation: 41 581

6

Haskell, 90 75 72 bytes

a[i]|d:n<-[[i|n<-i,n==a]|a<-i]=and[[i]<d,[d|i<-n]==n]--aadd,,,,:::::<=||

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

n(l)|d<-[[0|n<-l,n==a]|a<-l]=and[[0]<d!!0,all(==d!!0)d]--an!((())),,,0<[]||

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!

nimi

Posted 2018-03-01T14:02:57.473

Reputation: 34 639

6

MATL, 12 bytes

q&=sqt&=tsvv

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

Luis Mendo

Posted 2018-03-01T14:02:57.473

Reputation: 87 464

5

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

s{.}[@m[@1{$&}+=$.].=g]eg;$\=s()(e@m;1)&&m[e(\sg+)\1+;]}{

Try it online!

Ton Hospel

Posted 2018-03-01T14:02:57.473

Reputation: 14 114

5

R, 90 bytes

"?"=`u\164f8ToI\x6Et`;'!'=prod;!{y<-xtabs(~?readLines())}%in%{z<-y[1]}&z>T##&[]>~48bEfILpu

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.

Robin Ryder

Posted 2018-03-01T14:02:57.473

Reputation: 6 625

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) – JDL – 2019-09-05T16:03:31.150

1@JDL Thanks, you're right. The latest edit fixes this issue. – Robin Ryder – 2019-09-06T03:57:13.230

1@JDL the comments suggest that consistent, distinct answers are ok for truthy and falsy. – Giuseppe – 2019-09-06T03:57:58.620

@Giuseppe Actually, I solved this issue seconds ago (see new version, which is quite different but same byte count); now outputs TRUE and FALSE. – Robin Ryder – 2019-09-06T03:58:37.677

4

Brachylog, 18 bytes

oḅlᵐ=h≥2
oḅlᵐ=h≥2

Try it online!

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

Erik the Outgolfer

Posted 2018-03-01T14:02:57.473

Reputation: 38 134

It is definitely possible to do something shorter that doesn't require linefeeds (but you might need to change some things) ;) – Fatalize – 2018-03-01T14:20:03.450

@Fatalize No time to currently, and yes I did read that discussion. :) – Erik the Outgolfer – 2018-03-01T14:20:37.107

4

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!

Asone Tuhid

Posted 2018-03-01T14:02:57.473

Reputation: 1 944

@nimi Thanks for pointing it out, I think that was some weirdness with gets and ;. Changed it, it's shorter as a lambda anyway – Asone Tuhid – 2018-03-01T18:00:53.197

3

R, 132 116 bytes

crudcardounenforceableuploads<-function(b){{pi&&pi[[1-!1]];;;"";{1<{f<<-table(strsplit(b,"",,,)[[1]])}}&&!!!sd(-f)}}

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

examples:

> crudcardounenforceableuploads("aaabbbccc")
[1] TRUE
> crudcardounenforceableuploads("aaabbbcc")
[1] FALSE
> crudcardounenforceableuploads("abc")
[1] FALSE
> crudcardounenforceableuploads("crudcardounenforceableuploads<-function(b){{pi&&pi[[1-!1]];;;\"\";{1<{f<<-table(strsplit(b,\"\",,,)[[1]])}}&&!!!sd(-f)}}")
[1] TRUE

JDL

Posted 2018-03-01T14:02:57.473

Reputation: 1 135

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. – JDL – 2018-03-01T17:25:13.767

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? – Giuseppe – 2018-03-01T17:59:47.237

also all the . seem to be superfluous. – Giuseppe – 2018-03-01T18:02:30.327

This is [tag:code-golf], so byte count is important, per your comment. – Giuseppe – 2018-03-01T18:09:04.763

Can someone explain to me why the two semicolons after table(strsplit(l,"",,,)[[1.]]); are legal? – Vlo – 2018-03-01T22:09:44.870

2

some possible anagrams: no pip-bonded cupboard bureaucracies; RIP carbonaceous barbecued pound dip. Found using https://www.wordplays.com/anagrammer

– John Dvorak – 2018-03-02T08:32:00.600

Vlo, they are equivalent to blank lines (I could have used \n in place of each of the ;) – JDL – 2018-03-02T08:51:45.673

golfed away those 16 now. It might be possible to remove the ; as well, though it will be tricky (perhaps starting pi[[1-!1]]&&... and having "1" instead of 1 somewhere? – JDL – 2018-03-02T09:58:34.300

90 bytes, using a different strategy. – Robin Ryder – 2019-09-05T14:54:25.930

2

Stax, 26 24 18 bytes

:u{m*_{y#m:u_hy#h*

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 ...

Explanation

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

_{y#m:u_hy#h*
_{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

Weijun Zhou

Posted 2018-03-01T14:02:57.473

Reputation: 3 396

@WGroleau which characters appear once? Did you read my answer carefully enough? – Weijun Zhou – 2018-03-02T12:41:41.330

‘#’ appears more often than ‘:’ (just one example). Oops, misreading (see other comment) – WGroleau – 2018-03-02T12:44:51.183

@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"? – Weijun Zhou – 2018-03-02T12:45:59.880

Sorry, thought the line above the explanation was the whole thing. – WGroleau – 2018-03-02T12:48:11.750

2

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

Caleb

Posted 2018-03-01T14:02:57.473

Reputation: 121

2

C (gcc), 153 bytes

f(h,a,c,f){{{{{{{char*o=f=h,*r;for(a=!h;*o;o++){for(c=!h,r=h;*r;c+=!(*r++^*o)){}f*=!!(c^!!h)*(!a+!(a^c));a=c;}(a^c^c^f^f^h)+o,a+r,o,o,+h^*r;(a=f);}}}}}}}

Try it online!

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

f(
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.

gastropner

Posted 2018-03-01T14:02:57.473

Reputation: 3 264

1

SmileBASIC, 164 152 148 140 bytes

DeF M(X)DIM W[#R]WHILE""<X
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#
RETURN!H
enD

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");

button.onclick=function(){
  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
    freqs[letter]++
  }
  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];
    if(count<min)min=count;
    if(count>max)max=count;
    out+="\n"+letter+":"+count;
  }
  output.textContent="min:"+min+"\nmax:"+max+"\nunique:"+sorted.length+"\nlength:"+text.length+out;
}
<textarea id="input" placeholder="code here"></textarea>
<button id="button"butt>count</button>
<pre id="output">...</pre>

12Me21

Posted 2018-03-01T14:02:57.473

Reputation: 6 110

1

Pip, 22 bytes

I1&MY$=_Y_NaMa$=y&1NIy

Try it online!

Explanation

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:

$&MY_Y_NaMa$=y&--1=1Ny

DLosc

Posted 2018-03-01T14:02:57.473

Reputation: 21 213

1

Retina 0.8.2, 168 90 bytes

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

***???;;;;```!!$$$$MMMMOOOO..1111ssss222{{{{\^^^^

s;{O`.
M!*\`^((.)\2(?!\2))*$
(.)(?!\1)

Try it online

Core program (39 bytes)

s;{O`.
M!*\`^((.)\2(?!\2))*$
(.)(?!\1)

Explanation

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.

mbomb007

Posted 2018-03-01T14:02:57.473

Reputation: 21 944

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: https://tio.run/##K0otycxLNPz/vzhBQ09Tw97GVsPeVgNIG9rFGGrW6Glqa@ppadYUA4GdnV2NXYw2BKoAgbK9srJyjYuLi5aLkZaRkVFCQoKNlg3QCFtbQ8ND2w5t0@NSUQYyuLi4XBL0tICMQ9tqjOhoFQA

– FryAmTheEggman – 2018-03-02T04:40:09.887

@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. – mbomb007 – 2018-03-02T14:26:57.280

@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. – mbomb007 – 2018-03-02T15:30:46.973

Nicely done! And I hadn't thought enough about my program it seems, but at least you found a better one :) – FryAmTheEggman – 2018-03-02T19:18:28.437

1

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

Shieru Asakoto

Posted 2018-03-01T14:02:57.473

Reputation: 4 445

1

Pyth, 30 bytes

  "&8<MQSlqr{"&q1lJ{hMrSz8<1hJ

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.

&q1lJ{hMrSz8<1hJ

 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.

RK.

Posted 2018-03-01T14:02:57.473

Reputation: 497

1

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.

Jo King

Posted 2018-03-01T14:02:57.473

Reputation: 38 234

0

Perl 6, 132 100 bytes

my &f={{$_[0]>1&&[==] $_}(.comb.categorize({$_}).values)}#myy ff[]00>>11()cobbattggrriizzvvlluuss##

bb94

Posted 2018-03-01T14:02:57.473

Reputation: 1 831

0

Pyth, 66 bytes

 " &&))//0<<==??@@IIJNNVVaallqq{"zJ.{zVJ=aY/zN)I&q1l.{Y<1@Y01.?0 "

Try it online!

Pyth (indented) | Python 3 (translation)
                                  | def a(A,B):
                                  |     c=list(A)
                                  |     c.append(B)
                                  |     return c
                                  | Y=[]
                                  | z=input()
 " &&))//0<<==??@@IIJNNVVaallqq{" | " &&))//0<<==??@@IIJNNVVaallqq{"
z                                 | print(z)
J.{z                              | J=set(z)
VJ                                | for N in J:
    =aY/zN)                       |     Y=a(Y,z.count(N))
I&q1l.{Y<1@Y0                     | if 1==len(set(Y)) and 1<Y[0]:
    1                             |     print(1)
.?                                | else:
    0                             |     print(0)
     "                            |     ""

hakr14

Posted 2018-03-01T14:02:57.473

Reputation: 1 295

0

APL, 19 72 bytes

This is my second attempt at golfing and also second program in APL. I cant figure out if I can do an unnamed lambda within a named function. If I can do that I can shave some bytes and make it more readable. Was happy to land on a solution so quick #I♥APL

i ← ⍞ ◊ 2 ≤ ∨ / { ⍴ i ∩ ⍵ } ¨ ∪ i[⍋i]

i←{⍞}◊{}◊{}◊◊2≤∨/∨/∨/∨/{∪⍴i∩∪⍵}¨∪i[∪⍋i]⍝⍝⍝⍝⍞⍞⍞←←←222≤≤≤¨¨¨∩∩∩⍴⍴⍴⍵⍵⍵[[[]]]⍋⍋⍋

Try Apl Online Note you will need to change ⍞ to your string as character input is not supported in the online platform

Explination

Basically it gets character input and saves as i then sorts i and makes a list of the number of occurances of each unique element in i then it reduces the list with a logical or to check that there are the same number of each unique element and finally checks if there are at least 2 of each unique element.

Feel free to tear into my solution! I need to learn and I am still very new to APL and golfing.

Edit!!!

I am an idiot (as was kindly pointed out in the comments) and forgot to make my program non-deterministic. FAIL.

quack!

rmoro

Posted 2018-03-01T14:02:57.473

Reputation: 131

I cant figure out if I can do an unnamed lambda within a named function. You could ask in the APL orchard. – Laikoni – 2018-03-05T13:47:09.177

0

Jotlin, 116 bytes

{c(it).map({(_,ebb)->ebb}).l{a.none({icmp_2->icmp_2<2||icmp_2!=a[0]||",,,-->>llnnoooaettt<<<!!=[[[000!]]]".l==""})}}

Full program code:

val f: (String)->Boolean =

{c(it).map({(_,ebb)->ebb}).l{a.none({icmp_2->icmp_2<2||icmp_2!=a[0]||",,,-->>llnnoooaettt<<<!!=[[[000!]]]".l==""})}}

val trues = listOf(
        "aaaa",
        "aa!1 1 !a !1",
        "aabbccddeeffgg",
        "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",
        "{c(it).map({(_,ebb)->ebb}).l{a.none({icmp_2->icmp_2<2||icmp_2!=a[0]||\",,,-->>llnnoooaettt<<<!!=[[[000!]]]\".l==\"\"})}}"
)

val falses = listOf(
        "a",
        "abbaabb",
        "abc",
        "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>"
)

for (t in trues) {
    val r1 = f(t)
    if (!r1) throw AssertionError("'$t' gave the wrong value, ($r1 != true)")
}
for (t in falses) {
    val r1 = f(t)
    if (r1) throw AssertionError("'$t' gave the wrong value ($r1 != false)")
}

Uses a check for lowercase equaling an empty string to get rid of extra characters.

jrtapsell

Posted 2018-03-01T14:02:57.473

Reputation: 915

0

Whispers v2, 1750* 1305 bytes

> 1
> InputAll
>> ∪2
>> #2
>> #3
>> 4÷5
>> ⌊6⌋
>> L⋅7
>> Each 8 3
>> 9ᴺ
>> 2ᴺ
>> 10=11
>> 6>1
>> 12⋅13
>> Output 14














           ###########################00000000000000000000000000001111111111111111111112222222222222222222222222333333333333333333333333334444444444444444444444444445555555555555555555555555555666666666666666666666666666777777777777777777777777777788888888888888888888888888889999999999999999999999999999============================AAAAAAAAAAAAAAAAAAAAAAAAAAAAEEEEEEEEEEEEEEEEEEEEEEEEEEEEIIIIIIIIIIIIIIIIIIIIIIIIIIIILLLLLLLLLLLLLLLLLLLLLLLLLLLLOOOOOOOOOOOOOOOOOOOOOOOOOOOOaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccchhhhhhhhhhhhhhhhhhhhhhhhhhhhlllllllllllllllllllllllllllnnnnnnnnnnnnnnnnnnnnnnnnnnnnpppppppppppppppppppppppppppttttttttttttttttttttttttttuuuuuuuuuuuuuuuuuuuuuuuuuu÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷ᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺᴺ∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪∪⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌊⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋⌋

Try it online!

* Golfs made while explaining it. You can see the original here

Interesting task, fairly boring restriction.

Unfortunately, due to the fact that every line must start with either >> or >, this forces the number of each character to be disproportionately large. Luckily, Whispers ignores every line that doesn't match one of its regexes, all of which require the line to begin with >. Therefore we just have a large character dump at the end of the program. In addition to this, Whispers, being designed for mathematical operations, struggles when applied to a question. Overall, this means that the task is interesting to attempt, but the source code requirements are a bit boring.

If we strip all the unnecessary characters from the program, we end up with

> 1
> InputAll
>> ∪2
>> #2
>> #3
>> 4÷5
>> ⌊6⌋
>> L⋅7
>> Each 8 3
>> 9ᴺ
>> 2ᴺ
>> 10=11
>> 6>1
>> 12⋅13
>> Output 14

Try it online!

which is the part of the code we're actually interested in.

How that works

Here we conduct two key tests: the count of each is the same and the counts are greater than 1. However, the code for these two tests are shared between them, so a complete walkthrough of the program is a more effective method of explaining this.

We start with the shared code:

> InputAll
>> ∪2
>> #2
>> #3
>> 4÷5

Here, we take the input and store it on line 2 (> InputAll). We then create a nique version of that string (i.e. the input without duplicate characters). With our next two lines, we take the length of the untouched input (>> #2) and the number of unique characters in the input (>> #3). Finally, we divide the former by the latter.

Why? Let's have a look at the two inputs of aabbcc and abbaabb. With the first string, the division becomes 6÷3 = 2, and the second results in 7÷2 = 3.5. For non-discriminating strings, the result of this division is a) An integer and b) Greater than 1. Unfortunately, this also applies to some non-discriminating strings, such as abbccc, so we have to perform one more test.

>> ⌊6⌋
>> L⋅7
>> Each 8 3
>> 9ᴺ
>> 2ᴺ
>> 10=11

Note: line 6 is the result of the division.

First, we take the floor of the division, because Python strings cannot be repeated a float number of times. Then we reach our Each statement:

>> L⋅7
>> Each 8 3

3 is a reference to line 3, which contains our deduplicated input characters, so we map line 8 (>> L⋅7) over this list. Line 8 multiplies the character being iterated over by the floor of our division (>> ⌊6⌋). This creates an array of the deduplicated characters, repeated n times.

The results from our two previous strings, aabbcc and abbaabb, along with abcabc, would be aabbcc, aaabbb and aabbcc respectively. We can see that the first and last two are identical to their inputs, just with the letters shuffled around, whereas the middle one isn't (it has one less b). Therefore, we simply sort both the input and this new string, before comparing for equality:

>> 9ᴺ
>> 2ᴺ
>> 10=11

Finally, we need to check that the number of characters in the string is 2 or greater. Luckily, the division we performed earlier will always result in a value greater than 1 if a character repeats more than once, meaning we just need to assert that line 6 is greater than 1:

>> 6>1

Now we have two booleans, one for each test. They both need to be true, so we perform a logical AND (boolean multiplication) with >> 12⋅13, before finally outputting the final result.

user80418

Posted 2018-03-01T14:02:57.473

Reputation:

0

Pascal (FPC), 288 280 bytes

35 distinct characters * 8 times

var c:char;g:array[0..222]of byte;w,v:byte;begin;repeat read(c);inc(g[ord(c)]);v:=g[ord(c)]until eof;foR w:=0to 222do if(g[w]>=2)and(g[w]<>v)oR(v<2)then v:=0;wRitE(v>0)End.,,,,,,,.....0000::<<<<<<====>>>>>[[[]]]abbbbbccddffffgghhhhhhiiilllllllnnppppppptuuuuuuuvwwwyyyyyEEEEEERRRRR

Try it online!

-8 bytes by kicking out y from the program! (See below)
Now for the reduced range of characters, but still covering printable ASCII.

This is the basic program:

var c:char;g:array[0..255]of byte;w,v,y:byte;begin;repeat read(c);inc(g[ord(c)]);v:=g[ord(c)]until eof;for w:=0to 255do if(g[w]>=2)and(g[w]<>v)or(v<2)then y:=2;write(y=0)end.

The task was juggling between number of spaces, ;s and ()s and it seems that less than 8 characters on all of them is impossible.
There are more than 8 of es and rs in the basic program, so I introduced some capital letters or I would need to increase number of occurences of other characters.

AlexRacer

Posted 2018-03-01T14:02:57.473

Reputation: 979

0

Wolfram Language (Mathematica), 57 54 bytes

(Apply[Equal]@#)~And~(1<Last[#])&@*Counts

yEqd1<L*Co&

Try it online!

attinat

Posted 2018-03-01T14:02:57.473

Reputation: 3 495