 All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars  perplexus dot info  A piece of pie (Posted on 2010-12-07) Let N be defined by N=> 3*1*4*1*5*9*2, where each asterisk may be replaced by any basic arithmetic sign ( +, - ,* ,/) and => means that the result is obtained by calculating sequentially from left to right.
Examples: 3+1+4+1+5+9+2=>25; 3+1-4+1-5+9-2=>3; 3*1-4*1-5+9-2=>1 etc.

How many distinct positive integer results can be obtained?
What is the lowest positive integer that cannot be obtained?
What positive integer claims the highest quantity of distinct expressions?
Rem: No brackets allowed.

 No Solution Yet Submitted by Ady TZIDON No Rating Comments: ( Back to comment list | You must be logged in to post comments.) computer solution | Comment 3 of 5 | DEFDBL A-Z

OPEN "piecpi.txt" FOR OUTPUT AS #2

FOR a = 1 TO 4
SELECT CASE a
CASE 1
r1 = 3 + 1
CASE 2
r1 = 3 - 1
CASE 3
r1 = 3 * 1
CASE 4
r1 = 3 / 1
END SELECT
FOR b = 1 TO 4
SELECT CASE b
CASE 1
r2 = r1 + 4
CASE 2
r2 = r1 - 4
CASE 3
r2 = r1 * 4
CASE 4
r2 = r1 / 4
END SELECT
FOR c = 1 TO 4
SELECT CASE c
CASE 1
r3 = r2 + 1
CASE 2
r3 = r2 - 1
CASE 3
r3 = r2 * 1
CASE 4
r3 = r2 / 1
END SELECT
FOR d = 1 TO 4
SELECT CASE d
CASE 1
r4 = r3 + 5
CASE 2
r4 = r3 - 5
CASE 3
r4 = r3 * 5
CASE 4
r4 = r3 / 5
END SELECT
FOR e = 1 TO 4
SELECT CASE e
CASE 1
r5 = r4 + 9
CASE 2
r5 = r4 - 9
CASE 3
r5 = r4 * 9
CASE 4
r5 = r4 / 9
END SELECT
FOR f = 1 TO 4
SELECT CASE f
CASE 1
r6 = r5 + 2
CASE 2
r6 = r5 - 2
CASE 3
r6 = r5 * 2
CASE 4
r6 = r5 / 2
END SELECT

tst = ABS(r6 - INT(r6))
IF r6 > 0 THEN
IF tst / ABS(r6) < .000000001# AND r6 > 0 THEN
SELECT CASE a
CASE 1
PRINT #2, "3+1";
CASE 2
PRINT #2, "3-1";
CASE 3
PRINT #2, "3*1";
CASE 4
PRINT #2, "3/1";
END SELECT
SELECT CASE b
CASE 1
PRINT #2, "+4";
CASE 2
PRINT #2, "-4";
CASE 3
PRINT #2, "*4";
CASE 4
PRINT #2, "/4";
END SELECT
SELECT CASE c
CASE 1
PRINT #2, "+1";
CASE 2
PRINT #2, "-1";
CASE 3
PRINT #2, "*1";
CASE 4
PRINT #2, "/1";
END SELECT
SELECT CASE d
CASE 1
PRINT #2, "+5";
CASE 2
PRINT #2, "-5";
CASE 3
PRINT #2, "*5";
CASE 4
PRINT #2, "/5";
END SELECT
SELECT CASE e
CASE 1
PRINT #2, "+9";
CASE 2
PRINT #2, "-9";
CASE 3
PRINT #2, "*9";
CASE 4
PRINT #2, "/9";
END SELECT
SELECT CASE f
CASE 1
PRINT #2, "+2";
CASE 2
PRINT #2, "-2";
CASE 3
PRINT #2, "*2";
CASE 4
PRINT #2, "/2";
END SELECT
PRINT #2, USING "#######.############"; r6
END IF
END IF

NEXT
NEXT
NEXT
NEXT
NEXT
NEXT
CLOSE 2

The list produced was sorted on the total column, and then a second program was used to read this file in and summarize the numbers for each total:

OPEN "piecpi.txt" FOR INPUT AS #1
OPEN "piecpict.txt" FOR OUTPUT AS #2

DO
LINE INPUT #1, l\$
ix1 = INSTR(l\$, " ")
nw\$ = MID\$(l\$, ix1)
ix2 = INSTR(nw\$, ".")
n\$ = LTRIM\$(LEFT\$(nw\$, ix2 - 1))
IF n\$ <> prev\$ THEN
IF prev\$ > "" THEN PRINT #2, prev\$, ct
ct = 1
prev\$ = n\$
ELSE
ct = ct + 1
END IF

LOOP UNTIL EOF(1)
PRINT #2, prev\$, ct
CLOSE

Its output begins:

`1              33 2              60 3              12 4              29 5              21 6              48 7              34 8              29 9              21 10             30 11             34 12             14 13             26 14             21 15             13 16             20 17             9 18             40 19             14 20             19 21             5 22             22 23             18 24             30 25             15 26             9 27             11 28             23 29             22 30             5 31             2 32             11 33             9 34             12 36             11 37             6 38             14 40             6 ...`

from which you can see that 35 is the first missing number and 39 is the next.

In all, there are 160 lines to this file of counts, and so 160 distinct positive integers obtainable. By sorting it on the count column in descending order, we can see that 2 is the most common outcome, followed by 6, etc.:

`2              60 6              48 18             40 11             34 7              34 1              33 10             30 24             30 8              29 4              29 13             26 28             23 54             23 22             22 29             22 14             21 9              21 5              21 16             20 42             20 20             19 52             18 23             18 47             15 25             15 72             14 38             14 19             14 12             14 15             13 34             12 3              12 27             11 36             11 32             11 88             10 ...`

 Posted by Charlie on 2010-12-07 19:23:34 Please log in:

 Search: Search body:
Forums (1)