Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • \$\begingroup\$ Can you expand on what is going on in your code? I'm having trouble understanding how printf("%*c\n",i+=rand()%2?1:-1,46) prints the spaces, as well as how it keeps the dot from possibly moving past 29. Thanks in advance. (Sorry, I'm not a C programmer.) \$\endgroup\$ Commented Feb 17, 2014 at 23:33
  • \$\begingroup\$ @fireeyedboy done, hope you understand :) \$\endgroup\$ Commented Feb 17, 2014 at 23:53
  • \$\begingroup\$ Aaaah, I kind of had the feeling you were cheating a little bit there. ;-) But the rest is clear indeed now. Thank you! And nice solution! Does C also have the strange behavior with rand()%2 in that it is very predictable (odd/even turns)? I tried your rand()%2 in my PHP solution, and it exhibited this very predictable behavior (as opposed to rand(0,1). Since PHP makes a lot of use of C libraries (if I'm correct) I was wondering whether your C program has the same 'flaw'. \$\endgroup\$ Commented Feb 18, 2014 at 0:02
  • \$\begingroup\$ @fireeyedboy I did not seed the rand() function. In C if rand() is not seeded explicitly, it always uses the same seed every time. That's why it is predictable. If I had to seed it I can do srand(time()); which costs 14 chars \$\endgroup\$ Commented Feb 18, 2014 at 0:05
  • \$\begingroup\$ But is it so predictable that it switches from odd to even on each subsequent call as well? PHP claims rand() doesn't need to be seeded with srand() anymore, but still shows this odd behavior. \$\endgroup\$ Commented Feb 18, 2014 at 0:27