All pastes #170347 Raw Edit

tt

public text v1 · immutable
·published 2006-09-14 15:21 UTC
rendered paste body
Dim Answer$(20,20,20)
;Fill answers
For T1=-10 To 10
	For T2=-10 To 10
		For T3=-10 To 10
			Answer$(T1+10,T2+10,T3+10) = GetAnswer$(T1,T2,T3)
		Next
	Next
Next
		
For a1=-10 To 10
	For a2=-10 To 10
		For a3=-10 To 10
			If (a1<>0) And (a2<>0) And (a3<>0); dont bother with zeros
				If GetAnswer$(a1,a2,a3) Then ;only ask if subset sum=0 exists
					;=============
					;program start
					Print "{"+a1+","+a2+","+a3+"}"
					
					;P=NP
					Print GetAnswer$(a1,a2,a3)+" = 0"
					
					WaitKey
					
					;program end
					;============
				EndIf
			EndIf
		Next
	Next
Next

Function ZeroSum(a1,a2,a3)
	If a1+a2+a3=0 Return 1
End Function

Function GetAnswer$(R1,R2,R3)
	If R1+R2=0 Then Return R1+" + "+R2
	If R1+R3=0 Then Return R1+" + "+R3
	If R2+R3=0 Then Return R2+" + "+R3
	If R1+R2+R3=0 Then Return R1+" + "+R2+" + "+R3
End Function