Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have 4 rules laid out so just write code to check each rule.</p> <ul> <li><p>The number is N digits. Determine what N is. Could be done by converting to a string or a vector for each digit. You may need to use division by 10 and mod (%) 10 a few times.</p></li> <li><p>A method to move from one digit to the next. So if you are at digit position x with value y, you move to x+y mod N that is (x+y)%N. The first position is considered position 0, of course.</p></li> <li><p>You need to check that you touch every position, and also that you do not have a duplicate. This could be one check. If you reach a digit you have seen before you know you have the correct solution if and only if this is the Nth iteration and you are at index 0.</p></li> </ul> <p>12 is failure. Because although it is after 2 iterations you do not reach index 0 but revisit index 1 (2 takes you from index 1 back to index 1)</p> <p>11 is failure because you see another 1 when you have not had all your iterations yet.</p> <p>123 is failure because you get back to 1 an iteration too early. You don't need to know you didn't see the 3, or that you got back to index 0, just that you saw another 1 too early.</p> <p>285 works though. You see 2 then 5 then 8 then 2. You are at index 0 and have had 3 iterations.</p> <p>You need to store a collection of seen digits. vector is slightly controversial, so you could use std::bitset or even just a bool[10] will do for this example, or vector. You could also use std::set, the latter case of which would allow you to check its size to see your iteration count.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload