preparation for second course
This commit is contained in:
1 parent
549c124119
commit
319ba391d8
5 files changed
+6663
-1
No files matched your search
@@ -0,0 +1,179 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Class 3. keep going"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## The homework was **way** too hard!!\n",
|
||||
"\n",
|
||||
"We needed some more tools..."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The [concat](https://clojuredocs.org/clojure.core/concat) function is used to concatenate collections togheter."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Homework correction (Part 1)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[{:name \"class 1\", :url \"https://gitlab.com/didiercrunch/honore-beaugrand/raw/master/resources/data/homework2/class1.edn\"} {:name \"class 2\", :url \"https://gitlab.com/didiercrunch/honore-beaugrand/raw/master/resources/data/homework2/class2.edn\"} {:name \"class 3\", :url \"https://gitlab.com/didiercrunch/honore-beaugrand/raw/master/resources/data/homework2/class3.edn\"}]"
|
||||
]
|
||||
},
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"(def school-url \"https://gitlab.com/didiercrunch/honore-beaugrand/raw/master/resources/data/homework2/classes.edn\")\n",
|
||||
"(def school-data (read-string (slurp school-url)))\n",
|
||||
"\n",
|
||||
"school-data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"([{:name \"boris\", :sex :male, :age 22} {:name \"bob\", :sex :female, :age 25} {:name \"andrea\", :sex :male, :age 33} {:name \"stephanie\", :sex :female, :age 12} {:name \"alexa\", :sex :female, :age 90} {:name \"boris\", :sex :female, :age 12} {:name \"nathasha\", :sex :male, :age 32} {:name \"marco\", :sex :male, :age 30}] [{:name \"enrico\", :sex :male, :age 32} {:name \"raquel\", :sex :female, :age 15} {:name \"alfred\", :sex :male, :age 17} {:name \"kery\", :sex :female, :age 101} {:name \"alexa\", :sex :female, :age 43} {:name \"dominique\", :sex :female, :age 30} {:name \"sofia\", :sex :male, :age 33} {:name \"clory\", :sex :male, :age 45}] [{:name \"Scot\", :sex :male, :age 23} {:name \"Annmarie\", :sex :female, :age 15} {:name \"Jeremy\", :sex :male, :age 17} {:name \"Theodora\", :sex :female, :age 67} {:name \"Andria\", :sex :female, :age 45} {:name \"Kyoko\", :sex :female, :age 39} {:name \"Jeanine\", :sex :male, :age 41} {:name \"Jeanine\", :sex :male, :age 45}])"
|
||||
]
|
||||
},
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"(def class-urls (map :url school-data))\n",
|
||||
"(def class-data-raw (map slurp class-urls))\n",
|
||||
"(def class-data (map read-string class-data-raw))\n",
|
||||
"class-data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 28,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"The total number of student in the school is: 24\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"(def number-of-student-by-class (map count class-data))\n",
|
||||
"(def number-of-student-in-the-school (apply + number-of-student-by-class))\n",
|
||||
"(println \"The total number of student in the school is:\" number-of-student-in-the-school)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 32,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"#'user/all-student"
|
||||
]
|
||||
},
|
||||
"execution_count": 32,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"(def all-student (apply concat class-data))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 29,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"The youngest person is aged 12\n",
|
||||
"The oldest person is aged 101\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"(def all-ages (map :age all-student))\n",
|
||||
"\n",
|
||||
"(def youger-age (apply min all-ages))\n",
|
||||
"(def older-age (apply max all-ages))\n",
|
||||
"\n",
|
||||
"(println \"The youngest person is aged \" youger-age)\n",
|
||||
"(println \"The oldest person is aged \" older-age)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 34,
|
||||
"metadata": {
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"the average age is 36.0\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"(def sum-of-all-ages (apply + all-ages))\n",
|
||||
"(def average-age (/ sum-of-all-ages number-of-student-in-the-school))\n",
|
||||
"(println \"the average age is \" (double average-age))"
|
||||
]
|
||||
}
|
||||
],
|
||||
"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
|
||||
}
|
||||
Reference in new issue
Block a user