Advertisement
ana_makarevich

Factorials list with accumlator

Oct 15th, 2014
2,587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 0.23 KB | None | 0 0
  1. % Example: {Fact 4} has to return [1 2 6 24]
  2. declare
  3. fun {Fact N}
  4.    local FactAcc in
  5.       fun {FactAcc R L}
  6.      if (R==N) then {Reverse L}
  7.      else {FactAcc R+1 (L.1*(R+1))|L}
  8.      end
  9.       end
  10.       {FactAcc 1 [1]}    
  11.    end
  12. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement