From 054e8c396b9cc5847adbd337184cea206a74a468 Mon Sep 17 00:00:00 2001 From: didier amyot Date: Wed, 29 Aug 2018 20:00:30 -0400 Subject: [PATCH] homework 3 --- Devoir-3-real.ipynb | 310 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 310 insertions(+) create mode 100644 Devoir-3-real.ipynb diff --git a/Devoir-3-real.ipynb b/Devoir-3-real.ipynb new file mode 100644 index 0000000..5dd24f1 --- /dev/null +++ b/Devoir-3-real.ipynb @@ -0,0 +1,310 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Homework number 3\n", + "\n", + "\n", + "This is a **doable** homework. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Section 1\n", + "\n", + "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" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 1.1 create basic types\n", + "\n", + "1. Create a variable named `age` set to your age\n", + "2. Create a variable named `name` set to your name\n", + "3. Create a variable named `gender` set to your genger\n", + "4. Create a variable named `amount` set to the amount of money you have in your wallet\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 1.2 Create complexe types\n", + "\n", + "1. create a variable named `person` that represent the information you filled above in a single dictionnary\n", + "2. create 3 more persons with mocked values\n", + "3. create a variable named `persons` that contains all the four persons in a list" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 3 maps and apply\n", + "\n", + "We have seen that the [map](https://clojuredocs.org/clojure.core/map) function is used to transform a collection into an other in a one to one fashion. Let's try it\n", + "\n", + "* http://kimh.github.io/clojure-by-example/#map" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 3.1 The [map](https://clojuredocs.org/clojure.core/name) function" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3.1.1 Increase the value of each item in `[20 89 92 89]` of one using the [inc](https://clojuredocs.org/clojure.core/inc) function." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3.1.2 Decrease the value of each item in [100 90 98 11] of one using [dec](https://clojuredocs.org/clojure.core/dec) function." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3.1.3 Capitalize each word in `[\"one\" \"two\" \"three\"]` using the [clojure.string/upper-case](https://clojuredocs.org/clojure.string/upper-case) function" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3.1.4 Extract the name of each keyword in the array `[:name :age :gender]` using the [name](https://clojuredocs.org/clojure.core/name) function." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3.1.5 Extract the `:name` of each dict in the array `[{:name \"bob\"} {:name \"alice\"} {:name \"margaret\"}]` using the `:name` function." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 3.2 The [filter](https://clojuredocs.org/clojure.core/name) function" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3.2.1 Filter all the odd numbers of the `[1 2 3 4 5 6 7]` list using the [odd?](https://clojuredocs.org/clojure.core/odd_q) function." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3.2.2 Filter all the even numbers of the `[1 2 3 4 5 6 7]` list using the [even?](https://clojuredocs.org/clojure.core/even_q) function." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3.2.3 Filter all the \"not nil\" values of the `[false nil \"\" 0 true]` list using the [some?](https://clojuredocs.org/clojure.core/some_q) function." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 3.3 The [apply](https://clojuredocs.org/clojure.core/function) function" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3.3.1 Sum all the numbers of the `[1 2 3 4 5 6 7]` list using the [+](https://clojuredocs.org/clojure.core/+) function." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3.3.2 Multiply all the numbers of the `[1 2 3 4 5 6 7]` list using the [*](https://clojuredocs.org/clojure.core/*) function." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3.3.2 Concat the three lists `[1 2 3 4]`, `[:a :b :c]`, `[\"hello\" \"world\"]` using the [concat](https://clojuredocs.org/clojure.core/concat) function. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 4 All togheter.." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 4.1\n", + "sum the value of each odd number in the list `[1 2 3 4 5 6 7 8 9 10]`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 4.2\n", + "Find total amount owned by the persons in the list `[{:name \"bob\" :amout 10.23} {:name \"alice\" :amout 15.23} ]`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Lein-Clojure", + "language": "clojure", + "name": "lein-clojure" + }, + "language_info": { + "file_extension": ".clj", + "mimetype": "text/x-clojure", + "name": "clojure", + "version": "1.9.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}