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