Advertisement
obernardovieira

The Sausage King (day 2) [SLiSW]

Jul 27th, 2015
3,274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
IO 0.84 KB | None | 0 0
  1. /*Not all exercises, but I don't see any objetive in this language, and I'm not happy doing this, so, I will stop. I will not do the day 3*/
  2.  
  3. /*some exercises from the book*/
  4.  
  5. fib := method(result, (
  6.     i := 0;
  7.     res := list(0, 1);
  8.     while(i < result, res append(res at(i) + res at(i+1)); i = i + 1);
  9.     res at(i) println
  10. ))
  11.  
  12. fib(4)
  13. fib(5)
  14. fib(6)
  15. fib(7)
  16.  
  17. /*--------*/
  18.  
  19. a := list(list(1,2,3), list(4,5,6), list(7,8,9))
  20. b := list(list(7,8,9), list(4,5,6), list(1,2,3))
  21. final := list()
  22.  
  23. i := 0
  24. while(i < a size, final append((a at(i) sum) + (b at(i) sum)); i = i + 1); final sum println
  25.  
  26. /*---------*/
  27.  
  28. List myAverage := method(
  29.     i := 0
  30.     sum := 0
  31.     while(i < self size, if(self at(i) type == "Number", sum = sum + self at(i), Exception raise("Not a number!")); i = i + 1)
  32.     sum = sum / self size
  33. )
  34.  
  35. list(1,2,3,4,5,6) myAverage println
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement