Countdown: Difference between revisions
→{{header|Wren}}: Aligned with latest Quorum version - much quicker than before.
m (→{{header|Quorum}}: Remove of one useless test case) |
(→{{header|Wren}}: Aligned with latest Quorum version - much quicker than before.) |
||
Line 464:
{{trans|Quorum}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascript">import "random" for Random
import "./fmt" for Fmt
var countdown // recursive function
countdown = Fn.new { |
if (numbers.count == 1) return false
for (n0 in numbers) {
Line 481 ⟶ 476:
var nums2 = nums1.toList
nums2.remove(n1)
var res =
var numsNew
Fmt.print("$d = $d + $d", res, n0, n1)▼
return true▼
numsNew = nums2.toList
numsNew.add(res)
if (res == target || countdown.call(
Fmt.print("$d = $d
return true
}
res = n1
numsNew = nums2.toList
numsNew.add(res)
if (res == target || countdown.call(
Fmt.print("$d = $d
return true
}
numsNew = nums2.toList
numsNew.add(res)
if (res == target || countdown.call(
Fmt.print("$d = $d
return true
}
}
numsNew = nums2.toList
numsNew.add(res)
if (res == target || countdown.call(
Fmt.print("$d = $d / $d", res, n1, n0)
return true
Line 554 ⟶ 532:
System.print("Target: %(targetList[i])")
var start = System.clock
var done = countdown.call(
System.print("Took %(((System.clock - start) * 1000).round) ms")
if (!done) System.print("No exact solution
System.print()
}</syntaxhighlight>
Line 568 ⟶ 546:
23800 = 23850 - 50
23850 = 225 * 106
106 =
225 =
Took
Using : [100, 75, 50, 25, 6, 3]
Line 576 ⟶ 554:
952 = 23800 / 25
23800 = 23850 - 50
23850 =
106 = 100 + 6
Took
Using : [8, 4, 4, 6, 8, 9]
Target: 594
594 =
Took
Using : [
Target:
Took
</pre>
|