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. Riddle me this

Riddle me this

Scheduled Pinned Locked Moved The Lounge
question
9 Posts 5 Posters 0 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.
  • C Offline
    C Offline
    Colborne_Greg
    wrote on last edited by
    #1

    If you can only do 2 things: Add 25 to a number or subtract 6 from that number; is it possible to obtain any number? And how could you get the number 20 starting from 0?

    L V 2 Replies Last reply
    0
    • C Colborne_Greg

      If you can only do 2 things: Add 25 to a number or subtract 6 from that number; is it possible to obtain any number? And how could you get the number 20 starting from 0?

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

      x = 0;
      while (x != n) // n = 20, for example
      {
      x += 25; // x + 25 - 6 - 6 - 6 - 6 = x + 1
      x -= 6; // loop will iterate n times to reach any positive number
      x -= 6;
      x -= 6;
      x -= 6;
      }

      Wow. That was hard. I just fell out of bed and still am sleeping to 90%. And, of course, you can also unroll the loop 20 times if it must be the primitive solution.

      The language is JavaScript. that of Mordor, which I will not utter here
      I hold an A-7 computer expert classification, Commodore. I'm well acquainted with Dr. Daystrom's theories and discoveries. The basic design of all our ship's computers are JavaScript.

      C 1 Reply Last reply
      0
      • L Lost User

        x = 0;
        while (x != n) // n = 20, for example
        {
        x += 25; // x + 25 - 6 - 6 - 6 - 6 = x + 1
        x -= 6; // loop will iterate n times to reach any positive number
        x -= 6;
        x -= 6;
        x -= 6;
        }

        Wow. That was hard. I just fell out of bed and still am sleeping to 90%. And, of course, you can also unroll the loop 20 times if it must be the primitive solution.

        The language is JavaScript. that of Mordor, which I will not utter here
        I hold an A-7 computer expert classification, Commodore. I'm well acquainted with Dr. Daystrom's theories and discoveries. The basic design of all our ship's computers are JavaScript.

        C Offline
        C Offline
        Colborne_Greg
        wrote on last edited by
        #3

        Try to reach this answer in the least number of steps. Try the human asnwer

        L N 2 Replies Last reply
        0
        • C Colborne_Greg

          Try to reach this answer in the least number of steps. Try the human asnwer

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

          The loop contains 5 operation and iterates 20 times, so we would have 100 operations. Fine. 0 + 25 - 6 + 25 - 6 - 6 - 6 - 6 = 20. Or you could try to find the solutions for a x 25 + b x -6 = n for any given n. For n = 20 a would be 2 and b would be 5.

          Colborne_Greg wrote:

          Try the human asnwer

          That's hard, even if I have to wait another 100 years before they finally send a ship to pick me up.

          The language is JavaScript. that of Mordor, which I will not utter here
          I hold an A-7 computer expert classification, Commodore. I'm well acquainted with Dr. Daystrom's theories and discoveries. The basic design of all our ship's computers are JavaScript.

          C 1 Reply Last reply
          0
          • L Lost User

            The loop contains 5 operation and iterates 20 times, so we would have 100 operations. Fine. 0 + 25 - 6 + 25 - 6 - 6 - 6 - 6 = 20. Or you could try to find the solutions for a x 25 + b x -6 = n for any given n. For n = 20 a would be 2 and b would be 5.

            Colborne_Greg wrote:

            Try the human asnwer

            That's hard, even if I have to wait another 100 years before they finally send a ship to pick me up.

            The language is JavaScript. that of Mordor, which I will not utter here
            I hold an A-7 computer expert classification, Commodore. I'm well acquainted with Dr. Daystrom's theories and discoveries. The basic design of all our ship's computers are JavaScript.

            C Offline
            C Offline
            Colborne_Greg
            wrote on last edited by
            #5

            Two quarters and five half dozens. The solution 50 cents for case of eggs.

            1 Reply Last reply
            0
            • C Colborne_Greg

              If you can only do 2 things: Add 25 to a number or subtract 6 from that number; is it possible to obtain any number? And how could you get the number 20 starting from 0?

              V Offline
              V Offline
              Vivi Chellappa
              wrote on last edited by
              #6

              Add 25 to 0 eight times. You get 200. Subtract 6 thirty times. You are left with 20.

              1 Reply Last reply
              0
              • C Colborne_Greg

                Try to reach this answer in the least number of steps. Try the human asnwer

                N Offline
                N Offline
                Nagy Vilmos
                wrote on last edited by
                #7

                Simples:

                int x = 0;
                int n = 21;
                while (x != n)
                {
                while (x < n)
                {
                x+=25; // too low goes up
                }
                while (x > n)
                {
                x-=6; // too high goes down
                }
                }
                // Goldilocks, just right.

                speramus in juniperus

                C _ 2 Replies Last reply
                0
                • N Nagy Vilmos

                  Simples:

                  int x = 0;
                  int n = 21;
                  while (x != n)
                  {
                  while (x < n)
                  {
                  x+=25; // too low goes up
                  }
                  while (x > n)
                  {
                  x-=6; // too high goes down
                  }
                  }
                  // Goldilocks, just right.

                  speramus in juniperus

                  C Offline
                  C Offline
                  Colborne_Greg
                  wrote on last edited by
                  #8

                  Cool

                  1 Reply Last reply
                  0
                  • N Nagy Vilmos

                    Simples:

                    int x = 0;
                    int n = 21;
                    while (x != n)
                    {
                    while (x < n)
                    {
                    x+=25; // too low goes up
                    }
                    while (x > n)
                    {
                    x-=6; // too high goes down
                    }
                    }
                    // Goldilocks, just right.

                    speramus in juniperus

                    _ Offline
                    _ Offline
                    _Damian S_
                    wrote on last edited by
                    #9

                    Nagy Vilmos wrote:

                    int x = 0; int n = 21; while (x != n)

                    Errrm... you were meant to stop at 20. ;-)

                    Quad skating his way through the world since the early 80's... Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

                    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