Sum to 100: Difference between revisions

Added AutoHotkey
(Added AutoHotkey)
Line 531:
12 -3 -4 +5 -6 +7 +89
-1 +2 -3 +4 +5 +6 +78 +9</pre>
 
=={{header|AutoHotkey}}==
Inspired by https://autohotkey.com/board/topic/149914-five-challenges-to-do-in-an-hour/
<lang AutoHotkey>global Matches:=[]
AllPossibilities100()
for eq, val in matches
res .= eq "`n"
MsgBox % res
return
 
AllPossibilities100(n:=0, S:="") {
if (n = 0) ; First call
AllPossibilities100(n+1, n) ; Recurse
else if (n < 10){
AllPossibilities100(n+1, S ",-" n) ; Recurse. Concatenate S, ",-" and n
AllPossibilities100(n+1, S ",+" n) ; Recurse. Concatenate S, ",+" and n
AllPossibilities100(n+1, S n) ; Recurse. Concatenate S and n
} else { ; 10th level recursion
Loop, Parse, S, CSV ; Total the values of S and check if equal to 100
{
SubS := SubStr(A_LoopField, 2) ; The number portion of A_LoopField
if (A_Index = 1)
Total := A_LoopField
else if (SubStr(A_LoopField, 1, 1) = "+") ; If the first character is + add
Total += SubS
else ; else subtract
Total -= SubS
}
if (Total = 100)
matches[LTrim(LTrim(StrReplace(S, ","), "0"),"+")] := true ; remove leading 0's, +'s and all commas
}
}</lang>
Outputs:<pre>-1+2-3+4+5+6+78+9
1+2+3-4+5+6+78+9
1+2+34-5+67-8+9
1+23-4+5+6+78-9
1+23-4+56+7+8+9
12+3+4+5-6-7+89
12+3-4+5+67+8+9
12-3-4+5-6+7+89
123+4-5+67-89
123+45-67+8-9
123-4-5-6-7+8-9
123-45-67+89</pre>
 
 
=={{header|C sharp|C#}}==
299

edits