DEV Community

Discussion on: Daily Challenge #300 - Username / Password Comparison

Collapse
 
mbaas2 profile image
Michael Baas

Here's a solution in Dyalog APL:

∇ z←validate(a b);l;m;s;subs
 →(z←0∊l←≢¨a b)↑0                               ⍝ l=lengths, exit if there's 0 among them
 m←⌊/l                                          ⍝ lowest length
 s←(l⍳m)⊃a b                                    ⍝ get the shortest string
 m←⌊m÷2                                         ⍝ divide by 2
 subs←m{(↓⍺,[1.5]⍳(≢⍵)-⍺){⍺[1]↑⍺[2]↓⍵}¨⊂⍵}¨a b ⍝ look for matches of substrings of a in b (and vice versa)  ⍝ get substrings (of length m)
 z←~1∊∊subs{⍺⍷¨⊂⍵}¨b a                          ⍝ return 0 if we found any matches
∇
Enter fullscreen mode Exit fullscreen mode

Running it:

      validate'newyorkcity' 'yankees101'
1
      validate'username' 'usernamePW'
0
      validate'Paa2' 'Paaaaaa222!!!'
0
      validate'wordpass' 'password'
0
      validate'superman' 'persuzod'
1
      validate'abc' 'defghijklmnopab'  ⍝ added this testcase
0
Enter fullscreen mode Exit fullscreen mode

But don't take my word for it - Try It Online!