Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Programming Puzzle 28 - Alphabet Math?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Programming Puzzle 28 - Alphabet Math?

    Puzzle 28 - Alphabet Math

    Write an xbasic script that will solve this puzzle. Display your answer in a message box on screen.

    In the following math problem substitute numeric digits for the letters.
    Find the three numbers that these words represent.
    You may assume that none of the numbers begin with a zero. However, the number assigned to
    a letter must be the same everywhere that letter appears.

    Code:
        SEND
      + MORE
      -------
       MONEY


    There are numerous valid solutions to this, but only one where MONEY = 10,652.

    What are the values of SEND and MORE that make MONEY = 10,652 ?




    Credit for this puzzle: EasyCalculations.com
    Last edited by Tom Cone Jr; 06-07-2012, 12:30 PM.

  • #2
    Re: Programming Puzzle 28 - Alphabet Math?

    Hi Tom,

    These puzzles beat me to do in Xbasic. I do it the hard way, pen and paper!!!

    How about
    Code:
     CROSS
    +ROADS
    DANGER
    The only clue is S=3 and there are no Zeros.
    Regards
    Keith Hubert
    Alpha Guild Member
    London.
    KHDB Management Systems
    Skype = keith.hubert


    For your day-to-day Needs, you Need an Alpha Database!

    Comment


    • #3
      Re: Programming Puzzle 28 - Alphabet Math?

      Here's a brute-force approach, which surely someone can improve upon. It finds all possible solutions, and is NOT fast - running in the background while I was doing other work, it took over 20 minutes on my system to identify 155 solutions.

      Code:
      '  SEND
      '+ MORE
      '------
      ' MONEY
      'Assume that none of the numbers begin with a zero
      '    therefore neither M nor S may be zero
      
      'Variables to store results
      dim SENDValue			as n
      dim MOREValue			as n
      dim MONEYValue			as n
      
      'start by creating a simple formula by multiplying the digits by their place value
      ' SEND becomes 1000S + 100E + 10N + D
      ' MORE becomes 1000M + 100O + 10R + E
      ' MONEY becomes 10000M + 1000O + 100N + 10E + Y
      dim SENDFormula			as c = "1000*S + 100*E + 10*N + D"
      dim MOREFormula			as c = "1000*M + 100*O + 10*R + E"
      dim MONEYFormula		as c = "10000*M + 1000*O + 100*N + 10*E + Y"
      
      'A simplified formula can also be assembled...
      ' assemble SEND + MORE = MONEY
      '    1000S + 100E + 10N + D + 1000M + 100O + 10R + E = 10000M + 1000O + 100N + 10E + Y
      ' then regroup
      '    1000S + 91E + D + 10R = 9000M + 900O + 90N + Y
      dim AssembledFormula	as c = "1000*S + 91*E + D + 10*R = 9000*M + 900*O + 90*N + Y"
      
      'variables for tracking the values of the individual digits
      dim D					as n
      dim E					as n
      dim M					as n
      dim N					as n
      dim O					as n
      dim R					as n
      dim S					as n
      dim Y					as n
      
      dim Solution			as c = ""
      dim NumSolutionsFound	        as n = 0
      dim ProfessorsTarget	        as n = 10652	'the problem asks specifically about 10652
      dim ProfessorsTargetSol	as c = ""		'will be populated with text to solve the specific case asked about
      dim Timer				as Util::Timer	'see how long it takes to run this, just for curiosity
      
      'quick-and-dirty (SLOW-and-dirty) brute-force approach to just try every combination that satisfies the formula above
      '  simply try digits 0-9 for each individual digit (except M and S, which can only be 1-9)
      '  no attempt is made to ensure that the values of each dgit are unique, since that was not specified in the problem
      for D = 0 to 9
      	for E = 0 to 9
      		for M = 1 to 9 'M cannot be zero
      			for N = 0 to 9
      				for O = 0 to 9
      					for R = 0 to 9
      						for S = 1 to 9 'S cannot be zero
      							for Y = 0 to 9
      								ui_yield() 'keeps the A5 UI responsive while this long-running script is doing its thing
      
      								'if eval(AssembledFormula) 'An eval here makes the code a bit neater, but also runs slower, so use the formula directly for better performance
      								if (1000*S + 91*E + D + 10*R) = (9000*M + 900*O + 90*N + Y)
      									'test was true, solution found
      									NumSolutionsFound = NumSolutionsFound + 1
      									statusbar.Set_Text("Found " + NumSolutionsFound + " solutions so far...")
      
      									SENDValue	= eval(SENDFormula)
      									MOREValue	= eval(MOREFormula)
      									MONEYValue	= eval(MONEYFormula)
      									Solution = Solution + "SEND: " + ltrim(str(SENDValue)) + crlf() + \
      														"MORE: " + ltrim(str(MOREValue)) + crlf() + \
      														"MONEY: " + ltrim(str(MONEYValue)) + crlf() + "------" + crlf()
      									if MONEYValue = ProfessorsTarget
      										'The professor asked specifically about this value
      										ProfessorsTargetSol = "When MONEY is " + ProfessorsTarget + ", SEND is " + SENDValue + " and MORE is " + MOREValue
      									end if
      								end if
      
      							next Y
      						next S
      					next R
      				next O
      			next N
      		next M
      	next E
      next D
      Timer.Stop() 'stop the timer
      
      Solution = "Found " + NumSolutionsFound + " solutions in " + Timer.ElapsedSeconds + " seconds" + \
      			crlf() + "*****************" + "The professor asked specifically about " + ProfessorsTarget + \
      			crlf() + chr(9) + ProfessorsTargetSol + \
      			crlf() + "*****************" + Solution
      showvar(Solution,"Found " + NumSolutionsFound + " Solutions")

      Lenny Forziati
      Vice President, Internet Products and Technical Services
      Alpha Software Corporation

      Comment


      • #4
        Re: Programming Puzzle 28 - Alphabet Math?

        Lenny,

        Very nice! I've shown your xbasic script to the "professor" and he's curious whether your solution assures that values assigned to specific letters in a word are not used by different letters elsewhere. i.e. a value assigned to the letter "E" may not be used by the letter "M", or any other letter of the alphabet in the three words. Otherwise, you'd be changing the alphabetic representation of the puzzle, which the professor says is a no-no. I attempted to persuade him that this limitation was not explicitly stated in the puzzle, but he is adamant. Perhaps this is because he missed his nap this afternoon! But in his cranky condition he insists that this limitation should be inferred from the puzzle as presented.

        Added later ...
        I've shown the professor your results, and he congratulates you on solving the puzzle for the case where MONEY = 10652. He still has a bone to pick with you on some of the other "solutions", but as they're not necessary to solve the original puzzle, I've persuaded him to give you full credit. Nice work! Hope you had fun.
        Last edited by Tom Cone Jr; 06-07-2012, 05:45 PM.

        Comment


        • #5
          Re: Programming Puzzle 28 - Alphabet Math?

          Originally posted by Tom Cone Jr View Post
          Lenny,

          Very nice! I've shown your xbasic script to the "professor" and he's curious whether your solution assures that values assigned to specific letters in a word are not used by different letters elsewhere. i.e. a value assigned to the letter "E" may not be used by the letter "M", or any other letter of the alphabet in the three words. Otherwise, you'd be changing the alphabetic representation of the puzzle, which the professor says is a no-no. I attempted to persuade him that this limitation was not explicitly stated in the puzzle, but he is adamant. Perhaps this is because he missed his nap this afternoon! But in his cranky condition he insists that this limitation should be inferred from the puzzle as presented.
          There's actually a comment in the code specifically explaining that this condition is not checked for since it isn't required, but it is certainly one of the improvements that could be made to what I posted. Depending on the implementation, this checking could also greatly improve the performance of the script (or have almost no impact at all). Others are welcome to use what I provided as a basis to make this improvement and/or any others.

          The professor really should be more careful about what he expects to be inferred though. It would be just as reasonable to infer that the script could stop at the first solution as it would be to infer that no two letters could have the same value, IMHO. He should remember that inferring is essentially assuming, and I hope he knows what assume does

          Lenny Forziati
          Vice President, Internet Products and Technical Services
          Alpha Software Corporation

          Comment


          • #6
            Re: Programming Puzzle 28 - Alphabet Math?

            Originally posted by Lenny Forziati View Post
            There's actually a comment in the code specifically explaining that this condition is not checked for since it isn't required, but it is certainly one of the improvements that could be made to what I posted. Depending on the implementation, this checking could also greatly improve the performance of the script (or have almost no impact at all). Others are welcome to use what I provided as a basis to make this improvement and/or any others.
            I'll even leave a hint to one such implementation: continue. With it, I can cut the 20+ minutes down to 1.5 minutes and get rid of what the professor considers to be extraneous solutions at the same time.

            Lenny Forziati
            Vice President, Internet Products and Technical Services
            Alpha Software Corporation

            Comment


            • #7
              Re: Programming Puzzle 28 - Alphabet Math?

              Lenny,

              I've managed to catch up with the professor before his evening lecture and he's unpersuaded. Instead, he says that if there's any ambiguity in the puzzle its the fault of me, your humble servant, and can hardly be his fault. Academics! What are you gonna do with them!

              Thanks for planting a few useful clues of your own. Let's see if anyone else will take a crack at this.

              Comment


              • #8
                Re: Programming Puzzle 28 - Alphabet Math?

                So um... can you send more money please?
                Attached Files
                Andrew

                Comment


                • #9
                  Re: Programming Puzzle 28 - Alphabet Math?

                  Andy, very nice! Your solution runs quickly. The professor is impressed that you solved this by working backwards from the clues that were furnished in the puzzle.

                  good work!

                  Comment


                  • #10
                    Re: Programming Puzzle 28 - Alphabet Math?

                    Here is my solution. I stuck to the very basics of what was asked.

                    Code:
                    'Date Created: 10-Jun-2012 02:14:16 PM
                    'Last Updated: 10-Jun-2012 02:47:19 PM
                    'Created By  : spilon
                    'Updated By  : spilon
                    'Puzzle 28 - Alphabet Math
                    'Write an xbasic script that will solve this puzzle. Display your answer in a message box on screen.
                    'In the following math problem substitute numeric digits for the letters. 
                    'Find the three numbers that these words represent. 
                    'You may assume that none of the numbers begin with a zero. However, the number assigned to
                    'a letter must be the same everywhere that letter appears.
                    '
                    'Code:
                    '    SEND
                    '  + MORE
                    '  -------
                    '   MONEY
                    '
                    'There are numerous valid solutions to this, but only one where MONEY = 10,652.
                    'What are the values of SEND and MORE that make MONEY = 10,652 ?
                    'Credit for this puzzle: EasyCalculations.com
                    
                    'Given: M-O-N-E-Y = 1-0-6-5-2
                    dim nMONEY as n = 10652
                    'Given: only one possible solution for previous given (i.e., not asked to prove only one solution)
                    'Assuming: digits unique for each letter
                    'Thus: S-E-N-D = ?-5-6-?
                    dim nSEND as n
                    'Thus: M-O-R-E = 1-0-?-5
                    dim nMORE as n
                    
                    'With unique values for each letter, R = 3, 4, 7, 8 or 9
                    'Thus: M-O-R-E = 1-0-3-5 or  1-0-4-5 or  1-0-7-5 or  1-0-8-5 or 1-0-9-5
                    
                    'Challange: look for occurance when nMONEY - nMORE has pattern ?-5-6-?
                    
                    for nMORE = 1035 to 1095 step 10
                    	'skip these values, as not part of check
                    	if .not. inlist(nMORE,1055,1065) then
                    		if right(left(ut(str(nMONEY - nMORE)),3),2) = "56" then
                    			'we found our match
                    			ui_msg_box("Send More Money",chr(9) + "Send" + chr(9) + (nMONEY - nMORE) + crlf() + "+" + chr(9) + "More" + chr(9) + nMore + crlf() + "_____________________________" + chr(9) + crlf() + "=" +  chr(9) + "Money" + chr(9) + nMONEY)
                    			exit for
                    		end if
                    	end if
                    	'if we are still here, go to next number
                    next nMORE
                    Stephen Pilon
                    Associate Librarian
                    Christendom College

                    Comment


                    • #11
                      Re: Programming Puzzle 28 - Alphabet Math?

                      Very nice, Stephen!

                      I woke the "professor" from his Sunday afternoon nap to have a look at your solution. He was impressed with your use of the INLIST() function to exclude values that are disqualified by the puzzle's terms. He had "forgotten" that this function could handle numeric data in the "list". Your use of the function was sweet, however, he thought an explanatory comment on the list items themselves might prove useful six months from now!

                      The Professor's "eyes crossed" when he tried to decipher line 39 where you say:
                      Code:
                      right(left(ut(str(nMONEY - nMORE)),3),2) = "56"
                      Your expression works just fine, but the professor suggests you look to SUBSTR() to simplify the expression.

                      Congratulations for coming up with a solution that runs so quickly.

                      Comment

                      Working...
                      X