Anonymous user
Left factorials: Difference between revisions
no edit summary
(→{{header|Lambdatalk}}: flagged Lamdatalk as incorrect (wrong start of the 1st range).) |
No edit summary |
||
Line 1,868:
=={{header|Lambdatalk}}==
{{incorrect|Lambdatalk| <br><br> The first range of left factorials should start with 0 (zero), not 2. <br><br>
<center>Hi Rosetta, I fixed the code. Thanks for the warning, it gave me a chance to improve it. At least that's what I think.</center>
}}
The code can be tested in this wiki page: http://lambdaway.free.fr/lambdawalks/?view=left_factorial
<lang scheme>
2.1) defining !n
{def !n // the main function's name
{def MEM.undef? {lambda {:n} {W.equal? {A.get :n {MEM}} undefined} }} ▼
{def !n.mem {A.new 0 1 2}} // initializing a global array
// memorizing the computed values of !n
{def !n.set // computing and storing the values
{lambda {:n}
{A.set! :n // assign at n
{!n.mem}}}} // in the global array
{def !n.get // getting a value
{lambda {:n}
▲
then {!n.set :n} // then compute it
else {!n.mem}}}}} // else get it from the global array
{lambda {:n} // the main function's body
{if {< :n 2} // if n=0 and n=1
then :n // then return 0 or 1
else {S.reduce long_add // apply add_long to
1 {S.map !n.get {S.serie 1 {- :n 1}}}}}}} // the sequence of computed values
2.2) the task
Line 1,892 ⟶ 1,903:
{S.map {lambda {:n} {br}!n(:n) = {!n :n}}
{S.serie
->
!n(0) = 0
!n(1) = 1
!n(2) = 2
!n(3) = 4
|