Countdown: Difference between revisions

Description update + Quorum reduction of the number of lines
(→‎{{header|Quorum}}: Replace french variables names with english variables names)
(Description update + Quorum reduction of the number of lines)
Line 28:
;Extra challenge:
 
The brute force algorithm is quite obvious. What is more interesting areis theto find some optimisation heuristics to reduce the number of calculations. For example, a rather interesting computational challenge is to calculate, as fast as possible, all existing solutions (that means 2'764'800 operations) for all possible games (with all the 12013'867'208243 combinations of six numbers out of twenty-four for all 898 possible targets between 101 and 999).
 
 
Line 91:
end
 
if n0 >< n1
resinteger temp = n1 - n0
if n0 >= n1
n1 = endtemp
end
 
if n0 modnot= n1 = 0
res = n0 - n1
numbersNew = cast(List<integer>, numbers2:Copy())
Line 99 ⟶ 105:
return true
end
elseif n1 > n0end
 
res = n1 - n0
if n1n0 mod n0n1 = 0
res = n0 / n1
numbersNew = cast(List<integer>, numbers2:Copy())
numbersNew:Add(res)
if res = target or Solution(target, numbersNew)
output res + " = " + n1n0 + " -/ " + n0n1
return true
end
end
 
if n0 > n1
if n0 mod n1 = 0
res = n0 / n1
numbersNew = cast(List<integer>, numbers2:Copy())
numbersNew:Add(res)
if res = target or Solution(target, numbersNew)
output res + " = " + n0 + " / " + n1
return true
end
end
else
if n1 mod n0 = 0
res = n1 / n0
numbersNew = cast(List<integer>, numbers2:Copy())
numbersNew:Add(res)
if res = target or Solution(target, numbersNew)
output res + " = " + n1 + " / " + n0
return true
end
end
end
Line 137 ⟶ 123:
{{out}}
<pre>
952 = 2380050 /+ 25902
23800902 = 2385022550 -/ 5025
2385022550 = 10650 *+ 22522500
22522500 = 757500 * 3
1067500 = 100 +* 675
456214.0 ms
</pre>
451

edits