Skip to content

Commit

Permalink
Finalize material for workshop in Exeter (#7)
Browse files Browse the repository at this point in the history
* why Julia; use the manifesto

* correct URL syntax

* add "insane" showcase of composability in Julia

* update Manifest file

* add section multipkle dispatch + science

* finish multiple dispatch

* finish exercises for sction 1
  • Loading branch information
Datseris authored Nov 19, 2023
1 parent 1ee7d46 commit 3178777
Show file tree
Hide file tree
Showing 8 changed files with 966 additions and 388 deletions.
50 changes: 5 additions & 45 deletions 1-JuliaIntro.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2653,25 +2653,6 @@
"Using recursion (a function that calls itself) create a function that given an integer `n` it returns the `n`-th [Fibonacci number](https://en.wikipedia.org/wiki/Fibonacci_number). Apply it using `map` to the range `1:8` to get the result `[1,1,2,3,5,8,13]`."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Robot movement\n",
"\n",
"Simulate the movement of a robot in a two-dimensional integer grid. The robot can perform three actions: turn left, right, or move for 1 step in the direction it is facing. The robot receives instructions in the form of strings composed entirely by the letters `L, R, M` (meaning \"turn left\", \"turn right\" and \"move 1 step forwards\"). Write a function `move_robot(u0, instructions)` which receives as input:\n",
"\n",
"1. The robot's starting position `u0`, a tuple of `(x::Int, y::Int, d::Char)`, where `x, y` encode the starting position, and `d` the orientation, which can be a character of `'N', 'S', 'E', 'W'`.\n",
"2. The instructions which is a string sequencing the individual instructions, e.g., `\"LLMMMRMMRM\"`.\n",
"\n",
"The function should return `uf` which the robot's final position, which is a tuple of same type as `u0`.\n",
"\n",
"Test your function with the inputs `u0 = (7, 3, 'N')` and `instructions = \"RMMLML\"`, which should output `uf = (9, 4, 'W')`.\n",
"\n",
"_Hint: one way to solve this exercise is with lots and lots of `if` statements. Another is to create 2-tuples of movement vectors for each possible orientation. For rotation commands, the orientation vector gets updated. For movement commands, the oriantation vector is added to current position_"
]
},
{
"attachments": {},
"cell_type": "markdown",
Expand Down Expand Up @@ -2731,28 +2712,14 @@
},
{
"cell_type": "code",
"execution_count": 124,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `c:\\Users\\gd419\\OneDrive - University of Exeter\\Teaching\\Zero2Hero-JuliaWorkshop`"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m registry at `C:\\Users\\gd419\\.julia\\registries\\General.toml`\n"
"\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `c:\\Users\\gd419\\OneDrive - University of Exeter\\Teaching\\Zero2Hero-JuliaWorkshop`\n"
]
},
{
Expand All @@ -2768,7 +2735,7 @@
"text": [
"\n",
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\gd419\\OneDrive - University of Exeter\\Teaching\\Zero2Hero-JuliaWorkshop\\Project.toml`\n",
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\gd419\\OneDrive - University of Exeter\\Teaching\\Zero2Hero-JuliaWorkshop\\Manifest.toml`"
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\gd419\\OneDrive - University of Exeter\\Teaching\\Zero2Hero-JuliaWorkshop\\Manifest.toml`\n"
]
},
{
Expand All @@ -2779,19 +2746,12 @@
"\u001b[32m⌃\u001b[39m \u001b[90m[13f3f980] \u001b[39mCairoMakie v0.10.7\n",
"\u001b[36m\u001b[1mInfo\u001b[22m\u001b[39m Packages marked with \u001b[32m⌃\u001b[39m have new versions available and may be upgradable.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"import Pkg # the package manager of Julia is a package itself\n",
"Pkg.activate(@__DIR__) # activate directory of notebook as dedicated environment\n",
"Pkg.add(\"CairoMakie\") # package name\n",
"Pkg.activate(@__DIR__) # activate directory of notebook as dedicated environment\n",
"Pkg.add(\"CairoMakie\") # add package specified by name\n",
"Pkg.status(\"CairoMakie\") # print the version of the package installed"
]
},
Expand Down
Loading

0 comments on commit 3178777

Please sign in to comment.