0

I am trying to understand code used to solve the 100 doors problem of rosettacode. The code in question is this

n=100;
tmp=ConstantArray[-1,n];
Do[tmp[[i;;;;i]]*=-1;,{i,n}];
Do[Print["door ",i," is ",If[tmp[[i]]==-1,"closed","open"]],
{i,1,Length[tmp]}]

I understand every line except the third. I have never seen the construct

Do[tmp[[i;;;;i]]*=-1;,{i,n}];

what do these semicolons inside a list do. What is the * for?

PhoenixPerson
  • 553
  • 2
  • 10

1 Answers1

1

I look in the help that aaa[[b;;c;;d]] is understood as Part from b to c in steps of d. Then if c is missed that means to the end. Only the positions that are squares are opened. So it cames from this [[b;; ;;d]]

Anxon Pués
  • 907
  • 5
  • 13