Inspired by this comment chain...
I wanna
enklact
my way out of this challenge but I can't...@ETHproductions to enklact (v): to implement a lookup table using a subsection consisting of unique elements.
Enklacting is a very useful way to compress a lookup table. For example, let's say you had the following list of colors:
red
green
blue
yellow
purple
orange
If you want to be able to take a color as input and return it's index in this list, there's obviously the straightforward way:
["red", "green", "blue", "yellow", "purple", "orange"].index(input())
But there's a way we could do this in way less bytes:
"rgbypo".index(input()[0])
This works because the first (or 0'th) index of each string is unique. This example is obvious, but sometimes it's a little bit harder. What if we wanted to make a lookup table for this list?
Sweet Onion Chicken Teriyaki
Oven Roasted Chicken
Turkey Breast
Italian BMT
Tuna
Black Forest Ham
Meatball Marinara
In this case, we can't do this:
"SOTITBM".index(input()[0])
because there are two different inputs that start with a 'T'
, namely "Tuna" and "Turkey". We must look at a different index. If you look at the 4th index of each string, you'll notice that they are all unique. So we can do this...
"enklact".index(input()[3])
In this case, the "enklaction string" is "enklact".
That leads us to today's challenge...
Given a list of strings, return any valid enklaction string. Or in other words, given a list of strings, return any new string where each letter is unique, and the string is formed by joining the i'th letter of each string.
If there is no valid enklaction string, your submission must return an empty string or a consistent falsy value instead. As usual, either functions or full programs are allowed, and the input/output formats are permissive (within reason).
Each string will only contain printable ASCII, and this challenge is case sensitive.
This is code-golf, so try to write the shortest program possible in your language of choice!
Test cases
Input:
Programming
Puzzles
Code
Golf
Output (any one of these):
"ozdl"
"gzef"
Input:
the quick
brown fox
jumped over
lazy dogs
Output:
"tbjl"
"hrua"
"eomz"
" wpy"
"qne "
"if o"
"kxvs"
Note that "u dd" and "coog" are not valid.
Input:
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Output:
""
Input:
AbC
aBc
bbC
Output:
"Aab"
Input:
@#$%^_
Hello_World
How are you?
Output:
"#eo"
"$lw"
"%l "
"^oa"
Input:
a
ab
ac
Output:
""