Odd'em out: letters

11

0

Objective

Write a program or function (or equivalent) that sorts out and returns the odd letter in the matrix of random size.

Details

You will be passed a matrix (as a string) as input of random dimensions such as this.

bbbbbbbbbb
bbbbbdbbbb
bbbbbbbbbb
bbbbbbbbbb
bbbbbbbbbb

Your job is to find the letter that doesn't match the rest (in this case, it is d, found at line 2, col 6) and to return that letter as output. The matrix will consist of letters A-Z, a-z, newlines (\n, only on ends of rows) and have dimensions ranging from 5x5 to 10x10 (25-100 letters).

Standard loopholes apply. This is a code golf challenge; entry with code of least bytes wins.

Input

Input will be passed in through standard input as a string if it is a program or as an argument if a function (or similar).

Output

A single character that is the "odd" in the matrix or None, nil, NUL, or the string "None" if there is no "odd" character.

More Examples

AAAAAAA
AAAAAAA
AAAAAAA
AAAIAAA
AAAAAAA

Answer: I

vvqvvvvvvv
vvvvvvvvvv
vvvvvvvvvv
vvvvvvvvvv
vvvvvvvvvv

Answer: q

puuuuuuuu
uuuuuuuuu
uuuuuuuuu
uuuuuuuuu
uuuuuuuuu
uuuuuuuuu
uuuuuuuuu
uuuuuuuuu
uuuuuuuuu
uuuuuuuuu

Answer: p

Generator

Here is a random matrix generator written in Python that you can use to test your program. Note: There is a slight chance that it could make a mistake and not put in an odd letter.

Instructions

1. Copy this code into a file called `matrix_gen.py`.
2. Run it with `python matrix_gen.py`.

---

from random import randint

rows = randint(5,10)
cols = randint(5,10)

charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
neg = charset[randint(0,51)]
pos = charset[randint(0,51)]
p_used = 0

comp = 0
matrix = ""

while comp < rows:
  row = ""
  while len(row) < cols:
    if not p_used and not randint(0,10):
      p_used = 1
      row = row + pos
    else:
      row = row + neg
  row = row + "\n"
  matrix = matrix + row
  comp += 1

print matrix[:-1]

juniorRubyist

Posted 2017-11-28T06:57:23.117

Reputation: 875

1Here is a literal translation of your Python code into JS. – Arnauld – 2017-11-28T10:09:19.337

1@juniorRubyist "removing the bonus" isn't the same as "making the bonus mandatory". By moving the part that was optional so far into the requirements of the challenge, you've invalidated a large part of the existing answers. – Martin Ender – 2017-11-30T08:50:36.863

Answers

13

Python 3, 27 bytes

lambda x:min(x,key=x.count)

Try it online!

Mr. Xcoder

Posted 2017-11-28T06:57:23.117

Reputation: 39 774

6

J, 12 10 7 bytes

-.}./.~

Try it online!

    /.~        Group identical items together
  }.           Remove one item from each group
-.             Remove the rest from the input

10 byte version

-._1 1{\:~

hisss...

       \:~        Sort down
  _1 1{           Take the last character (which is a newline) and the second one.
-.                Remove those from the input

FrownyFrog

Posted 2017-11-28T06:57:23.117

Reputation: 3 112

2@ FrownyFrog This is a clever way to find the odd character – Galen Ivanov – 2017-11-28T08:25:59.347

can’t decide what i like better: this lovely hook or your dragon joke... – Jonah – 2017-11-28T13:46:36.403

4

Brachylog, 8 4 bytes

oḅ∋≠

Try it online!

Explanation

I haven't used Brachylog before, so this may not be optimal.

oḅ∋≠  Input is a string.
o     Sort the input.
 ḅ    Split it into blocks of equal elements.
  ∋   There is a block
   ≠  whose elements are all different.
      That block is the output.

Zgarb

Posted 2017-11-28T06:57:23.117

Reputation: 39 083

That use of ∋≠ after to get the results of length 1 is very clever. You should definitely post it in the Brachylog tips question.

– Fatalize – 2017-11-30T07:28:23.003

@Fatalize Thanks, I added the tip. – Zgarb – 2017-11-30T08:28:53.683

3

05AB1E,  4  2 bytes

Saved 2 bytes thanks to Adnan

.m

Try it online!

Explanation

.m   # push a list of the least frequent character(s) in input

Emigna

Posted 2017-11-28T06:57:23.117

Reputation: 50 798

Do you need to remove the newlines, seeing as we're guaranteed the input will be at least 5 lines long? – Shaggy – 2017-11-28T08:19:21.490

@Shaggy: No I don't. That was to handle 2x2 matrices. I missed the part about 5x5 and up. Thanks! – Emigna – 2017-11-28T08:44:50.623

It has to return nil if it doesn't have an "odd one out" doesn't it? – Magic Octopus Urn – 2017-11-30T00:49:46.160

@MagicOctopusUrn That part was optional when this answer was posted. I guess that change invalidates most answers now... – Martin Ender – 2017-11-30T08:49:32.773

3

K (oK), 7 6 bytes

Solution

*<#:'=

Try it online!

Example:

*<#:'="vvqvvvvvvv\nvvvvvvvvvv\nvvvvvvvvvv\nvvvvvvvvvv\nvvvvvvvvvv"
"q"

Explanation:

Found a slightly shorter approach: Evaluated right-to-left:

*<#:'= / the solution
     = / group matching items together
  #:'  / count (#:) each (')
 <     / sort ascending
*      / take the first one

Notes:

Whilst I'm expecting the bonus aspect of this challenge to get dropped, this solution will return the newline character \n if there is no odd character:

*<#:'="vvvvvvvvvv\nvvvvvvvvvv\nvvvvvvvvvv\nvvvvvvvvvv\nvvvvvvvvvv"
"\n"

streetster

Posted 2017-11-28T06:57:23.117

Reputation: 3 635

3

C (gcc), 93 92 90 66 62 Bytes

Much shorter as a function

t;f(char*p){for(t=*p;*p;)t^*p++?putchar(*p^*--p?*p:t),*p=0:0;}

Try it online!

test code

main()
{
    char s[99];
    for(;gets(s);)f(s);
}

old version is a program

C 86 Bytes

char*p;s[9];main(t){for(;p=gets(s);)for(t=*p;*p;)t^*p++?putchar(*p^*--p?*p:t),*p=0:0;}

Outputs the odd character, or nothing. run like this;

C:\eng\golf>python matrix_gen.py | a.exe
X
C:\eng\golf>python matrix_gen.py | a.exe
G
C:\eng\golf>python matrix_gen.py | a.exe
x
C:\eng\golf>python matrix_gen.py | a.exe

C:\eng\golf>python matrix_gen.py | a.exe
J

cleblanc

Posted 2017-11-28T06:57:23.117

Reputation: 3 360

I don't know that it is quite fair to put the gets() into the test driver as it is sanitizing the input by removing the \n chars for you. That's doing some work so that your function is not working on the original input. – Michael Dorgan – 2017-11-29T23:10:48.460

@MichaelDorgan It works with the piped input from the python script as well as input on TIO. Others simply hard-coded the input which didn't seem with the spirit of the challenge. – cleblanc – 2017-11-30T13:45:57.343

3

Prolog (SWI), 46 bytes

p(L):-select(X,L,Y),\+member(X,Y),writef([X]).

Try it online!

Or if the standard true output from prolog queries is not okay:

Prolog (SWI), 48 bytes

Z*L:-select(X,L,Y),\+member(X,Y),char_code(Z,X).

Try it online!

Explanation

Find the first element X in the input  
that when removed, results in output  
that does not contain X

then depending on the version above either:  
print X as a character  
or  
return X as an atom

Emigna

Posted 2017-11-28T06:57:23.117

Reputation: 50 798

2

C, 94 bytes

Return by pointer. If none, return \0.

This will cause memory leaks. Assuming int is 4 bytes.

*t;f(c,p,i)char*c,*p;{t=calloc(64,8);for(*p=-1;*c;c++)t[*c]--;for(i=0;++i<128;)!~t[i]?*p=i:0;}

Try it online!

Colera Su

Posted 2017-11-28T06:57:23.117

Reputation: 2 291

2Functions must be reusable. – Shaggy – 2017-11-28T08:21:09.427

@Shaggy Actually, I don't know how to interpret that rule, as I see some (other) users explicitly know about that rule but still post such answers like this one. – user202729 – 2017-11-28T09:44:20.040

2@user202729, just because others do it doesn't mean it's right ;) If you spot such solutions, best to point it out to them. – Shaggy – 2017-11-28T09:46:44.223

@Shaggy Well, I explicitly pointed the rule but that user said "the rule explicitly says that this one is valid". I don't know what to say. | In this case the function require the array t be zeroed before calling each time not the first time. – user202729 – 2017-11-28T09:50:04.527

@Shaggy Thanks, fixed. – Colera Su – 2017-11-28T11:05:08.613

2

Mathematica, 27 bytes

Last@*Keys@*CharacterCounts

Try it online!

-1 byte from Martin Ender

J42161217

Posted 2017-11-28T06:57:23.117

Reputation: 15 931

2

Retina, 13 bytes

s(O`.
(.)\1+

Try it online!

Explanation

s(O`.

Sort all characters.

(.)\1+

Remove any characters that appear at least twice.

Martin Ender

Posted 2017-11-28T06:57:23.117

Reputation: 184 808

2

Bash, 15 20 bytes

fold -1|sort|uniq -u

Try it online!

Explanation: folds the input to 1 character per line, sorts it into groups of matching letters, then prints only lines that are unique.

Thanks @Nahuel Fouilleul for catching and helping fix a problem with this approach.

Justin Mariner

Posted 2017-11-28T06:57:23.117

Reputation: 4 746

doesn't work if the odd character is the second or the penuitlimate – Nahuel Fouilleul – 2017-11-29T14:45:17.683

@NahuelFouilleul Good catch... I'm unsure of how to fix that at the moment, but I will fix or delete later unless you had a suggested fix. – Justin Mariner – 2017-11-29T14:50:45.067

it can be simply fix with |sort| but there may be a better solution – Nahuel Fouilleul – 2017-11-29T15:38:38.083

also found a solution with grep but it's longer grep -oP '^(.)((?=(?!\1).){2}|.*\K(?!\1).)' – Nahuel Fouilleul – 2017-11-29T16:17:55.827

@NahuelFouilleul I'm going with the sort fix, thanks. You could always post that grep answer as your own if you want to, though. – Justin Mariner – 2017-11-29T19:56:03.373

2

Husk, 2 bytes

◄=

Try it online!

This is a function taking a string as input and returning a character. It takes the minimum of the input string when comparing characters for equality (i.e. it returns the character that is equal to the least number of other characters).

Leo

Posted 2017-11-28T06:57:23.117

Reputation: 8 482

1

JavaScript (ES6), 37 bytes

Returns null if there's no odd letter.

s=>s.match(`[^
${s.match(/(.)\1/)}]`)

Test cases

let f =

s=>s.match(`[^
${s.match(/(.)\1/)}]`)

console.log(f(
  'bbbbbbbbbb\n' +
  'bbbbbdbbbb\n' +
  'bbbbbbbbbb\n' +
  'bbbbbbbbbb\n' +
  'bbbbbbbbbb'
))

console.log(f(
  'AAAAAAA\n' +
  'AAAAAAA\n' +
  'AAAAAAA\n' +
  'AAAIAAA\n' +
  'AAAAAAA'
))

console.log(f(
  'vvqvvvvvvv\n' +
  'vvvvvvvvvv\n' +
  'vvvvvvvvvv\n' +
  'vvvvvvvvvv\n' +
  'vvvvvvvvvv'
))

console.log(f(
  'puuuuuuuu\n' +
  'uuuuuuuuu\n' +
  'uuuuuuuuu\n' +
  'uuuuuuuuu\n' +
  'uuuuuuuuu\n' +
  'uuuuuuuuu\n' +
  'uuuuuuuuu\n' +
  'uuuuuuuuu\n' +
  'uuuuuuuuu\n' +
  'uuuuuuuuu'
))

console.log(f(
  'AAAAA\n' +
  'AAAAA\n' +
  'AAAAA\n' +
  'AAAAA\n' +
  'AAAAA'
))

Arnauld

Posted 2017-11-28T06:57:23.117

Reputation: 111 334

1

Jelly, 4 bytes

ċ@ÐṂ

Try it online!

Return \n (a single newline) in case there is no odd character. Obviously \n is not a printable character.

Coincidentally this is exactly the same algorithm as Mr.Xcoder Python answer. (I came up with it independently)

Explanation:

  ÐṂ    Ṃinimum value by...
ċ@      ċount. (the `@` switch the left and right arguments of `ċ`)

That works because in a m×n matrix:

  • If there exists odd character: There are m-1 newlines, 1 odd characters and m×n-1 normal character, and 1 < m-1 < m×n-1 because 5 ≤ m, n ≤ 10.
  • If there doesn't exist odd character: There are m-1 newlines and m×n normal character, and m-1 < m×n.

user202729

Posted 2017-11-28T06:57:23.117

Reputation: 14 620

1

Pyth, 4 bytes

ho/Q

Try it here!

Mr. Xcoder

Posted 2017-11-28T06:57:23.117

Reputation: 39 774

.m/Q is 4 bytes as well – Dave – 2017-11-30T12:56:16.367

@Dave That outputs as a list though, I chose this because it was more elegant ;-) – Mr. Xcoder – 2017-11-30T12:57:30.133

1

Japt, 6 bytes

Takes input as a multi-line string and outputs a single character string, or an empty string if there's no solution.

k@èX É

Try it


Explanation

Remove the characters that return truthy (k) when passed through a function (@) that counts (è) the occurrences of the current element (X) in the input and subtracts 1 (É).

Shaggy

Posted 2017-11-28T06:57:23.117

Reputation: 24 623

1

Perl 5, 17 + 3 (-00p) -25% = 15 bytes

/(.)\1/;s/
|$1//g

try it online

Nahuel Fouilleul

Posted 2017-11-28T06:57:23.117

Reputation: 5 582

1

Octave, 26 25 bytes

1 byte saved thanks to @Giuseppe

@(x)x(sum(x(:)==x(:)')<2)

Anonymous function that takes a 2D char array as input, and outputs either the odd letter or an empty string if it doesn't exist.

Try it online!

Luis Mendo

Posted 2017-11-28T06:57:23.117

Reputation: 87 464

1

Haskell, 33 * 0.75 = 24.75 bytes

f s=[c|[c]<-(`filter`s).(==)<$>s]

Returns an empty list if there's no odd character.

Try it online!

For each char c in the matrix (given as a string s) make a string of all chars in s that are equal to c and keep those of length 1.

nimi

Posted 2017-11-28T06:57:23.117

Reputation: 34 639

1

Common Lisp, 47 bytes

(lambda(s)(find-if(lambda(x)(=(count x s)1))s))

Try it online!

Returns the odd letter or NIL if it does not exist.

Renzo

Posted 2017-11-28T06:57:23.117

Reputation: 2 260

1

C (gcc), 91 86 82 79 71 bytes

f(char*s){for(;*++s==10?s+=2:0,*s;)if(*s^s[-1])return*s^s[1]?*s:s[-1];}

Try it online!

  • Thanks to Gastropner for the xor and ? tricks (-3 bytes)
  • Reworked the compare version to fix bugs and used Gastropner magic from comments.

Explanation:

Compare current and previous char while skipping newlines. If different, compare to next char. This tells us if we return current or previous char. The function returns the "odd" char value if it exists or 0 if the array is not odd. We get away with the "next" char check because there is always a newline before the \0 char. If there is no odd char, we intrinsically return the \0 from the for loop.


Older, sexier xor code Explanation:

Make a running xor mask of the next 3 string values. If they are all the same, then the value will be equal to any of the three. If they are different, then the 2 identical will cancel each other out leaving the unique.

Must factor /n before the xor or it gets messy. Also have to check 2 chars for inequality in case s[0] is the odd value. This costs the extra || check.

v;f(char*s){while(s[3]){s[2]==10?s+=3:0;v=*s^s[1]^s[2];if(v^‌​*s++||v^*s)break;}}

Michael Dorgan

Posted 2017-11-28T06:57:23.117

Reputation: 221

79 with a few tweaks. The fall-through return does not agree with my compiler, so only tested on TIO: v;f(char*s){while(s[3]){s[2]==10?s+=3:0;v=*s^s[1]^s[2];if(v^*s++||v^*s)break;}} – gastropner – 2017-11-29T22:12:20.153

For the crap I am writing, TIO is what I stick with. Thanks! – Michael Dorgan – 2017-11-29T22:59:45.763

Rearranging some expressions allows another -2 for 77: v;f(char*s){while(s[2]==10?s+=3:0,v=*s^s[1]^s[2],s[3])if(v^*s++||v^*s)break;}

However your winning horse is the other one, if you fiddle with it a bit, for 73: v;f(char*s){for(v=-1;*++s==10?s+=2,v--:0,*s;v=0)if(*s^s[-1])return s[v];} – gastropner – 2017-11-29T23:36:18.783

Yeah, but the xor seems so sexy. :) – Michael Dorgan – 2017-11-29T23:39:42.183

Suggest s+=*++s-10?0:2 instead of *++s==10?s+=2:0 – ceilingcat – 2019-08-02T20:33:54.910

1

Matlab, 25 Bytes

a=input('');a(a~=mode(a))

The input "a" where "a" isn't the mode of "a". Outputs empty array for no oddball.

Jeremiah Peek

Posted 2017-11-28T06:57:23.117

Reputation: 11

1

C# (.NET Core), 54 bytes

i=>i.GroupBy(x=>x).FirstOrDefault(g=>g.Count()<2)?.Key

Try it online!

Wakawakamush

Posted 2017-11-28T06:57:23.117

Reputation: 121

You are right, my answer was wrong. I have deleted it. But you are missing the 18 bytes from the using statement in the byte count. – raznagul – 2017-11-29T13:03:15.303

0

Alice, 16 * 75% = 12 bytes

/-.nDo&
\i..*N@/

Try it online!

Outputs Jabberwocky if there is no duplicate character.

Explanation

/...@
\.../

This is a framework for linear programs that operate entirely in Ordinal (string processing mode). The actual code is executed in a zigzag manner and unfolds to:

i..DN&-o

i   Read all input.
..  Make two copies.
D   Deduplicate one copy, giving only the two letters and a linefeed.
N   Multiset difference. Removes one copy of each letter and one linefeed.
    Therefore it drops the unique letter.
&-  Fold substring removal over this new string. This essentially removes
    all copies of the repeated letter and all linefeeds from the input,
    leaving only the unique letter.
.   Duplicate.
n   Logical NOT. Turns empty strings into "Jabberwocky" and everything else
    into an empty string.
*   Concatenate to the previous result.
o   Print the unique letter or "Jabberwocky".

Instead of &-, we could also use ey (transliteration to an empty string). Alternatively, by spending one more character on stack manipulation, we could also deduplicate the input which lets us remove the unwanted characters with N, but it's still the same byte count:

i.D.QXN.n*o@

Alice, 13 bytes

/N.-D@
\i&.o/

Try it online!

This is the solution without the bonus, it's simply missing the .n*.

Martin Ender

Posted 2017-11-28T06:57:23.117

Reputation: 184 808

0

Retina, 22 bytes

!`(.)(?!.*\1)(?<!\1.+)

Try it online! Only requires height and width of at least 3, rather than 5.

Neil

Posted 2017-11-28T06:57:23.117

Reputation: 95 035

0

APL+WIN, 16 bytes

(1=+/a∘.=a)/a←,⎕

Prompts for screen input and either outputs odd letter or nothing if there is no odd letter

Graham

Posted 2017-11-28T06:57:23.117

Reputation: 3 184

a/⍨1=+/a∘.=a←,⎕ for a byte – Uriel – 2017-11-28T15:16:09.557

@Uriel Thanks but I am afraid the operator ⍨ is not available in my old APL+WIN version 5 :( – Graham – 2017-11-28T15:35:26.463

0

PowerShell, 39 bytes

([char[]]"$args"|group|sort c*)[0].Name

Try it online!

Takes input as a string with newlines (as specified in the challenge), converts it to a char-array. We then Group-Object the characters, so that characters are grouped together by their names, then sort based on the count. This ensures that the lonely character is first, so we take the [0] index and output its .Name.

If newline is acceptable for "nothing" then this qualifies for the bonus.

AdmBorkBork

Posted 2017-11-28T06:57:23.117

Reputation: 41 581

I was hoping sort c*)[0] could be shortened, but what I came up with was the same number of bytes, ? c* -eq 1). – root – 2017-11-28T21:03:26.493

can be shortened by removing the double quotes around $args. Also it is more accurate to do ([char[]]$args|group|? c* -eq 1).Name as it will accurately return null when there is no odd character (instead of new line). However in terms of bytes this still won't bring you below 37. – cogumel0 – 2017-11-29T10:15:38.433

@cogumel0 Doesn't run without double quotes. – root – 2017-11-29T13:11:25.633

@root you're correct. However to pass one of the requirements (A single character that is the "odd" in the matrix or None, nil, NUL, or the string "None" if there is no "odd" character.) it should still be changed. Newline is not part of the acceptable answers. – cogumel0 – 2017-11-29T14:12:46.467

@cogumel0 Ah, the challenge was changed since I posted my answer. The "None / nil / whatever" used to just be a bonus rather than mandatory. I'm going to keep my answer as-is. – AdmBorkBork – 2017-11-29T14:16:55.500

@AdmBorkBork thx for the explanation, now it's clear why your solution was posted that way. – cogumel0 – 2017-11-29T14:20:13.787

0

Perl 6,  27  24 -25% = 18 bytes

*.comb.Bag.min(*.value).key

Test it

{%(.comb.Bag.invert){1}}

Test it

This will return an undefined value when given an input that doesn't have an odd character out.

Expanded:

{  # bare block lambda with implicit parameter 「$_」

  %(        # coerce into a Hash

    .comb   # split the input into graphemes (implicit method call on 「$_」)
    .Bag    # turn into a weighted Set
    .invert # invert that (swap keys for values) returns a sequence

  ){ 1 }    # get the character that only occurs once
}

Brad Gilbert b2gills

Posted 2017-11-28T06:57:23.117

Reputation: 12 713

0

Java (OpenJDK 8), 93 98 108 bytes

a->{char[]r=a.toCharArray();java.util.Arrays.sort(r);return String.valueOf(r).replaceAll("(.)\\1+|\\n","");}

Try it online!

The input is converted to an array of characters, which is then sorted. We have to make a string again so we can replace all occurences matching the regex.

I first tried to simply do it with one "replaceAll" but I did not manage to create a regex that would delete the first a in "abaa" for example.

Luca H

Posted 2017-11-28T06:57:23.117

Reputation: 163

I think what you're looking for in the first two statements is char[] r = a.toCharArray(); Arrays.sort(r); a = new String(r);; the existing code doesn't actually do anything to a. This should fix your solution for cases like abaa. – Jakob – 2017-11-29T03:00:45.117

@Jakob the code does something. It converts a string to a char array and sorts it, then it changes it back to a string and replaces everything appearing more than once. If I managed to create a regex matching cases like abaaI could leave out the part converting the string to an array etc. – Luca H – 2017-11-29T07:28:23.583

Nope. The first statement sorts a copy of the string's character array and discards it, and the second statement passes a through String.valueOf(Object), which leaves it unchanged. – Jakob – 2017-11-29T17:37:38.673

@Jakob I don't have any words for this... I am sure I tested it and it was working in my tests but I simply feel stupid now, of course it discards the copy... Thank you – Luca H – 2017-11-30T10:23:00.417

@Jakob fixed, but it costs 5 bytes... I should stop trying to submit Java solutions, in part because I seem to be an idiot :D – Luca H – 2017-11-30T10:32:45.300

No, by all means keep golfing! The more you practice, the better you'll get. – Jakob – 2017-11-30T16:13:48.170

One more thing: lambda solutions can't use imports without including them in the byte count, so you'll have to either add in an import for Arrays or use the fully-qualified name in your lambda. – Jakob – 2017-11-30T16:15:49.380

@Jakob oh man, didn't think about that... plus another 10 bytes ^^ but hey, at least it's valid now :P and thank you for encouraging – Luca H – 2017-12-01T07:48:39.917

0

R, 61 bytes

cat(names(sort(table(unlist(strsplit(scan(,""),""))),T))[-1])

Try it online!

Takes input from stdin, outputs the letter (or the empty string) to stdout.

Explanation:

x=scan(,"")                     # read in input
x=unlist(strsplit(x,""))        # split into characters
x=table(x)                      # tabulate character counts
x=sort(x,T)                     # sort into decreasing order
x=names(x)                      # get the names (the characters)
x=x[-1]                         # remove the first element
cat(x)                          # print out the remaining letter (or nothing if none exist)

Giuseppe

Posted 2017-11-28T06:57:23.117

Reputation: 21 077

0

Brainfuck, 125 bytes

,[----------[>],]<[->+<]<<[[->->+<<]>[>[->-<<<+>>]>[,<<,>>]<<<[->+<]>[->+<]<]>[-<<+>>]>[-<+>]<<<<]>>>>[<]<++++++++++.

Try It Online

Prints the letter of the matrix if there is no odd one out

Jo King

Posted 2017-11-28T06:57:23.117

Reputation: 38 234

0

Java 8, 85 bytes

This is a lambda from String to String (e.g. Function<String, String>). It's essentially a copy of Luca's solution, but I've pared down the string sorting a bit.

s->new String(s.chars().sorted().toArray(),0,s.length()).replaceAll("(.)\\1+|\\n","")

Try It Online

Jakob

Posted 2017-11-28T06:57:23.117

Reputation: 2 428

0

PHP, 74 bytes

normal program, 57 bytes:

<?=chr(array_search(min($a=count_chars($argv[1],1)),$a));

(prints a newline if the is no odd character)

modified program, 74 bytes:

<?=count($a=count_chars($argv[1],1))<4?None:chr(array_search(min($a),$a));

(assumes Windows linebreaks; replace 4 with 3 for input with Unix linebreaks)

Run with php <scriptname> '<matrix>' or try then online.

Titus

Posted 2017-11-28T06:57:23.117

Reputation: 13 814

0

Ruby, 33 bytes

->s{s.chars.min_by{|c|s.count c}}

Try it online!

Uses the same idea as Mr. Xcoder's great Python answer.

Justin Mariner

Posted 2017-11-28T06:57:23.117

Reputation: 4 746