| Bytes | Lang | Time | Link |
|---|---|---|---|
| 033 | Curry PAKCS | 240812T151639Z | Wheat Wi |
| 047 | Haskell | 240812T134834Z | Wheat Wi |
| 022 | Haskell + hgl | 240812T134722Z | Wheat Wi |
| 034 | Perl 6 | 190512T015850Z | bb94 |
| 109 | Java 7 | 161116T205501Z | Poke |
| 056 | Mathematica | 161118T155133Z | Kelly Lo |
| 056 | Octave | 161116T171906Z | Stewie G |
| 006 | Jelly | 161116T165419Z | Dennis |
| nan | Java 8 | 161202T174159Z | Xanderha |
| 292 | Racket | 161118T173200Z | rnso |
| nan | Perl | 161116T174236Z | Gabriel |
| 175 | VBA | 161118T150521Z | user3819 |
| 111 | Bash | 161117T220937Z | zeppelin |
| 061 | Haskell | 161118T091106Z | Angs |
| 015 | Pushy | 161117T224102Z | FlipTack |
| 046 | Python 2 | 161116T181653Z | Dennis |
| 041 | Perl | 161116T182514Z | Dada |
| 071 | PHP | 161117T155017Z | Titus |
| 092 | C# | 161116T194102Z | Yodle |
| 036 | Retina | 161116T170610Z | mbomb007 |
| 067 | PowerShell v3+ | 161116T165727Z | AdmBorkB |
| 100 | R | 161117T133423Z | Billywob |
| 066 | Python 2 | 161116T172844Z | Rod |
| 060 | Mathematica | 161117T002947Z | LegionMa |
| 019 | CJam | 161117T123220Z | Martin E |
| 048 | ><> FISH | 161117T094950Z | Teal pel |
| 105 | Java 7 | 161116T164814Z | Geobits |
| 062 | ><> | 161117T015448Z | Brian Gr |
| 080 | Python 2 | 161116T200107Z | ElPedro |
| 041 | JavaScript ES6 | 161116T170932Z | ETHprodu |
| 065 | Python 3 | 161116T181431Z | 0WJYxW9F |
| 062 | Haskell | 161116T185921Z | nimi |
| 063 | Python 2 | 161116T173336Z | DJMcMayh |
| 008 | 05AB1E | 161116T171052Z | Adnan |
| 022 | Actually | 161116T173154Z | user4594 |
| 035 | Cjam | 161116T170003Z | A Simmon |
Curry (PAKCS), 33 bytes
f[_]=1
f(x:l@(succ x:z)++[x])=f l
Takes a string and outputs 1 if the input is a Giza number and nothing otherwise.
Haskell, 48 47 bytes
1 byte saved thanks to @xnor
f x=or[x==[j..pred i]++[i,pred i..j]|i<-x,j<-x]
Improves upon nimi's haskell answer.
Haskell + hgl, 22 bytes
x1(yS$Ng<<x' 1)<δ<bs0
Explanation
This gets the differences between consecutive digits and checks that they consist of some number of 1s followed by the same number of -1s.
bs0convert to base 10, i.e. get the list of digitsδget the differences of consecutive elementsx1is there exactly one parse of ...x' 1get some number of1sNgnegate themySparse that result
On strings, 25 bytes
fe$(nt*^*rv)<cg['1'..'9']
Generates all the giza numbers and checks if the input is among them.
Reflection
- There should be versions of
x_andx'which return the number of symbols parsed rather than the symbols themselves. - There should be a function to take a number and a symbol and parse exactly that many of that symbol.
Perl 6, 43 34 bytes
Thanks to Jo King for -9 bytes.
{!/0/==set comb $_- S:g/..?/1/²:}
Port of Gabriel Benamy's Perl solution.
Java 7, 129 119 109 bytes
boolean e(char[]a){int l=a[0]-1,f=0,b=a.length-1;for(;f<b&&a[f]==++l&a[f++]==a[b--];);return f==b&l==a[b]-1;}
Old Recursive Method, 119
boolean b(char[]a){int b=a.length;return b>1&&a[0]==a[b-1]&a[0]+1==a[1]?b(java.util.Arrays.copyOfRange(a,1,b-1)):b==1;}
-10 bytes thanks to Geobits. We are were tied...
Mathematica, 56 bytes
This is a little shorter:
MatchQ[Differences@IntegerDigits@#,{a:1...,b__}/;b==-a]&
Octave, 56 bytes
@(n)nnz(n)<2||~(abs(diff(+n))-1)&&diff(+n(1:1+end/2))==1
Check out all test cases here.
This would be two less bytes in MATLAB, since diff(n) works for strings. In Octave, you need diff(+n).
Explanation:
@(n) % Anonymous function taking a string `n` as argument
nnz(n)<2 % True if there is only one element in n
|| % Short circuit or operator. Expression will be true if this is true
~(abs(diff(+n))-1) % Takes the absolute value of the difference between adjacent numbers
% which should always be 1. Subtracts 1, to get 0
% and negates it to get 1 (true)
diff(+n(1:1+end/2))==1 % Checks if the difference between the first half of the numbers
% is 1.
% If either the first, or both the second and third argument is true
% then the function will return 1, otherwise 0.
Jelly, 10 7 6 bytes
9ẆŒBḌċ
Generates all 45 Giza numbers numbers, then tests for membership.
Try it online! or see the generated numbers.
How it works
9ẆŒBḌċ Main link. Argument: n
9 Set the return value to 9.
Ẇ Windows; yield all "substrings" of [1, ..., 9].
ŒB Bounce; map each [a, ..., b] to [a, ..., b, ..., a].
Ḍ Undecimal; convert the digit arrays to integers.
ċ Count the number of occurrences of n.
Java 8, 162 + 19 bytes
19 for import java.util.*;
s->{List f=new ArrayList();for(int i=0;i<9;){String l=String.valueOf(++i);for(int j=i;j>0;){f.add(l);String k=String.valueOf(--j);l=k+l+k;}}return f.contains(s);}
Different approach to the other Java answer, I wanted to try and use the method of creating all the possible Timmy numbers and checking to see if our string was contained in them.
Racket 292 bytes
(let*((s(number->string n))(sn string->number)(st string)(lr list-ref)(sl(string->list s))(g(λ(i)(-(sn(st(lr sl(add1 i))))
(sn(st(lr sl i)))))))(cond[(even?(string-length s))#f][(not(equal? s(list->string(reverse sl))))#f][(andmap identity
(for/list((i(floor(/(length sl)2))))(= 1(g i))))]))
Ungolfed:
(define(f n)
(let* ((s (number->string n))
(sn string->number)
(st string)
(lr list-ref)
(sl (string->list s))
(g (λ (i) (- (sn(st(lr sl (add1 i))))
(sn(st(lr sl i)))))))
(cond
[(even? (string-length s))
#f]
[(not(equal? s (list->string (reverse sl))))
#f]
[else
(andmap identity
(for/list ((i (floor(/(length sl)2))))
(= 1 (g i))))]
)))
Testing:
(f 12321)
(f 123321) ; only this should be false;
(f 9)
(f 787)
(f 67876)
(f 4567654)
(f 123454321)
(f 12345654321)
(f 1234567654321)
(f 123456787654321)
(f 12345678987654321)
Output:
#t
#f
#t
#t
#t
#t
#t
#t
#t
#t
#t
Perl, 39 37 42 39 + 1 = 40 bytes
Using a new method, I managed to cut down a huge number of bytes. Run with the -n flag. Accepts input repeatedly at runtime, printing 0 or 1 accordingly.
I had to add 5 bytes because I realized without it, the code worked for inputs such as 1234567900987654321, which is not a Giza number. Since Giza numbers never contain the digit 0 (and all false positives by necessity would contain the digit 0), these 5 bytes account for that.
say!/0/*($_- s/..?/1/gr**2)=~/^(.)\1*$/
Explanation:
say!/0/*($_- s/..?/1/gr**2)=~/^(.)\1*$/ #$_ contains input by default.
!/0/ #Ensure that the initial text doesn't contain the number 0
* #Since both halves of this line return either 0 or 1, multiplying them together only yields 1 if both are true (which we want).
s/ / /gr #Perform a substitution regex on $_ (see below)
#/g means keep replacing, /r means don't modify original string; return the result instead
..? #Replace 1 or 2 characters (2, if possible)...
1 #...with the number 1
**2 #Square this number...
($_- ) #...and subtract it from the input
=~ #Do a regex match on the result
/^ $/ #Make sure the regex matches the WHOLE string
(.) #Match any character...
\1* #...followed by itself 0 or more times
say #Finally, output the result of the whole line of code.
The purpose of the substitution regex is to construct a string of 1s whose length is half the length of the input, rounded up. Thus, an input of 12321 will produce the string 111, which then gets squared (explanation below). Even-length inputs will produce strings that are too small to ensure the final regex is successful.
The reason this code works is because of the following:
1 = 1**2
121 = 11**2
12321 = 111**2
1234321 = 1111**2
123454321 = 11111**2
12345654321 = 111111**2
1234567654321 = 1111111**2
123456787654321 = 11111111**2
12345678987654321 = 111111111**2
We can clearly see that the number of 1's in RHS is equal to 1/2 more than half the size of LHS. (1 more if we truncate). Additionally:
567898765 - 123454321 = 444444444, which is just 4 repeating. So when we subtract our square from our number, if we get a repdigit, our original number is a Giza number.
Old code and old method (58 + 1 = 59 bytes)
Saved 1 byte thanks to @Dada
Run with the -n flag, pipe text in using echo
say$_==($;=join"",/(.)/..($==y///c/2+/(.)/)-1).$=.reverse$
Calculates the unique giza number determined by the length and the leading integer, and sees if it matches the input.
Run as echo -n "123454321" | perl -M5.010 -n giza.pl
Returns 1 if it's a Giza number, null otherwise.
VBA, 175 bytes
Function e(s) As Boolean
Dim f As Long
For i=1 To Int(Len(s)/2)+1
x=Mid(s,i,1)
If f<>0 And ((f+1)<>x) Or (x<>Mid(s,Len(s)-i+1,1)) Then Exit Function
f=x
Next
e=1
End Function
Bash, 111 bytes
UPDATE
Note that input number normalization can probably be skipped completely, if you just add the first digit back to your generated GIZA number, like that:
01210 + 6 => 67876
and then just compare it with the input directly.
Disclaimer: this one is not really optimized, so it is more a proof of concept than a real contender
Golfed
G() { I=`sed "s/./\0-${1::1}\n/g"<<<$1|bc`;Z=`seq 0 $((${#1}/2))`;A=`rev <<<$Z`;cmp -s <(echo $I) <<<$Z${A:1}
Algorithm
Any GIZA number can be normalized to its canonical form, by substracting its first digit from the rest:
67876 - 6 => 01210
78987 - 7 => 01210
and there is only one canonical GIZA number of a particular length.
Knowing this we can easily generate a canonical GIZA number based on the input number length:
Z=`seq 0 $((${#1}/2))`;A=`rev <<<$Z` => $Z${A:1}
then normalize the input number:
I=`sed "s/./\0-${1::1}\n/g"<<<$1|bc`
and compare
cmp -s <(echo $I) <<<$Z${A:1};
Test
for i in `seq 0 1000`; do G $i && echo $i; done
0
1
2
3
4
5
6
7
8
9
121
232
343
454
565
676
787
898
...
G 12345678987654321 && echo "OK" || echo FALSE
OK
G 123456789987654321 && echo "OK" || echo FALSE
FALSE
Haskell, 61 bytes
g[a,b]=0>1
g(a:b:c)=a==last c&&b==succ a&&g(b:init c)
g _=1>0
Pushy, 30 15 bytes
I woke up this morning and realise I could half the length of my answer...
s&K-kL2/OvhXwx#
(non-competing as the language postdates challenge)
Input is given on the command line: $ pushy gizas.pshy 3456543. Outputs 1 for truthy and 0 for falsy. Here's the breakdown:
s % Split the number into its individual digits
&K- % Subtract all digits by the last
kL2/ h % Get the halved length of the stack (+1)
Ov X % In stack 2, generate range (0, halved length)
w % Mirror the range
x# % Check stack equality and output
The algorithm was inspired by the bash answer: first, normalize the number, (45654 -> 01210), then generate the normalized giza number of the same length (there is only one), and compare.
Old Solution
s&K-Y?kL2%?L2/:.;&OvhXx#i;;;0#
Python 2, 48 47 46 bytes
lambda s:s[~len(s)/2:]in'987654321'>s==s[::-1]
Test it on Ideone.
How it works
In Python, a chained comparison returns True if and only if all individual comparison do the same. In this specific case, our lambda returns True if and only if all of the following conditions are met.
s[~len(s)/2:]in'987654321'For a string s of length 2n + 1,
~len(s)/2returns ~(2n + 1) / 2 = -(2n + 2) / 2 = -(n + 1), sos[~len(s)/2:]yields the rightmost n + 1 characters of s.Similarly, for a string s of length 2n,
~len(s)/2returns ~(2n) / 2 = -(2n + 1) / 2 = -(n + 1) (integer division always round towards -∞, sos[~len(s)/2:]once more yields the rightmost n + 1 characters of sThe comparison returns True if and only if the rightmost n + 1 characters form a substring of
987654321.Note that if they do and s has 2n characters, s cannot be a palindrome; the nth and (n+1)th characters from the right will be distinct, and the latter is the nth character from the left.
'987654321'>sThis compares the strings lexicographically. Since 9 is the only Giza number that starts with 9, all Giza numbers satisfy this comparison.
Note that comparing these strings does not form part of our decision problem;
>sis simply three characters shorter thanand s.s==s[::-1]This returns True if and only if s is a palindrome.
Perl, 41 bytes
40 bytes of code + -p flags.
s/(.)(?=(.))/$1-$2/ge;$_=/^(-1(?1)1|).$/
Outputs 1 if the input is a Giza number, nothing otherwise. Supply the input without final newline to run it :
echo -n '123456787654321' | perl -pe 's/(.)(?=(.))/$1-$2/ge;$_=/^(-1(?1)1|).$/'
Explanations : first, s/(.)(?=(.))/$1-$2/ge replace each digit $1 (followed by $2) by $1-$2. If it's a Giza number, then each digits being one less than the next in the beginning, and one more in the end, then the string should contain only -1 in the first part, and 1 in the second (except the last that is left unchanged). That's what the second part /^(-1(?1)1|).$/ checks : looks for a -1 followed by recursion followed by a 1.
-1 byte thanks to Martin Ender.
My previous version 15 bytes longer (quite different so I'll let it here) :
echo -n '123456787654321' | perl -F -pe '$\=$_ eq reverse;$\&=$F[$_-1]+1==$F[$_]for 1..@F/2}{'
PHP, 71 bytes
for($t=$i=max(str_split($s=$argv[1]));$t!=$s&&--$i;)$t="$i$t$i";echo$i;
fetches the largest digit from input and counts down, adding the new digit to a comparison string until input and comparison string are equal - or $i is 0.
prints the lowest digit for a Timmy Number, 0 else.
C#, 120 86 108 102 92 bytes
x=I=>{var Z=I.Length;return Z<2?1>0:I[0]==I[Z-1]&I[1]-0==I[0]+1?x(I.Substring(1,Z-2)):0>1;};
Full program with some test cases:
class a
{
static void Main()
{
Func<string, bool> x = null;
x = I=>
{
var Z=I.Length;
return Z==1? // length == 1?
1>0: // return true (middle of #)
I[0]==I[Z-1]&I[1]-0==I[0]+1? // else start == end and the next number is 1 above the current?
x(I.Substring(1,Z-2)): // recursive call on middle
0>1; // else false
};
Console.WriteLine("1 -> " + (x("1") == true));
Console.WriteLine("9 -> " + (x("9") == true));
Console.WriteLine("121 -> " + (x("121") == true));
Console.WriteLine("12321 -> " + (x("12321") == true));
Console.WriteLine("4567654 -> " + (x("4567654") == true));
Console.WriteLine("12345678987654321 -> " + (x("12345678987654321") == true));
Console.WriteLine("12 -> " + (x("12") == false));
Console.WriteLine("1221 -> " + (x("1221") == false));
Console.WriteLine("16436346 -> " + (x("16436346") == false));
Console.WriteLine("123321 -> " + (x("123321") == false));
Console.WriteLine("3454321 -> " + (x("3454321") == false));
Console.WriteLine("13631 -> " + (x("13631") == false));
Console.WriteLine("191 -> " + (x("13631") == false));
Console.Read(); // For Visual Studio
}
}
Hooray for single line conditionals, now beating the Java answer :)! Also got to write my first explaining comments, though it's probably self explanatory. Thanks to @Dada for finding a problem with my algorithm (was true for numbers that were mirrored like 13631). Now sub 100 since apparently checking for length%2 is redundant.
Retina, 55 54 36 bytes
Byte count assumes ISO 8859-1 encoding.
.
$*1:
+`^(1+:)(1\1.*)\b\1$
$2
^1+:$
Convert each digit to unary, separated by colons. Loop, removing matching outer digits if the next digit is one more. Match a single remaining digit.
PowerShell v3+, 147 108 67 bytes
$args[0]-in(1..9+(1..8|%{$i=$_;++$_..9|%{-join($i..$_+--$_..$i)}}))
Radically changed approach. Generates all possible Giza numbers, and then checks whether the input $args[0] is -in that collection. Below is how the collection of Giza numbers is formed:
1..9+(1..8|%{$i=$_;++$_..9|%{-join($i..$_+--$_..$i)}})
1..8|%{ } # Loop from 1 up to 8
$i=$_; # Set $i to the current number
++$_..9|%{ } # Loop from one higher up to 9
$i..$_+--$_..$i # Build two ranges and concatenate
# E.g., 2..5 + 4..2
-join( ) # Join into a single string
1..9+( ) # Array concatenate with 1 to 9
Example runs:
PS C:\Tools\Scripts\golfing> 12321,5678765,121,4,123321,1232,5678,13631|%{"$_ --> "+(.\giza-numbers.ps1 "$_")}
12321 --> True
5678765 --> True
121 --> True
4 --> True
123321 --> False
1232 --> False
5678 --> False
13631 --> False
R, 100 bytes
l=length(x<-el(strsplit(scan(,""),"")));all(x==rev(x))&all(diff(as.numeric(x[1:((l+1)/2)]))==1)&l%%2
Unfortunately, the last Giza number (12345678987654321) is too large to be represented using R's 32-bit integers. Consequently we need to treat input as a string which makes this program slightly longer and we can't effectively rely on calculations.
- Read input as string and split into character vector:
x<-el(strsplit(scan(,""),"")) - Calculate length:
l=length(x) - Check if
xis equal to itself revered:all(x==rev(x)) - and if the difference between the numbers
1...middleare all equal to one:&all(diff(as.numeric(x[1:((l+1)/2)]))==1) - and if number of characters is odd:
&l%%2
Python 2, 68 73 66 bytes
lambda n:n==`int('1'+len(n)/2%9*'1')**2+int(len(n)*`int(n[0])-1`)`
abusing the fact that 11^2=121, 111^2=12321 and so on, I calculate this and add 1111.. enough times as offset.
Examples:
23432=111^2+11111*1
676=11^2+111*5
Mathematica, 62 61 60 bytes
Saved 2 bytes due to @MartinEnder.
MatchQ[{a:1...,b___}/;{b}==-{a}]@*Differences@*IntegerDigits
Composition of functions. Takes a number as input and returns True or False as output.
CJam, 20 19 bytes
l_$_W=),\ci>_W<W%+=
Explanation
The basic idea is to find the minimum and maximum digit, then create a Giza number from those and then check that it's equivalent to the input.
l e# Read input.
_$ e# Get a sorted copy of the input.
_W= e# Get its last character, i.e. the maximum digit M.
), e# Get a string with all characters from the null byte up to M.
\c e# Get the first character of the sorted string, i.e. the minimum
e# character m.
i> e# Convert to its character code and discard that many leading
e# characters from the string we generated before. Now we've got
e# a string with all digits from m to M, inclusive.
_W<W%+ e# Palindromise it, by appending a reversed copy without M.
= e# Check that it's equal to the input.
Instead of the minimum character, we can also use the first character, for the same byte count:
l_:e>),1$ci>_W<W%+=
><> FISH 57 52 49 48 bytes
i:1+?!vi00.;n1<
%?v0n;>~l:1-?!^2
{:<11 ^?:=@:$+=
Edit 1: = returns 0 or 1 if true so removed a check and used this value to increment, then it checks equality after anyway. (saved 6 bytes, lost 1 for new line).
Edit 2: 3 directional markers removed and 11 placed into gap to offset the stack to an even length to force false ( 3 bytes saved).,
Edit 3: Duplicate the length of the stack for checking MOD by 2 and len(1), this was done by putting the length on twice before but this now filled an empty space on line 2 ( 1 byte saved).
Java 7, 128 119 105 bytes
boolean t(long n){long a=1,b=1,c=0;for(;a<n/10;b=b*b<=n/10?b*10+1:b,c^=1)a=a*10+1;return(n-b*b)%a<1&c<1;}
No more strings! So, now I start by generating a 111... number of the same length as input (a), and one shorter to square (b). Then you can subtract b*b from the input and check divisibility by a. c is just there to check odd/even, pay it no mind >_>
Whitespaced:
boolean t(long n){
long a=1,b=1,c=0;
for(;a<n/10;b=b*b<=n/10?b*10+1:b,c^=1)
a=a*10+1;
return(n-b*b)%a<1&c<1;
}
Old Method, 119 bytes
boolean g(char[]a){int i=1,l=a.length,b=1,d;for(;i<l;b*=i++>l/2?d==-1?1:0:d==1?1:0)d=a[i]-a[i-1];return b>0?l%2>0:0>1;}
Walks through the array, checking for a difference of 1 (or -1, depending on which half) between each digit. Then just checks to see the length is odd.
Whitespaced:
boolean g(char[]a){
int i=1,l=a.length,b=1,d;
for(;i<l;b*=i++>l/2?d==-1?1:0:d==1?1:0)
d=a[i]-a[i-1];
return b>0?l%2>0:0>1;
}
><>, 62 bytes
i:0( ?v
v!1&!~{!<:=$:@&-1=+2=*>l!-3!1(!:?
>l!;2!n=!0?!<-1=n;
Outputs 1 for a Giza number; 0 otherwise. Works by pushing the input into a dequeue (ok, technically a reversible stack) and repeatedly testing both ends for equality, as well as making sure they are exactly one larger than the previous value.
Python 2, 50 82 81 80 bytes
def f(a):b=len(a)/2+1;print(1,0)[a[:b-1]!=a[b:][::-1]or a[:b]not in'123456789']
Simple approach. Just splits the string in half (missing out the middle character or one after the middle character if it is of even length), reverses the second half then compares the two and compares the first half with a string of 1 to 9.
Edit
Reposted after constructive feedback from fellow golfers and realising and correcting my mistakes.
-1 for losing a (waste of) space
-1 for reading the question again and realising that we don't need to take 0 into account. Really must stop golfing after a long day at work.
JavaScript (ES6), 46 45 42 41 bytes
f=([c,...s])=>s+s&&c-s.pop()|c-~-f(s)?0:c
Takes input as a string and returns a single-digit string for truthy, 0 for falsy.
The basic idea is to check for a few things:
- If the string is one char long, OR
- the first char is the same as the last char, and
- the middle section is also a Giza number, and
- the second char is one more than the first char here.
Python 3, 65 bytes
lambda x:len(x)<18and x[:len(x)//2+1]in'0123456789'and x[::-1]==x
I'm not entirely sure, but I think this works.
Haskell, 62 bytes
(`elem`[[j..pred i]++[i,pred i..j]|i<-['1'..'9'],j<-['1'..i]])
The input is taken as a string.
Creates a list of all Giza numbers an checks if the number is in it. The list is created by looping i through '1'..'9' and then j through '1'..i and creating the elements j .. i-1 , i , i-1 .. j.
Python 2, 77, 76, 64, 63 bytes
f=lambda s:2>len(s)or(s[0]==s[-1]==`int(s[1])-1`and f(s[1:-1]))
A simple recursive solution. Checks to see if the first and last digits equal each other and the second digit minus one. Then checks if the middle is also a Giza number. Returns true once it gets down to a single digit.
One byte saved thanks to @Rod, a ton of bytes saved thanks to DLosc and ETHProductions!
Actually, 22 bytes
9uR;∙`xR;RdX+εj`M;░#íu
Takes input as a quoted string (e.g. "12321"). Output is a positive integer for true, and 0 for false.
Explanation:
9uR;∙`xR;RdX+εj`M;░#íu
9uR;∙ cartesian product of [1,2,3,4,5,6,7,8,9,10] with itself
`xR;RdX+εj`M for each pair:
x construct the half-open (end-exclusive) range ([1, 5] -> [1, 2, 3, 4])
R reverse
;RdX+ duplicate, reverse, remove first element, prepend ([1, 2, 3, 4] -> [1, 2, 3, 4, 3, 2, 1])
εj concatenate into a string
;░ filter out empty strings
#íu test for membership
Cjam, 35 bytes
Probably very suboptimal... I'm a little out of practice!
q__W%=\_,_2%@@2/)<2ew{:-}%e`,1=]:e&