[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
|
|
Problem DescriptionHere's a puzzle from "Mathematical Bafflers", Angela Dunn, Dover Books:: Using mathematical symbols to modify four fours it is possible to write expressions for all the numbers from 0 to 100. Background & Techniques
The original problem as I interpreted it, was to find an expressions containing
only the four digits 4444,
parentheses, the operators {+, -, *, /, and ^} (Plus, minus, multiply, divide,
and exponential), which
evaluate to all values from 0 to 100. Here are a few of the program's features:
Notes for ProgrammersI enjoy writing programs which stretch the mind solve problems which have no particular need to be solved. This is one such. It led me back to a number of previously written DFF programs and units including the Catalan Numbers program to create a sharable unit, UGetParens with the GetParens function which will generate all possible ways to parenthesize a given expression. I also created UTEvalInt unit defining the TEvalInt class, an integer arithmetic version of our TEval expression evaluator class. The old reliable UCombosV2 library unit provided the TCombo class used to permute the input integers when the users requested that option. I believe that TCombo could also provide the "multiset" permutations we need for the operators .But "just for fun", I decided to use a "counting in Base N" method which used previously other project. For creating arrangements of operators when repeats are allowed, an easy way is to create numbers of base N to permute N operators. If we need M operators, we'll create all M digit numbers of base N. There are NM of them. As a simple example, assume we want to use only the plus and minus operators to insert into the three gaps in a set of 4 variables or constants, (a+b+-c+d, a+b+c-d, etc.) . In this case N=2 and M=3. The 8 (23 ) base 2 numbers (000, 001, 010, 011, 100, 101, 110, 111) represent all possible ways of inserting 3 + and - symbols into a set of 4 variables. As a more complex example, suppose we are using the 4 operators {+, -, *, /} (N=4) and we need sets of 3 operators (M=3) to insert into a set of 4 variables to form expressions of the form "a op b op c op d". Three digit base 4 numbers can map 3 of the 4 operators into the three "op" positions. Our base 4 numbers will look like {000,001, 002, 003, 010, 011, ...320, 321, 322, 333} Since there are 4 choices for each of 3 positions, we have 4x4x4=64 numbers (or arrangements). If we assign each base 4 digit to an operator, we'll have the 64 possible ways to insert operators between the digits to for our expressions. If we map digits {0,1,2,3} to {+. -, *, / } then, for example, the value 320 generates "4 / 4 * 4 + 4". Running/Exploring the Program
Suggestions for Further Explorations
|
[Feedback] [Newsletters (subscribe/view)] [About me]Copyright © 2000-2018, Gary Darby All rights reserved. |