Files
honore-beaugrand/Devoir-3-real.ipynb
T
2018-08-29 20:00:30 -04:00

7.0 KiB

Homework number 3

This is a doable homework.

Section 1

the bellow section requires the knowledge of clojures basic types. I belive here is some good documentation about basic types. http://kimh.github.io/clojure-by-example/#about

1.1 create basic types

  1. Create a variable named age set to your age
  2. Create a variable named name set to your name
  3. Create a variable named gender set to your genger
  4. Create a variable named amount set to the amount of money you have in your wallet
In [ ]:

1.2 Create complexe types

  1. create a variable named person that represent the information you filled above in a single dictionnary
  2. create 3 more persons with mocked values
  3. create a variable named persons that contains all the four persons in a list
In [ ]:

3 maps and apply

We have seen that the map function is used to transform a collection into an other in a one to one fashion. Let's try it

3.1 The map function

In [ ]:

3.1.1 Increase the value of each item in [20 89 92 89] of one using the inc function.

In [ ]:

3.1.2 Decrease the value of each item in [100 90 98 11] of one using dec function.

In [ ]:

3.1.3 Capitalize each word in ["one" "two" "three"] using the clojure.string/upper-case function

In [ ]:

3.1.4 Extract the name of each keyword in the array [:name :age :gender] using the name function.

In [ ]:

3.1.5 Extract the :name of each dict in the array [{:name "bob"} {:name "alice"} {:name "margaret"}] using the :name function.

In [ ]:

3.2 The filter function

3.2.1 Filter all the odd numbers of the [1 2 3 4 5 6 7] list using the odd? function.

In [ ]:

3.2.2 Filter all the even numbers of the [1 2 3 4 5 6 7] list using the even? function.

In [ ]:

3.2.3 Filter all the "not nil" values of the [false nil "" 0 true] list using the some? function.

In [ ]:

3.3 The apply function

3.3.1 Sum all the numbers of the [1 2 3 4 5 6 7] list using the + function.

In [ ]:

3.3.2 Multiply all the numbers of the [1 2 3 4 5 6 7] list using the * function.

In [ ]:

3.3.2 Concat the three lists [1 2 3 4], [:a :b :c], ["hello" "world"] using the concat function.

In [ ]:

4 All togheter..

4.1

sum the value of each odd number in the list [1 2 3 4 5 6 7 8 9 10]

In [ ]:

4.2

Find total amount owned by the persons in the list [{:name "bob" :amout 10.23} {:name "alice" :amout 15.23} ]

In [ ]: