18
Based on this question from Code Review
Given a non-empty string of printable ASCII characters, output the second non-repeating character. For example, for input DEFD
, output F
.
Input
- A single string, in any suitable format.
Output
- The second character that doesn't repeat, when reading left-to-right, again in a suitable format.
- The output character is case-insensitive.
- If no such character exists (e.g., all characters repeat), output an empty string.
Rules
- The algorithm should ignore case. That is,
D
andd
count as the same character. - Either a full program or a function are acceptable.
- The input string will be guaranteed non-empty (i.e., at least one character in length).
- The input string is ASCII. Any valid character could repeat, not just alphanumeric (this includes spaces).
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
Examples
Input is on first line, output is on second line.
DEFD
F
FEED
D
This is an example input sentence.
x
...,,,..,,!@
@
ABCDefgHijklMNOPqrsTuVWxyz
B
AAAAAABBBBB
Thisxthis
This this.
.
8If it wasn't case-insensitive, I'd consider doing it in Forth. String operations suck in that language, though. – mbomb007 – 2016-07-01T17:05:36.973
What if my language doesn't support lowercase letters? – Adám – 2016-07-03T10:32:10.877
@Adám Does it utilize a different code page? How would it normally input an ASCII string if it doesn't support lowercase letters? – AdmBorkBork – 2016-07-04T13:37:34.237
2The system I had in mind had 7-bit code page; a modified standard code page where uppercase letters occupy the lowercase positions, and the uppercase positions were used for glyphs. This was done on old APL systems so that one could use Shift to access APL glyphs, while unshifted letters were classic coding-style capitals. – Adám – 2016-07-04T13:46:25.393