Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

The New Coffee Room

  1. TNCR
  2. General Discussion
  3. Puzzle Time - Read, Increment, Write

Puzzle Time - Read, Increment, Write

Scheduled Pinned Locked Moved General Discussion
22 Posts 5 Posters 141 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • jon-nycJ Offline
    jon-nycJ Offline
    jon-nyc
    wrote on last edited by
    #1

    One hundred scientists are working at a high-tech project.  Proud of their ability to do mental arithmetic, they institute a challenge.  In a small and noisy engine room, there is a blackboard with the number zero written on it.  Each scientist performs the following routine one hundred times:

    1.  Enter the engine room, read the number on the blackboard, and leave the engine room.
    2.  Increment the memorized number by 37 (mentally).
    3.  Enter the engine room, erase the number on the blackboard, write the incremented value on the blackboard, and leave the engine room.

    The scientists work at their own pace, independent of each other; that is, their steps can be interleaved.  The engine room is so small that at each moment, only one scientist can be in there.  So, occasionally, they will have to wait for each other.

    When they are all done, the largest number that could be on the blackboard is 370,000.

    What is the smallest possible final value?

    "You never know what worse luck your bad luck has saved you from."
    -Cormac McCarthy

    taiwan_girlT 1 Reply Last reply
    • AxtremusA Offline
      AxtremusA Offline
      Axtremus
      wrote on last edited by
      #2

      :::

      37 * 100 = 3700

      :::

      1 Reply Last reply
      • jon-nycJ Offline
        jon-nycJ Offline
        jon-nyc
        wrote on last edited by
        #3

        I can get lower than that Ax

        "You never know what worse luck your bad luck has saved you from."
        -Cormac McCarthy

        1 Reply Last reply
        • KlausK Offline
          KlausK Offline
          Klaus
          wrote on last edited by Klaus
          #4

          I'm getting Dijkstra-semaphore-vibes from this task!

          :::

          Probably I'm not getting something, but isn't it obviously just 37? For instance, if the first guy who enters-to-read is the last guy who enters-to-write.

          Or is the point that the scientists have to queue up immediately after step 1? But even then, if all 100 scientists queue up immediately, they'll all read 0 and write 37.

          :::

          jon-nycJ 1 Reply Last reply
          • KlausK Klaus

            I'm getting Dijkstra-semaphore-vibes from this task!

            :::

            Probably I'm not getting something, but isn't it obviously just 37? For instance, if the first guy who enters-to-read is the last guy who enters-to-write.

            Or is the point that the scientists have to queue up immediately after step 1? But even then, if all 100 scientists queue up immediately, they'll all read 0 and write 37.

            :::

            jon-nycJ Offline
            jon-nycJ Offline
            jon-nyc
            wrote on last edited by
            #5

            @Klaus Each guy has to repeat the cycle 100 times.

            "You never know what worse luck your bad luck has saved you from."
            -Cormac McCarthy

            KlausK 1 Reply Last reply
            • jon-nycJ jon-nyc

              @Klaus Each guy has to repeat the cycle 100 times.

              KlausK Offline
              KlausK Offline
              Klaus
              wrote on last edited by
              #6

              @jon-nyc said in Puzzle Time - Read, Increment, Write:

              @Klaus Each guy has to repeat the cycle 100 times.

              Oh, I missed that one. Hm....

              1 Reply Last reply
              • KlausK Offline
                KlausK Offline
                Klaus
                wrote on last edited by
                #7

                :::

                Thinking about it a little, I think the problem can be expressed in terms of a formal languages of balanced parantheses. Something like a Dyck language. I vaguely remember that there's a generalization of Dyck languages to different kinds of parentheses. I believe there is something like the language D_n, which is the balanced parenthesis expressions with n different kinds of parentheses. So for this scenario, we would need to consider the language D_100, featuring 100 different kinds of parentheses. There's a 1:1 correspondence between the scenarios that can unfold in Jon's story and the words of D_100 where each parenthesis shows up 100 times..

                Hmmm....
                :::

                1 Reply Last reply
                • jon-nycJ Offline
                  jon-nycJ Offline
                  jon-nyc
                  wrote on last edited by jon-nyc
                  #8

                  Don’t know much about Dyke languages but intuitively I see the analogy of the open and close parens.

                  "You never know what worse luck your bad luck has saved you from."
                  -Cormac McCarthy

                  George KG 1 Reply Last reply
                  • jon-nycJ Offline
                    jon-nycJ Offline
                    jon-nyc
                    wrote on last edited by
                    #9

                    Here’s a hint.

                    :::

                    Let M(n,r) be the minimum final number with n scientists doing r rounds of read, increment, write. Observe that M(n+1, r) <= M(n,r) since given a minimal sequence with r rounds and n scientists, you can add another scientist with no impact by having all his activity occur after the read associated with final write but before that final write.

                    :::

                    "You never know what worse luck your bad luck has saved you from."
                    -Cormac McCarthy

                    KlausK 1 Reply Last reply
                    • jon-nycJ jon-nyc

                      Don’t know much about Dyke languages but intuitively I see the analogy of the open and close parens.

                      George KG Offline
                      George KG Offline
                      George K
                      wrote on last edited by
                      #10

                      @jon-nyc said in Puzzle Time - Read, Increment, Write:

                      Don’t know much about Dyke languages

                      I'm calling bullshit on that....

                      "Now look here, you Baltic gas passer... " - Mik, 6/14/08

                      The saying, "Lite is just one damn thing after another," is a gross understatement. The damn things overlap.

                      1 Reply Last reply
                      • jon-nycJ jon-nyc

                        One hundred scientists are working at a high-tech project.  Proud of their ability to do mental arithmetic, they institute a challenge.  In a small and noisy engine room, there is a blackboard with the number zero written on it.  Each scientist performs the following routine one hundred times:

                        1.  Enter the engine room, read the number on the blackboard, and leave the engine room.
                        2.  Increment the memorized number by 37 (mentally).
                        3.  Enter the engine room, erase the number on the blackboard, write the incremented value on the blackboard, and leave the engine room.

                        The scientists work at their own pace, independent of each other; that is, their steps can be interleaved.  The engine room is so small that at each moment, only one scientist can be in there.  So, occasionally, they will have to wait for each other.

                        When they are all done, the largest number that could be on the blackboard is 370,000.

                        What is the smallest possible final value?

                        taiwan_girlT Offline
                        taiwan_girlT Offline
                        taiwan_girl
                        wrote on last edited by
                        #11

                        @jon-nyc said in Puzzle Time - Read, Increment, Write:

                        When they are all done, the largest number that could be on the blackboard is 370,000.

                        Hmmm, I will think some more (and probably not still be able to solve it),

                        :::

                        but I am not sure how it could be smaller than 370,000.

                        100 * 100 * 37

                        :::

                        jon-nycJ 1 Reply Last reply
                        • taiwan_girlT taiwan_girl

                          @jon-nyc said in Puzzle Time - Read, Increment, Write:

                          When they are all done, the largest number that could be on the blackboard is 370,000.

                          Hmmm, I will think some more (and probably not still be able to solve it),

                          :::

                          but I am not sure how it could be smaller than 370,000.

                          100 * 100 * 37

                          :::

                          jon-nycJ Offline
                          jon-nycJ Offline
                          jon-nyc
                          wrote on last edited by jon-nyc
                          #12

                          @taiwan_girl

                          Recall the read/increment, and write are separate. And whatever happens to the number between your read and your write is essentially lost when you write.

                          To put it another way, imagine you are one of the hundred. You go in first, see it at zero. Walk out. Then (say) all the other 99 do all 100 of their cycles. IOW, they’re done now. Then you finally walk back in, erase whatever number they got to, and write 37. So you basically reversed all of their work. Made it as if they had never even participated. And you’ve got 99 cycles left which will bring the grand total to 3700. That was basically Ax’s proposal.

                          But it can go even smaller than that.

                          "You never know what worse luck your bad luck has saved you from."
                          -Cormac McCarthy

                          1 Reply Last reply
                          • jon-nycJ jon-nyc

                            Here’s a hint.

                            :::

                            Let M(n,r) be the minimum final number with n scientists doing r rounds of read, increment, write. Observe that M(n+1, r) <= M(n,r) since given a minimal sequence with r rounds and n scientists, you can add another scientist with no impact by having all his activity occur after the read associated with final write but before that final write.

                            :::

                            KlausK Offline
                            KlausK Offline
                            Klaus
                            wrote on last edited by
                            #13

                            @jon-nyc said in Puzzle Time - Read, Increment, Write:

                            Here’s a hint.

                            :::

                            Let M(n,r) be the minimum final number with n scientists doing r rounds of read, increment, write. Observe that M(n+1, r) <= M(n,r) since given a minimal sequence with r rounds and n scientists, you can add another scientist with no impact by having all his activity occur after the read associated with final write but before that final write.

                            :::

                            So you want us to express M(n,r) as a recurrence relation and then solve it?

                            I assume it's something like this:

                            M(n+1,r) = minimum{ M(n,r) , -- the trick -- }
                            M(n,r+1) = minimum { M(n,a) + M(n,b) | a+b=r+1} union { -- the-other-trick -- }

                            1 Reply Last reply
                            • jon-nycJ Offline
                              jon-nycJ Offline
                              jon-nyc
                              wrote on last edited by
                              #14

                              Not necessarily. The implication of that hint that I was trying to communicate is that if you find a really low number with, say, 2 scientists, you’d be able to preserve that low number at 100 (or potentially do better).

                              "You never know what worse luck your bad luck has saved you from."
                              -Cormac McCarthy

                              1 Reply Last reply
                              • jon-nycJ Offline
                                jon-nycJ Offline
                                jon-nyc
                                wrote on last edited by
                                #15

                                So if you can convince yourself that a solution you found for a smaller n must be a lower bound for any n, you are done.

                                "You never know what worse luck your bad luck has saved you from."
                                -Cormac McCarthy

                                1 Reply Last reply
                                • KlausK Offline
                                  KlausK Offline
                                  Klaus
                                  wrote on last edited by Klaus
                                  #16

                                  :::

                                  I made a little progress.

                                  In the scenario with 2 scientists and 3 rounds, Ax's method would yield a bound of 3*37.

                                  If we denote by R<n> the event of scientist n entering the room to read and W<n> the event of scientist n entering the room two write, then this sequence of events yields a final number of just 2*27.

                                  R0,R1,W0,R0,W0,W1,R0,R1,W1,R1,W1,W0

                                  Here's a sequence that yields just 2*37 for 4 rounds of 2 scientists:

                                  R0,R1,W0,R0,W0,R0,W0,W1,R0,R1,W1,R1,W1,R1,W1,W0

                                  Even for five rounds, 2*37 is sufficient.

                                  R0,R1,W0,R0,W0,R0,W0,R0,W0,W1,R0,R1,W1,R1,W1,R1,W1,R1,W1,W0

                                  And finally, one for six rounds with 2*37.

                                  R0,R1,W0,R0,W0,R0,W0,R0,W0,R0,W0,W1,R0,R1,W1,R1,W1,R1,W1,R1,W1,R1,W1,W0

                                  Based on this pattern, I assume that 2*37 is also sufficient for 100 rounds of 2 scientists and, since more scientists can be added without increasing the number, also in the original case with 100 rounds and 100 scientists.

                                  :::

                                  1 Reply Last reply
                                  • KlausK Offline
                                    KlausK Offline
                                    Klaus
                                    wrote on last edited by Klaus
                                    #17

                                    I think I got it.

                                    :::

                                    With my nomenclature from above, here's how to get by with 2*37 for 100 rounds with 2 scientists:

                                    R0
                                    99 times R1,W1
                                    W0
                                    R1
                                    99 times R0,W0
                                    W1

                                    For the remaining 98 scientists, insert them somewhere before a "W"rite in that sequence.

                                    :::

                                    1 Reply Last reply
                                    • KlausK Offline
                                      KlausK Offline
                                      Klaus
                                      wrote on last edited by
                                      #18

                                      Here's a counter puzzle for @jon-nyc :

                                      How many different scenarios/orders are there for n scientists and r rounds?

                                      I have worked out the solution for n=2. It's interesting.

                                      jon-nycJ 1 Reply Last reply
                                      • KlausK Klaus

                                        Here's a counter puzzle for @jon-nyc :

                                        How many different scenarios/orders are there for n scientists and r rounds?

                                        I have worked out the solution for n=2. It's interesting.

                                        jon-nycJ Offline
                                        jon-nycJ Offline
                                        jon-nyc
                                        wrote on last edited by
                                        #19

                                        @klaus

                                        Your answer is what I got.

                                        As for your question, seems like it’s the problem of how many ways there are to interleave two (or k) ordered lists.

                                        "You never know what worse luck your bad luck has saved you from."
                                        -Cormac McCarthy

                                        KlausK 1 Reply Last reply
                                        • jon-nycJ jon-nyc

                                          @klaus

                                          Your answer is what I got.

                                          As for your question, seems like it’s the problem of how many ways there are to interleave two (or k) ordered lists.

                                          KlausK Offline
                                          KlausK Offline
                                          Klaus
                                          wrote on last edited by Klaus
                                          #20

                                          @jon-nyc said in Puzzle Time - Read, Increment, Write:

                                          As for your question, seems like it’s the problem of how many ways there are to interleave two (or k) ordered lists.

                                          Yes. Both lists have length 2r. Once the positions of the first list in the interleaved list are fixed, the positions of the elements of the second list are fixed, too. Hence the number we are looking for is binomial(4r,2r). Which turns out to be (r+1) * C(r), where C(r) is the r-th Catalan number. Which in turn brings us back to my reference to Dyck languages, since the number of distinct Dyck words with exactly n pairs of parentheses is the n-th Catalan number.

                                          1 Reply Last reply
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups