Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • 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
Code Project
  1. Home
  2. The Lounge
  3. Four fours

Four fours

Scheduled Pinned Locked Moved The Lounge
htmltutoriallearning
20 Posts 11 Posters 2 Views 1 Watching
  • 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.
  • Greg UtasG Greg Utas

    Did that route in a hired car in 2003. My VP of Engineering (a Sri Lankan Tamil) wanted to visit Chamundi's temple, so we made a day trip of it and also visited the Mysore Palace. Both impressive.

    Robust Services Core | Software Techniques for Lemmings | Articles
    The fox knows many things, but the hedgehog knows one big thing.

    V Offline
    V Offline
    Vikram A Punathambekar
    wrote on last edited by
    #7

    Kind of unusual to hear a Canadian has done that trip, and that too by road! :-D I've never done it by road but I've taken the train, just once.

    Cheers, Vikram.

    L 1 Reply Last reply
    0
    • B BillWoodruff

      imho, there is nothing of educational value in this puzzle. By the way, i've been on that train (1976); scenery's too nice to miss.

      «The mind is not a vessel to be filled but a fire to be kindled» Plutarch

      A Offline
      A Offline
      Amarnath S
      wrote on last edited by
      #8

      More of recreational value, something like a mathematical excursion.

      1 Reply Last reply
      0
      • V Vikram A Punathambekar

        Kind of unusual to hear a Canadian has done that trip, and that too by road! :-D I've never done it by road but I've taken the train, just once.

        Cheers, Vikram.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #9

        I also did the round trip by road a few years ago, but in a taxi. I would never drive myself on those roads.

        1 Reply Last reply
        0
        • A Amarnath S

          I teach high school maths to a child, and yesterday, there was some spare time as it was raining outside, and he could not head back home. So, I opened my old book of math puzzles and gave him some puzzles. One puzzle is quite interesting, and is said to have occupied an acquaintance over a two-and-a-half hour train journey from Mysore to Bangalore, two cities in Southern part of India separated by about 150 km. The puzzle goes like this: Four Fours Express any number between 1 and 100 in terms of four 4s, and mathematical symbols, + - x / . .4-dot ! sqrt, etc. For example, 1 = (4 + 4)/(4 + 4) 4 = 4 / sqrt(4) + 4 / sqrt(4) 12 = (4!/4) + (4!/4) 36 = (4!/4) x (4!/4) 45 = 44 + 4/4 100 = (4/.4) x (4/.4) Can you attempt to fill in the other numbers from 1 to 100. Some numbers have non-unique solutions. One challenge here is to find HTML symbols to express the numbers. For example, .444444... is expressed as .4-dot (with the dot on top) - so this fraction 4/9 is expressed as .4-dot, with only one 4 being used. Also, expressing square root needs a unicode symbol in HTML.

          J Offline
          J Offline
          jmaida
          wrote on last edited by
          #10

          16=4+4+4+4 88 = 44+44 2=4/4+4/4 4=4+4*0+4*0+4*0 ...

          A 1 Reply Last reply
          0
          • J jmaida

            16=4+4+4+4 88 = 44+44 2=4/4+4/4 4=4+4*0+4*0+4*0 ...

            A Offline
            A Offline
            Amarnath S
            wrote on last edited by
            #11

            Last one - cannot use the number 0 in the expression.

            J 1 Reply Last reply
            0
            • A Amarnath S

              Last one - cannot use the number 0 in the expression.

              J Offline
              J Offline
              jmaida
              wrote on last edited by
              #12

              Ok 32=4*4+4*4 36=4!+4+4+4 56=4!+4!+4+4 76=4!+4!+4!+4 96=4!+4!+4!+4!

              1 Reply Last reply
              0
              • A Amarnath S

                I teach high school maths to a child, and yesterday, there was some spare time as it was raining outside, and he could not head back home. So, I opened my old book of math puzzles and gave him some puzzles. One puzzle is quite interesting, and is said to have occupied an acquaintance over a two-and-a-half hour train journey from Mysore to Bangalore, two cities in Southern part of India separated by about 150 km. The puzzle goes like this: Four Fours Express any number between 1 and 100 in terms of four 4s, and mathematical symbols, + - x / . .4-dot ! sqrt, etc. For example, 1 = (4 + 4)/(4 + 4) 4 = 4 / sqrt(4) + 4 / sqrt(4) 12 = (4!/4) + (4!/4) 36 = (4!/4) x (4!/4) 45 = 44 + 4/4 100 = (4/.4) x (4/.4) Can you attempt to fill in the other numbers from 1 to 100. Some numbers have non-unique solutions. One challenge here is to find HTML symbols to express the numbers. For example, .444444... is expressed as .4-dot (with the dot on top) - so this fraction 4/9 is expressed as .4-dot, with only one 4 being used. Also, expressing square root needs a unicode symbol in HTML.

                M Offline
                M Offline
                mdblack98
                wrote on last edited by
                #13

                Since this is "codeproject" my train trip was short. Took about 15 minutes to get the 1st order solution in C. Yes...I know it's simplistic....but a good exercise nonetheless. Obviously could be improved for all the special cases....could obviously compute squares, square roots, factorials, etc and start from the largest of those to reduce the value. I'll leave that exercise for others. In this code just change the modulus value to whatever you want and you'll get all the 1st order solutions. #include int modulus = 5; void do4(int n) { int mod = n % modulus; int i, j; printf("%d=", n); for (i = modulus; i <= n; i += modulus) { if (i > modulus) { printf("+"); } printf("%d", modulus); } for (j = 0; j < mod; ++j) { if (i != modulus) { printf("+"); } printf("(%d/%d)", modulus, modulus); } printf("\n"); } void main(void) { int i; for (i = 1; i <= 100; ++i) { do4(i); } }

                A H 2 Replies Last reply
                0
                • M mdblack98

                  Since this is "codeproject" my train trip was short. Took about 15 minutes to get the 1st order solution in C. Yes...I know it's simplistic....but a good exercise nonetheless. Obviously could be improved for all the special cases....could obviously compute squares, square roots, factorials, etc and start from the largest of those to reduce the value. I'll leave that exercise for others. In this code just change the modulus value to whatever you want and you'll get all the 1st order solutions. #include int modulus = 5; void do4(int n) { int mod = n % modulus; int i, j; printf("%d=", n); for (i = modulus; i <= n; i += modulus) { if (i > modulus) { printf("+"); } printf("%d", modulus); } for (j = 0; j < mod; ++j) { if (i != modulus) { printf("+"); } printf("(%d/%d)", modulus, modulus); } printf("\n"); } void main(void) { int i; for (i = 1; i <= 100; ++i) { do4(i); } }

                  A Offline
                  A Offline
                  Amarnath S
                  wrote on last edited by
                  #14

                  Great!

                  1 Reply Last reply
                  0
                  • B BillWoodruff

                    imho, there is nothing of educational value in this puzzle. By the way, i've been on that train (1976); scenery's too nice to miss.

                    «The mind is not a vessel to be filled but a fire to be kindled» Plutarch

                    B Offline
                    B Offline
                    B Alex Robinson
                    wrote on last edited by
                    #15

                    A variant using the four digits, 1 9 7 and 2, in order, was educational to me. Took a few minutes to write a BASIC program to generate and evaluate random Polish notation expressions. The program took days to generate almost all of 1..100 on a time-shared mini-computer. When one of my kids had a similar assignment in school, I wrote the program again in C for modern hardware. Ran instantaneously. That program taught me that computers can solve problems without human super-skills being needed.

                    1 Reply Last reply
                    0
                    • M mdblack98

                      Since this is "codeproject" my train trip was short. Took about 15 minutes to get the 1st order solution in C. Yes...I know it's simplistic....but a good exercise nonetheless. Obviously could be improved for all the special cases....could obviously compute squares, square roots, factorials, etc and start from the largest of those to reduce the value. I'll leave that exercise for others. In this code just change the modulus value to whatever you want and you'll get all the 1st order solutions. #include int modulus = 5; void do4(int n) { int mod = n % modulus; int i, j; printf("%d=", n); for (i = modulus; i <= n; i += modulus) { if (i > modulus) { printf("+"); } printf("%d", modulus); } for (j = 0; j < mod; ++j) { if (i != modulus) { printf("+"); } printf("(%d/%d)", modulus, modulus); } printf("\n"); } void main(void) { int i; for (i = 1; i <= 100; ++i) { do4(i); } }

                      H Offline
                      H Offline
                      Harald M
                      wrote on last edited by
                      #16

                      Four fours! (not arbitrarily many)

                      M 1 Reply Last reply
                      0
                      • H Harald M

                        Four fours! (not arbitrarily many)

                        M Offline
                        M Offline
                        mdblack98
                        wrote on last edited by
                        #17

                        It works for four fours. But this is "Code Project" and writing a routine to do just that one example is no fun.

                        H 1 Reply Last reply
                        0
                        • M mdblack98

                          It works for four fours. But this is "Code Project" and writing a routine to do just that one example is no fun.

                          H Offline
                          H Offline
                          Harald M
                          wrote on last edited by
                          #18

                          The output, after repairing a small bug - condition in 2nd loop is i != modulus || j > 0:

                          1=(5/5)
                          2=(5/5)+(5/5)
                          3=(5/5)+(5/5)+(5/5)
                          4=(5/5)+(5/5)+(5/5)+(5/5)
                          5=5
                          6=5+(5/5)

                          etc. None of these lines has five fives, so this does not solve the problem. Running it with modulus 4, one gets:

                          1=(4/4)
                          2=(4/4)+(4/4)
                          3=(4/4)+(4/4)+(4/4)
                          4=4
                          5=4+(4/4)

                          etc Here, only the solution for 2 has four fours, all others are not solutions (two fours, six fours, one four, three fours, ...). So how does this "work for four fours"?

                          M 1 Reply Last reply
                          0
                          • H Harald M

                            The output, after repairing a small bug - condition in 2nd loop is i != modulus || j > 0:

                            1=(5/5)
                            2=(5/5)+(5/5)
                            3=(5/5)+(5/5)+(5/5)
                            4=(5/5)+(5/5)+(5/5)+(5/5)
                            5=5
                            6=5+(5/5)

                            etc. None of these lines has five fives, so this does not solve the problem. Running it with modulus 4, one gets:

                            1=(4/4)
                            2=(4/4)+(4/4)
                            3=(4/4)+(4/4)+(4/4)
                            4=4
                            5=4+(4/4)

                            etc Here, only the solution for 2 has four fours, all others are not solutions (two fours, six fours, one four, three fours, ...). So how does this "work for four fours"?

                            M Offline
                            M Offline
                            mdblack98
                            wrote on last edited by
                            #19

                            I didn't program the entire solution...left that for others to do. One could make the necessary change to solve the X/Y problem of trying to get 5 5's or 3 5's or such an arbitrary combination. I was just demonstrating the "let's use 4's" to solve the values. That's why I said there needed to be more work to do the special cases of "only 4" or "only X" values. You eight need to increase or decrease the # of terms so is a bit more challenging.

                            H 1 Reply Last reply
                            0
                            • M mdblack98

                              I didn't program the entire solution...left that for others to do. One could make the necessary change to solve the X/Y problem of trying to get 5 5's or 3 5's or such an arbitrary combination. I was just demonstrating the "let's use 4's" to solve the values. That's why I said there needed to be more work to do the special cases of "only 4" or "only X" values. You eight need to increase or decrease the # of terms so is a bit more challenging.

                              H Offline
                              H Offline
                              Harald M
                              wrote on last edited by
                              #20

                              Ok - fine :-) In other words, what you did does not take any useful step in any sensible direction for solving the problem :-D For this, one would need to create all possible expression trees fulfilling the stated properties (e.g., exactly four leaves with constant 4, only the given operator node types) and collecting the trees and their expression results. A suitable pruning condition could prevent creation of trees definitely not yielding results in {1...100} (although I don't see what a simple pruning condition would look like; maybe two stacked exponentations can always be excluded* or thereabouts). * Not true: 4^(4^(4-4)) is a valid solution for value 4, and (4^4)^(4-4) is a valid solution for value 1.

                              1 Reply Last reply
                              0
                              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
                              • World
                              • Users
                              • Groups