2

I was going through problems on SPOJ, when I saw this SBStr1. I learnt a little bit of WhiteSpace language, but I could reach only up to loops.
Can anyone please help me on how to check if a string has another string as a substring in WhiteSpace ?

ABcDexter
  • 2,751
  • 4
  • 28
  • 40
  • 2
    The strings are binary, so read them bit by bit and convert them into binary numbers, then compare (A/2^n) mod 32 to B, from n from 0 to 4. – Lynn Oct 23 '14 at 11:41
  • 1
    0 to 4 inclusive ?? And can you explain how it works ?? I know about bit shift (it's possibly the right explanation), please write this in answer part, thanks ^_^ – ABcDexter Oct 24 '14 at 06:59

1 Answers1

4

I'm not going to write the Whitespace code for you but here is an approach you can take that easily translates to Whitespace:

24 times:
    read 10 bit number into A
    skip space
    read 5 bit number into B
    skip newline

    if (A>>0)%32 == B or (A>>1)%32 == B or ... or (A>>5)%32:
        print 1
    else:
        print 0
    print newline

You can implement the bitshifts through repeated division by 2.

Lynn
  • 10,425
  • 43
  • 75