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

Home > Numbers
Divide et impera (Posted on 2015-08-18) Difficulty: 2 of 5
Divide the set of integers from 1 to 15 into two subsets A & B,
so that the sum of the numbers in A equals the product
of the numbers in B.

See The Solution Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution three computer solutions | Comment 1 of 2
a: 1 2 4 6 8 9 10 11 12 13 14 15   b: 3 5 7
a: 2 3 4 5 6 7 8 10 12 13 14 15   b: 1 9 11
a: 2 3 4 5 6 8 9 10 11 12 13 15   b: 1 7 14

from

DefDbl A-Z
Dim crlf$, tot, prod, a(15), b(15)


Private Sub Form_Load()
 Form1.Visible = True
 
 Text1.Text = ""
 crlf = Chr$(13) + Chr$(10)

 tot = 0: prod = 1
 
 addOn 1

 Text1.Text = Text1.Text & crlf & " done"
  
End Sub

Sub addOn(wh)
  a(0) = a(0) + 1
  a(a(0)) = wh: tot = tot + wh
  If wh = 15 Then
  If tot = prod Then
    Text1.Text = Text1.Text & "a:"
    For i = 1 To a(0)
      Text1.Text = Text1.Text & Str(a(i))
    Next
    Text1.Text = Text1.Text & "   b:"
    For i = 1 To b(0)
      Text1.Text = Text1.Text & Str(b(i))
    Next
    Text1.Text = Text1.Text & crlf
  End If
  Else
   addOn wh + 1
  End If
  tot = tot - wh
  a(0) = a(0) - 1
  
  b(0) = b(0) + 1
  b(b(0)) = wh: prod = prod * wh
  If wh = 15 Then
  If tot = prod Then
    Text1.Text = Text1.Text & "a:"
    For i = 1 To a(0)
      Text1.Text = Text1.Text & Str(a(i))
    Next
    Text1.Text = Text1.Text & "   b:"
    For i = 1 To b(0)
      Text1.Text = Text1.Text & Str(b(i))
    Next
    Text1.Text = Text1.Text & crlf
  End If
  Else
    addOn wh + 1
  End If
  prod = prod / wh
  b(0) = b(0) - 1
  
End Sub


  Posted by Charlie on 2015-08-18 12:02:45
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 (11)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

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