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 - concatenary palindromes

Puzzle time - concatenary palindromes

Scheduled Pinned Locked Moved General Discussion
20 Posts 3 Posters 168 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 Online
    jon-nycJ Online
    jon-nyc
    wrote on last edited by jon-nyc
    #8

    How high did your ‘n’ get before you gave up on the program?

    "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
      #9

      I believe around n=14.

      1 Reply Last reply
      • jon-nycJ Online
        jon-nycJ Online
        jon-nyc
        wrote on last edited by
        #10

        HINT: Finding the least positive integer with any given property is a matter of priorities: first, minimize the number of digits; then, minimize the leftmost digit (not allowing 0); then, minimize the second digit from the left, and so forth.

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

        1 Reply Last reply
        • AxtremusA Away
          AxtremusA Away
          Axtremus
          wrote on last edited by Axtremus
          #11

          click to show

          (EDIT: adding this extra line to prevent spoiler content from showing on the index page)

          19 8 17 6 15 4 13 2 11 12 3 14 5 16 7 18 9 1

          1 Reply Last reply
          • jon-nycJ Online
            jon-nycJ Online
            jon-nyc
            wrote on last edited by
            #12

            You skipped 10

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

            1 Reply Last reply
            • AxtremusA Away
              AxtremusA Away
              Axtremus
              wrote on last edited by Axtremus
              #13

              Hmm … I tried a few variations with similar methods and it seems I always miss something in the middle (either 11 or 10).

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

                edit: nope

                I think I have it with n=20

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

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

                  I have a solution with n=19.

                  Can’t be a lower n since any lower n will have more than one digit with an odd number of instances.

                  click to show

                  I don’t know if this is the smallest
                  2 11 3 14 5 16 7 18 9 10 19 8 17 6 15 4 13 1 12

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

                  1 Reply Last reply
                  • jon-nycJ Online
                    jon-nycJ Online
                    jon-nyc
                    wrote on last edited by
                    #16

                    Smallest.

                    click to show

                    Here.
                    1 12 3 14 5 16 7 18 9 10 19 8 17 6 15 4 13 2 11

                    "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
                      #17

                      OK, I turned my little 3-liner into a small back-tracking algorithm which stops early when a solution is no longer feasible, and it scales to n=19.

                      It turns out that there are 362,880 different palindromes one can make with 1..19.

                      And indeed the smallest one is the one Jon produced:

                      ae32eac9-eba6-4d87-bb9e-34e37305e6bd-image.png

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

                        Interestingly, my algorithm can produce palindromes very quickly for up to n=22, but at n=23 there is suddenly a problem. The computer hasn't found anything in 10min or so. I assume the third "3" makes it impossible. Which raises the question: What is the set of numbers for which there are palindromes as described above. So far, we know that the
                        set includes the numbers 19 to 22 but not 2 to 18.

                        jon-nycJ 1 Reply Last reply
                        • KlausK Klaus

                          Interestingly, my algorithm can produce palindromes very quickly for up to n=22, but at n=23 there is suddenly a problem. The computer hasn't found anything in 10min or so. I assume the third "3" makes it impossible. Which raises the question: What is the set of numbers for which there are palindromes as described above. So far, we know that the
                          set includes the numbers 19 to 22 but not 2 to 18.

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

                          @Klaus a third 3 and a thirteenth 1 together makes 23 impossible. .

                          If a number is a palindrome it will have a maximum of one digit with an odd number of occurrences.

                          Put such a test in your code and you can rule out impossible ‘n’s.

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

                          1 Reply Last reply
                          • jon-nycJ Online
                            jon-nycJ Online
                            jon-nyc
                            wrote on last edited by
                            #20

                            SOLUTION: Suppose that our solution concatenates the numbers from 1 to N. Then each of the digits 1, 2, ..., 9, 0 must appear an even number of times in the numbers from 1 to N, with at most one exception, in order for those digits to be arrangeable into a palindrome.

                            So a natural first task is to determine the least N with this property, and it turns out to be 19. The numbers from 1 to 19 contain 12 1's, 2 of each digit from 2 to 9, and just one 0 (which would thus have to be in the middle of our concatenary palindrome).

                            We don't know yet whether there is a concatenary palindrome made from the numbers 1 through 19, but let's be optimistic and try to construct the smallest one we can. We'd want to start the number with the digit 1, and thus it must also end with 1. Can we begin it with two 1's? Yes, but only if we end it with the number eleven, and begin it with the number 1 followed by something in the teens. So our number looks like "1 1x ... 0 ... x 11" for some digit x. So far so good.

                            We can't have x = 1, but x = 2 is OK, so our number becomes "1 12 y ... 0 ... y 2 11" for some digit y. Can y be 1? No, because the y on the right side can only belong to the number one or the number eleven and we've already used those. But it can be 3, provided that on the right it's part of the number 13. So now we have "1 12 3 1z ... 0 ... z 13 2 11," where z is some digit — which can be taken to be 4.

                            Proceeding in this manner we end up with

                            1 12 3 14 5 16 7 18 9 10 19 8 17 6 15 4 13 2 11,

                            also known as 11,231,451,671,891,019,817,615,413,211, or "eleven octillion something."

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

                            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