Hexagonal Grid Discussions | Algorithms | HackerRank
  • + 0 comments

    ~10 lines Python, 100%, cool bit things

    If you figure out what the numbers mean I'll buy you a virtual coffee :D

    @cache
    def f(a,b):
        x=((a&3)<<2)|(b&3)
        if a==b:
            return True
        if (a,b)==(0,1) or (a,b)==(1,0) or x in {6,11,14}:
            return False
        if x in {2,7,8,13}:
            return f(a>>1,b>>1)
        if x in {0,3,5,9,10,12,15}:
            return f(a>>2,b>>2)
        return f(a>>1,(b>>1)|1) or f((a>>1)|1,b>>1)
    
    def hexagonalGrid(a, b):
        return "YES" if f(int(a,2),int(b,2)) else "NO"