24 game/Solve: Difference between revisions

Content added Content deleted
No edit summary
mNo edit summary
Line 4,608: Line 4,608:


{{trans|Python Succinct}}
{{trans|Python Succinct}}
{{works with|Nim Compiler|0.19.4}}


<lang nim>import algorithm, sequtils, strformat
<lang nim>import algorithm, sequtils, strformat
Line 4,620: Line 4,621:
const Ops = @[opAdd, opSub, opMul, opDiv]
const Ops = @[opAdd, opSub, opMul, opDiv]


proc opr(o: Operation, a, b: float): float =
func opr(o: Operation, a, b: float): float =
case o
case o
of opAdd: a + b
of opAdd: a + b
Line 4,627: Line 4,628:
of opDiv: a / b
of opDiv: a / b


proc solve(nums: array[4, int]): string =
func solve(nums: array[4, int]): string =
func `~=`(a, b: float): bool =
func `~=`(a, b: float): bool =
abs(a - b) <= 1e-5
abs(a - b) <= 1e-5