prcsamrat's blog

By prcsamrat, history, 8 months ago, In English

Hello, I am trying to solve the Josephus Queries (Mathematics section) problem, and I am not able to code the logic that is iterative and not recursive.

I am really trying hard to get through this problem, I just completed the introduction and graph sections.

Looking forward to help.

Thanks in advance.

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
8 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Why does it have to be iterative? A recursive solution is probably easier to implement

»
8 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I find recursive solution difficult to understand.

»
8 months ago, # |
  Vote: I like it 0 Vote: I do not like it

ordered_set is a cheatcode if u really wanna solve it

  • »
    »
    8 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Can you elaborate a bit more on this? I tried thinking in this way but not able to pick up!

    • »
      »
      »
      8 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Just simulate the process and use ordered ser from gnu pbds

      • »
        »
        »
        »
        8 months ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        How do you simulate the process using ordered_set for n=10^9?

        • »
          »
          »
          »
          »
          8 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          oh wait its josephus queries i thought it was josephus problem sorry

          • »
            »
            »
            »
            »
            »
            7 months ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Yeah, you can refer the link I have added to get rid of confusion.

        • »
          »
          »
          »
          »
          7 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          It would be great if you share any of the insights for iterative solution.

          • »
            »
            »
            »
            »
            »
            7 months ago, # ^ |
              Vote: I like it 0 Vote: I do not like it
            • »
              »
              »
              »
              »
              »
              »
              7 months ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              Thank you for sharing, I am aware of this blog and solution it contains is recursive. I am looking out for iterative intuition.

              • »
                »
                »
                »
                »
                »
                »
                »
                7 months ago, # ^ |
                  Vote: I like it 0 Vote: I do not like it

                copy paste the code given into chatgpt and tell it to do iterative, i think it will work

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  7 months ago, # ^ |
                    Vote: I like it 0 Vote: I do not like it

                  I did that, chatgpt didt went well! GPT is language model, it doesnt understand the logic encoded in some kinda variables!

»
7 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Recently, I found this solution online, anyone can decode it?

  • »
    »
    7 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I see some kind of pattern author is trying to code, is it?

    • »
      »
      »
      7 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I also followed the solution suggested by drugkeeper . It's neat and clear. I can try explain it to you . Why are you bothered to find iterative one?