Elixir 練習問題 ListsAndRecursion-8

^o^ > elixir practice_10_4.exs
[total_amount: 107.5, id: 123, ship_to: :NC, net_amount: 100.0]
[total_amount: 35.5, id: 124, ship_to: :OK, net_amount: 35.5]
[total_amount: 25.92, id: 125, ship_to: :TX, net_amount: 24.0]
[total_amount: 48.384, id: 126, ship_to: :TX, net_amount: 44.8]
[total_amount: 26.875, id: 127, ship_to: :NC, net_amount: 25.0]
[total_amount: 10.0, id: 128, ship_to: :MA, net_amount: 10.0]
[total_amount: 100.0, id: 129, ship_to: :CA, net_amount: 100.0]
[total_amount: 53.75, id: 130, ship_to: :NC, net_amount: 50.0]

total_amount が最初に追加されちゃってるのがちょっと気に入らないけど、まあいいか。

Elixir 練習問題 ListsAndRecursion-7

以前に作った span 関数と内包表記を使って 2 から n までの素数。

^o^ > iex practice_10_3.exs
Eshell V8.0  (abort with ^G)
Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> MyList.primes(50)
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]