### 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.

Mensa® Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

(Hint: If you can wait, current year calendars are usually on sale in January.)

### Contact

 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).

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).

### Suggestions for Further Explorations

 Allow parentheses Allow user control of allowable set of operators.

 Original Date: June 11, 2004 Modified: July 29, 2017