Count the coins/0-1: Difference between revisions

Content added Content deleted
m (Replaced "collect" with "toSeq" (equivalent but maybe more elegant.)
Line 357: Line 357:


Using a solver object rather than global variables.
Using a solver object rather than global variables.
<lang Nim>import math, strutils, sugar
<lang Nim>import math, sequtils, strutils


type Solver = object
type Solver = object
Line 383: Line 383:
echo "Sum $# from coins $#".format(want, coins.join(" "))
echo "Sum $# from coins $#".format(want, coins.join(" "))
var solver = Solver(want: want, width: width)
var solver = Solver(want: want, width: width)
var rindices = collect(for i in 0..coins.high: i)
var rindices = toSeq(0..coins.high)
solver.count(0, newSeq[int](), @coins, newSeq[int](), rindices)
solver.count(0, newSeq[int](), @coins, newSeq[int](), rindices)
if solver.count1 > 10:
if solver.count1 > 10: