1
$\begingroup$

The code below is in F#. It creates a scene which looks like a perspective coming from the top left. I thought if I would change i % j = w then it would come from the top right instead, but that doesn't work. So what change do I need to make for it to be able to come from the top right, bottom left, bottom right and even the top centre?

open System

let w = Console.WindowWidth
let h = Console.WindowHeight

for i in 1 .. w - 1 do
    for j in 1 .. h - 1 do
        Console.SetCursorPosition(i, j)
        if i % j = 0 then printf "."

Console.Read() |> ignore

Here is what the program looks like.

 .......................................................................................................................  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
   .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .
     .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .    .
      .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     .     .
       .      .      .      .      .      .      .      .      .      .      .      .      .      .      .      .      .        .       .       .       .       .       .       .       .       .       .       .       .       .       .
         .        .        .        .        .        .        .        .        .        .        .        .        .
          .         .         .         .         .         .         .         .         .         .         .
           .          .          .          .          .          .          .          .          .          .
            .           .           .           .           .           .           .           .           .
             .            .            .            .            .            .            .            .            .
              .             .             .             .             .             .             .             .
               .              .              .              .              .              .              .
                .               .               .               .               .               .               .
                 .                .                .                .                .                .                .                  .                 .                 .                 .                 .                 .
                   .                  .                  .                  .                  .                  .
                    .                   .                   .                   .                   .
                     .                    .                    .                    .                    .
                      .                     .                     .                     .                     .
                       .                      .                      .                      .                      .
                        .                       .                       .                       .
                         .                        .                        .                        .
                          .                         .                         .                         .
                           .                          .                          .                          .
                            .                           .                           .                           .
                             .                            .                            .                            .
$\endgroup$

closed as off-topic by Evil, David Richerby, Thomas Klimpel, Discrete lizard, Tom van der Zanden Aug 31 '18 at 11:12

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about computer science, within the scope defined in the help center." – Evil, David Richerby, Thomas Klimpel, Discrete lizard, Tom van der Zanden
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ You've written "algorithm" but, really, this seems to be a programming problem, which is off-topic, here. Also, I'm not really sure what you're trying to achieve. $\endgroup$ – David Richerby Aug 20 '18 at 10:14
  • $\begingroup$ @DavidRicherby Indeed, I had flagged this question as off-topic too although I answered it anyway. I just took a little bit more thought. I believe that the OP, as probably a newcomer to programming and computer science, may believe this question is about the correct algorithm that can produce the desired output. In a way, he is right. But then almost every programming problem can be treated as a question about algorithm. $\endgroup$ – Apass.Jack Aug 20 '18 at 10:38
  • $\begingroup$ @Apass.Jack I agree that there's often no clear dividing line between designing an algorithm and writing a program. For me, this is on the programming side, though, as it's essentially "Here's a program that does X; how do I modify it to do Y?" But this is certainly something that reasonable people can disagree on. However, I would say that you shouldn't flag a question as off-topic and answer it: those are kind of contradictory acts. $\endgroup$ – David Richerby Aug 20 '18 at 10:49
  • $\begingroup$ @DavidRicherby, indeed, I had said (implicitly) that I had made contradictory acts, too. $\endgroup$ – Apass.Jack Aug 20 '18 at 11:01
  • $\begingroup$ I would have thought it could be considered an algorithm, that's why I thought it was best suited here. Otherwise I would have posted it on Stack Overflow and probably gotten a much quicker answer, but I wanted it in the right place. $\endgroup$ – Alanay Aug 20 '18 at 13:59
0
$\begingroup$

Can you try replacing the original condition i % j == 0 with the following conditions? They work for me.

  • For a perspective coming from the top right, (w-i) %j == 0
  • For a perspective coming from the bottom left, i %(h-j) == 0
  • For a perspective coming from the bottom right, (w-i) % (h-j) == 0
  • For a perspective coming from the the top centre, (w/2-i) % j == 0
$\endgroup$
  • $\begingroup$ Thank you! Funnily enough I tried some of those before but never used parentheses. $\endgroup$ – Alanay Aug 20 '18 at 13:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.