Блог пользователя dush1729

Автор dush1729, история, 8 лет назад, По-английски

I solved TopBiologist by recursion. I want to know if there is any iterative approach? We will need to run loop 6 times to generate sequence of length 6. Is there any shorter way to do this?

My code

  • Проголосовать: нравится
  • -6
  • Проголосовать: не нравится

»
8 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

It's similar to converting numbers into the radix 4.

for num in [0 .. 4**length)
  s = ""
  x = num
  for i in [0 .. length)
    s += "ACGT"[x % 4]
    x /= 4
  // use s
  • »
    »
    8 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Thanks. Can we write i th element of an integer array like you wrote for string?

    You wrote s += "ACGT"[x % 4]

    I wrote this and got compilation error

    for(int i=0;i<4;i++) cout<<{1,2,3,4}[i];

»
7 лет назад, # |
  Проголосовать: нравится -8 Проголосовать: не нравится

I have found an interesting solution without recursion.