Skip to main content
added 580 characters in body
Source Link
user12205
  • 9k
  • 3
  • 33
  • 65

C, 7186

Assuming that seeding the rand() function is not required.

k=30;main(i){i=rand()%k;while(k--){printf("%*c\n",i+=randi+=i==30?-1:i==1||rand()%2?1:-1,46);}} 

Explanation:

In C, in "%*c" the * means that the length of the output will have a minimum length, and this minimum length is determined by the argument of the function call (in this case, it is i+=i==30?-1:i==1||rand()%2?1:-1. The c means the next argument (46) is a character (the dot).

As for the boundary check, I apologise that I forgot about that. I have now added this to the answer, at the cost of 15 chars. The ternary operator works as follows: boolean_condition?value_if_true:value_if_false. Note that in C true is 1 and false is 0.

C, 71

Assuming that seeding the rand() function is not required.

k=30;main(i){i=rand()%k;while(k--)printf("%*c\n",i+=rand()%2?1:-1,46);} 

C, 86

Assuming that seeding the rand() function is not required.

k=30;main(i){i=rand()%k;while(k--){printf("%*c\n",i+=i==30?-1:i==1||rand()%2?1:-1,46);}} 

Explanation:

In C, in "%*c" the * means that the length of the output will have a minimum length, and this minimum length is determined by the argument of the function call (in this case, it is i+=i==30?-1:i==1||rand()%2?1:-1. The c means the next argument (46) is a character (the dot).

As for the boundary check, I apologise that I forgot about that. I have now added this to the answer, at the cost of 15 chars. The ternary operator works as follows: boolean_condition?value_if_true:value_if_false. Note that in C true is 1 and false is 0.

deleted 2 characters in body
Source Link
user12205
  • 9k
  • 3
  • 33
  • 65

C, 7371

Assuming that seeding the rand() function is not required.

k=30;main(i){i=rand()%k;while(k--){printf("%*c\n",i+=rand()%2?1:-1,46);}} 

C, 73

Assuming that seeding the rand() function is not required.

k=30;main(i){i=rand()%k;while(k--){printf("%*c\n",i+=rand()%2?1:-1,46);}} 

C, 71

Assuming that seeding the rand() function is not required.

k=30;main(i){i=rand()%k;while(k--)printf("%*c\n",i+=rand()%2?1:-1,46);} 
Source Link
user12205
  • 9k
  • 3
  • 33
  • 65

C, 73

Assuming that seeding the rand() function is not required.

k=30;main(i){i=rand()%k;while(k--){printf("%*c\n",i+=rand()%2?1:-1,46);}}