Ad

This is a response to the kumite https://www.codewars.com/kumite/5a4edf17d8e145968c00015e to show that it has an elegant solution for ruby using the compiled bash utility "tr"

It's my first kumite so I'm not sure if this is how to use it. Don't mind if I do!

Code
Diff
  • def pattern a,b
      a.tr(a,b)==b && b.tr(b,a)==a
    end
    • def pattern(p,st):
    • def encode(s):
    • dic={} # dictionary to hold values from the input string
    • num=0
    • sn="" # a numerical string to hold the encoding
    • for i in s:
    • if i not in dic:
    • dic[i]=num
    • num+=1
    • sn+=str(dic[i])
    • return sn
    • return encode(st)==encode(p)
    • def pattern a,b
    • a.tr(a,b)==b && b.tr(b,a)==a
    • end