Minimal steps down to 1: Difference between revisions

Content deleted Content added
Wherrera (talk | contribs)
Wherrera (talk | contribs)
Line 187: Line 187:


=={{header|Julia}}==
=={{header|Julia}}==
Non-recursive solution that is memoized for the count-only portions of the task. When the steps are to be printed, the solution is not memoized in order to list all possible paths of the shortest length (all solutions). Implemented as a generic solution for any functions acting on an integer and taking any range of second arguments, with the goal solution also specifiable. To do so generically, it is also necessary to specify a falure condition, which in the example is falling below 1.
This is a non-recursive solution that is memoized for the count-only portions of the task, but not memoized when all possible solutions are to be listed.

Implemented as a generic solution for any functions acting on an integer and taking any range of second arguments, with the goal solution also specifiable. To do so generically, it is also necessary to specify a failure condition, which in the example is falling below 1.
<lang julia>import Base.print
<lang julia>import Base.print


Line 200: Line 202:
end
end


function Base.print(io::IO, ao::ActionOutcome)
Base.print(io::IO, ao::ActionOutcome) = print(io, "$(ao.act.f) $(ao.act.i) yields $(ao.out)")
print(io, "$(ao.act.f) $(ao.act.i) yields $(ao.out)")
end


memoized = Dict{Int, Int}()
memoized = Dict{Int, Int}()