Expressions for Bethe

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. We receive a few cents from each purchase.   Thanks.


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

Problem Description

Given a set of integers and a target value, construct an expression by inserting arithmetic operators (+, -, x, ) into the set of integers without rearranging them so that the value of the expression equals the target value.  

Background & Techniques

This is a generalized extension of the Expressions100 and  Expressions2002 programs previously posted.  This version will search for solutions for any set of digits and  any integer expression value.   It was prompted by a problem posed by a viewer (Using five 9's, form an expression which equals 10).      

Non-programmers are welcome to read on, but may want to skip to the bottom of this page to download executable version of the program.

Expressions2002 generated all 8 digit  base 3 numbers (00000000 to 22222222) to define operators to be inserted into the 8 slots between the 9 given digits.  Operators there were +, x, and concatenation.   ExpressionsForBethe  extends the concept to base 5 numbers (for the four operators and concatenation) and for a variable number of slots (always one less than the number of input digits).   

I handled the "order of operations" problem in Expressions2002 by introducing a "stack" to hold terms until we know it is OK to evaluate them.   I described the process in some detail there, so i won't repeat it here.  The division operation here needed tests so that we don't try to divide b y zero and to make sure that the quotient is an exact integer (divisor divides the dividend exactly).     

Running/Exploring the Program 

bulletBrowse source extract
bulletDownload source
bulletDownload  executable

Suggestions for Further Explorations

Allow parentheses
Allow user control of allowable set of operators.

 

Original Date: June 11, 2004 

Modified: February 18, 2016

 
  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2017, Gary Darby    All rights reserved.