All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Just Math
The five 3īs (Posted on 2008-07-07) Difficulty: 2 of 5
This is a real story. A long long time ago, based on the "Four fours" problem, I wondered if I could do the same using exactly five 3īs, the restrictions a bit tighter: I could use only the 4 basic math operations, exponentiation, factorial, and all parentheses I may need. Besides, I didnīt disallow me to join two "3īs" to make "33".

Using this, and only this, I succeeded in writing expressions for all integers from 0 to 100.

To narrow your work, since a great number of integers can be easily obtained, can you find expressions for 47, 50, 56, 58, 64, 70, 71, 73, 74, 76, 77, 85, 88, 94, and 95?

See The Solution Submitted by pcbouhid    
Rating: 4.5000 (2 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution geeky computer solution for some values (spoilers present) | Comment 7 of 35 |

The solution is for those mentioned values that don't require exponentiation.

The list shows the RPN form, the algebraic form and the value:

3,3!!,3!/+,3/,3!+           (3+3!!/3!)/3+3!              47 
33,3/,3!,3!*+               33/3+3!*3!                   47
3,3!*,3*,3!,3/+             3*3!*3+3!/3                  56 
3,3!,3**,3!,3/+             3*3!*3+3!/3                  56
3,3!+,3!*,3!,3/+            (3+3!)*3!+3!/3               56
3,3*,3!*,3!,3/+             3*3*3!+3!/3                  56
3,3,3!**,3!,3/+             3*3*3!+3!/3                  56
3,333+,3!/                  (3+333)/3!                   56
333,3+,3!/                  (333+3)/3!                   56
3,3!*,3!!,3!,3*/+           3*3!+3!!/(3!*3)              58 
3,3!*,3!!,3!/,3/+           3*3!+(3!!/3!)/3              58
3,3!*,3!!,3,3!*/+           3*3!+3!!/(3*3!)              58
3,3!*,3!!,3/,3!/+           3*3!+(3!!/3)/3!              58
33,3!*,3!-,3/               (33*3!-3!)/3                 64 
3,3!,3!*,3!*+,3/            (3+3!*3!*3!)/3               73 
3,3!,3!,3!**+,3/            (3+3!*3!*3!)/3               73
3,3/,3!,3!,3!+*+            3/3+3!*(3!+3!)               73
3,3/,3!,3!+,3!*+            3/3+(3!+3!)*3!               73
33,3!!,3!,3*/+              33+3!!/(3!*3)                73
33,3!!,3!/,3/+              33+(3!!/3!)/3                73
33,3!!,3,3!*/+              33+3!!/(3*3!)                73
33,3!!,3/,3!/+              33+(3!!/3)/3!                73
3,3!!,3!,3+/,3!-+           3+3!!/(3!+3)-3!              77 
3,3!!,3!,3+/+,3!-           3+3!!/(3!+3)-3!              77
3,3!!,3,3!+/,3!-+           3+3!!/(3+3!)-3!              77
3,3!!,3,3!+/+,3!-           3+3!!/(3+3!)-3!              77
3,3!!,3,3*/,3!-+            3+3!!/(3*3)-3!               77
3,3!!,3,3*/+,3!-            3+3!!/(3*3)-3!               77
3,3!!,3/,3/,3!-+            3+(3!!/3)/3-3!               77
3,3!!,3/,3/+,3!-            3+(3!!/3)/3-3!               77
3,3!,3!!,3!,3+/--           3-(3!-3!!/(3!+3))            77
3,3!-,3!!,3!,3+/+           3-3!+3!!/(3!+3)              77
3,3!,3!!,3,3!+/--           3-(3!-3!!/(3+3!))            77
3,3!-,3!!,3,3!+/+           3-3!+3!!/(3+3!)              77
3,3!,3!!,3,3*/--            3-(3!-3!!/(3*3))             77
3,3!-,3!!,3,3*/+            3-3!+3!!/(3*3)               77
3,3!,3!!,3/,3/--            3-(3!-(3!!/3)/3)             77
3,3!-,3!!,3/,3/+            3-3!+(3!!/3)/3               77
3,3!!,3/,3!+,3/+            3+(3!!/3+3!)/3               85 
3,3!,3!!,3/+,3/+            3+(3!+3!!/3)/3               85

To find the RPN (vb 5.0):

Private Sub cmdStart_Click()
  FontTransparent = False
  Open "five3s.txt" For Output As #2
  avail = 5
  stackMax = -1
  cm$ = ""
  place
  CurrentX = 1: CurrentY = 1: Print "end"
  Close
End Sub

Sub place()
 CurrentX = 1: CurrentY = 1: Print cm$
 DoEvents
 If Len(cm$) = 0 Then
  cm$ = "3"
  avail = 4
  stack(0) = 3
  stackMax = 0
  place
  stackMax = -1
  cm$ = ""
  avail = 5
 Else
  If avail > 0 Then
   If Right$(cm$, 1) = "3" Then
    cm$ = cm$ + "3"
    stack(0) = 10 * stack(0) + 3
    avail = avail - 1
    place
    cm$ = Left$(cm$, Len(cm$) - 1)
    stack(0) = stack(0) \ 10
    avail = avail + 1
   End If
   cm$ = cm$ + ",3"
   For i = stackMax + 1 To 1 Step -1
    stack(i) = stack(i - 1)
   Next i
   stack(0) = 3
   stackMax = stackMax + 1
   avail = avail - 1
   place
   cm$ = Left$(cm$, Len(cm$) - 2)
   stack(0) = stack(0) \ 10
   avail = avail + 1
   stackMax = stackMax - 1
   For i = 0 To stackMax
    stack(i) = stack(i + 1)
   Next
  End If
  If stackMax > 0 Then
   cm$ = cm$ + "*"
   hs0 = stack(0): hs1 = stack(1)
   stackMax = stackMax - 1
   stack(0) = stack(0) * stack(1)
   For i = 1 To stackMax
    stack(i) = stack(i + 1)
   Next
   place
   cm$ = Left$(cm$, Len(cm$) - 1)
   stackMax = stackMax + 1
   For i = stackMax To 1 Step -1
    stack(i) = stack(i - 1)
   Next i
   stack(0) = hs0: stack(1) = hs1
  
   If stack(0) <> 0 Then
    cm$ = cm$ + "/"
    hs0 = stack(0): hs1 = stack(1)
    stackMax = stackMax - 1
    stack(0) = stack(1) / stack(0)
    For i = 1 To stackMax
     stack(i) = stack(i + 1)
    Next
    place
    cm$ = Left$(cm$, Len(cm$) - 1)
    stackMax = stackMax + 1
    For i = stackMax To 1 Step -1
     stack(i) = stack(i - 1)
    Next i
    stack(0) = hs0: stack(1) = hs1
   End If
  
   cm$ = cm$ + "+"
   hs0 = stack(0): hs1 = stack(1)
   stackMax = stackMax - 1
   stack(0) = stack(1) + stack(0)
   For i = 1 To stackMax
    stack(i) = stack(i + 1)
   Next
   place
   cm$ = Left$(cm$, Len(cm$) - 1)
   stackMax = stackMax + 1
   For i = stackMax To 1 Step -1
    stack(i) = stack(i - 1)
   Next i
   stack(0) = hs0: stack(1) = hs1
  
   cm$ = cm$ + "-"
   hs0 = stack(0): hs1 = stack(1)
   stackMax = stackMax - 1
   stack(0) = stack(1) - stack(0)
   For i = 1 To stackMax
    stack(i) = stack(i + 1)
   Next
   place
   cm$ = Left$(cm$, Len(cm$) - 1)
   stackMax = stackMax + 1
   For i = stackMax To 1 Step -1
    stack(i) = stack(i - 1)
   Next i
   stack(0) = hs0: stack(1) = hs1
  
   If (stack(0) < 18 And stack(0) > 2 Or stack(0) = 0) And (stack(0) - Int(stack(0)) < 0.0000001 Or stack(0) - Int(stack(0) + 0.5) > 0.9999999) Then
    hs0 = stack(0)
    cm$ = cm$ + "!"
    stack(0) = fact(stack(0))
    place
    stack(0) = hs0
    cm$ = (Left$(cm$, Len(cm$) - 1))
   End If
  End If
  If avail = 0 And stackMax = 0 Then
   If stack(0) - Int(stack(0)) < 0.0000001 Or stack(0) - Int(stack(0) + 0.5) > 0.9999999 Then
    s0 = Int(stack(0) + 0.5)
    If s0 >= 0 And s0 <= 100 Then
     printVal = Right("   " + Str(s0), 3)
     Print #2, printVal, cm$
    End If
   End If
  End If
 End If
End Sub
Function fact(x)
 f = 1
 For i = 1 To x
  f = f * i
 Next
 fact = f
End Function

and to convert to algebraid notation (QB):

DECLARE SUB checkParen (s$, ops$)
OPEN "five3s.txt" FOR INPUT AS #1
OPEN "five3sal.TXT" FOR OUTPUT AS #2
DO
 LINE INPUT #1, l$
 v$ = LEFT$(l$, 14): l$ = MID$(l$, 15)
 v = VAL(v$)
 SELECT CASE (v)
   CASE 47, 50, 56, 58, 64, 70, 71, 73, 74, 76, 77, 85, 88, 94, 95
 stackLevel = 0

 bld$ = ""
 FOR i = 1 TO LEN(l$)
  c$ = MID$(l$, i, 1)
  ix = INSTR("0123456789", c$)
  IF ix THEN
   bld$ = bld$ + c$
   stkRaise = 1
  ELSE
   IF stkRaise THEN
    stackLevel = stackLevel + 1
    stack$(stackLevel) = bld$
    stkRaise = 0
    bld$ = ""
   END IF
   SELECT CASE c$
    CASE "+"
     stackLevel = stackLevel - 1
     stack$(stackLevel) = stack$(stackLevel) + "+" + stack$(stackLevel + 1)
    CASE "-"
     h2$ = stack$(stackLevel)
     checkParen h2$, "+-"
     stackLevel = stackLevel - 1
     h1$ = stack$(stackLevel)
     stack$(stackLevel) = h1$ + "-" + h2$
    CASE "*"
     h2$ = stack$(stackLevel)
     checkParen h2$, "+-"
     stackLevel = stackLevel - 1
     h1$ = stack$(stackLevel)
     checkParen h1$, "+-/"
     stack$(stackLevel) = h1$ + "*" + h2$
    CASE "/"
     h2$ = stack$(stackLevel)
     checkParen h2$, "+-/*"
     stackLevel = stackLevel - 1
     h1$ = stack$(stackLevel)
     checkParen h1$, "+-/"
     stack$(stackLevel) = h1$ + "/" + h2$
    CASE "^"
     h2$ = stack$(stackLevel)
     checkParen h2$, "+-*/"
     stackLevel = stackLevel - 1
     h1$ = stack$(stackLevel)
     checkParen h1$, "+-*/"
     stack$(stackLevel) = h1$ + "^" + h2$
    CASE "!"
     h2$ = stack$(stackLevel)
     checkParen h2$, "+-*/"
     stack$(stackLevel) = h2$ + "!"
   END SELECT
  END IF
 NEXT
 IF stackLevel <> 1 THEN
      REM
 END IF
 PRINT l$, stack$(1), v: PRINT #2, l$, stack$(1), v
 END SELECT
LOOP UNTIL EOF(1)
CLOSE

SUB checkParen (s$, ops$)
 pLevel = 0
 flag = 0
 FOR i = 1 TO LEN(s$)
   SELECT CASE MID$(s$, i, 1)
     CASE "("
      pLevel = pLevel + 1
     CASE ")"
      pLevel = pLevel - 1
     CASE ELSE
      IF pLevel = 0 AND INSTR(ops$, MID$(s$, i, 1)) THEN flag = 1: EXIT FOR
   END SELECT
 NEXT i
 IF flag THEN s$ = "(" + s$ + ")"
END SUB

 


  Posted by Charlie on 2008-07-07 14:47:24
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (5)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information