diff --git a/404.html b/404.html index b97a542..bb28670 100644 --- a/404.html +++ b/404.html @@ -1 +1 @@ -
The goal of this game is to have the user guess a random number. Your program should select a number between 1 and 100 (inclusive). Then, it should accept a series of guesses from the user. Each time the guess entered is wrong, your program provides a hint: whether the guess entered was too high or too low. When the correct number is entered, you can print a message and exit.
You will need some pieces from the Julia standard library:
rand(a:b)
(docs): select a random integer in
readline()
(docs): read a single line from the terminal and return it as a string
parse(Int, s)
(docs): parse the String
s
as an Int
The top-level Julia scope behaves differently than you might expect. You will want to wrap your code in a function, like so:
# in your_filename.jl
+ Day 1 Day 1
Problem: Guessing Game
The goal of this game is to have the user guess a random number. Your program should select a number between 1 and 100 (inclusive). Then, it should accept a series of guesses from the user. Each time the guess entered is wrong, your program provides a hint: whether the guess entered was too high or too low. When the correct number is entered, you can print a message and exit.
You will need some pieces from the Julia standard library:
rand(a:b)
(docs): select a random integer in
readline()
(docs): read a single line from the terminal and return it as a string
parse(Int, s)
(docs): parse the String
s
as an Int
The top-level Julia scope behaves differently than you might expect. You will want to wrap your code in a function, like so:
# in your_filename.jl
function main()
# your code here
end
diff --git a/day2/index.html b/day2/index.html
index 9c68401..1693053 100644
--- a/day2/index.html
+++ b/day2/index.html
@@ -1,4 +1,4 @@
- Day 2 Day 2
Problem 1: Prime Number Iterator
Make an iterator over the prime numbers less than or equal to using a Sieve of Eratosthenes
The sieve should be created when building the Primes struct
You should provide a constructor which does so (Primes(n::Int)
)
The iterator interface is described here
You may wish to define additional functions
Sieve of Eratosthenes:
Allocate a Boolean vector of size , where each element represents whether that number is prime.
They should all start as true
. You can use the function ones(Bool, n)
to make the vector.
(there's also a trues
function, which returns a BitVector
. This'll also work.)
Mark 1 as false
1 isn't prime
Let
While there are numbers marked as prime greater than :
Set to the smallest number marked prime larger than the previous
Mark all multiples of (, , ...) as not prime
Now, all numbers are marked correctly
Hint: 1:2:10
gives you a range over (1, 3, 5, 7, 9)
Problem 2: Outer Product Matrix
Problem 2: Write a matrix type which is the outer product of two vectors
You should only store the vectors
Both should have element type T
, and it should be a subtype of AbstractMatrix{T}
You should implement the methods (docs):
size(::OuterProduct)
getindex(::OuterProduct, i::Int, j::Int)
adjoint(::OuterProduct)
(hint: (uv')' = (vu'))
Try building an instance of OuterProduct in the REPL. Julia can already print it and has matrix-vector and matrix-matrix multiplication defined!
Problem 3: Peano Arithmetic
Peano arithmetic provides a compact axiomatic description of the natural numbers. An informal description is:
There exists 0.
There exists the successor function, .
implies
From this we can recursively construct the naturals. Further, we can define addition recursively:
+(0, 0) = 0
+ Day 2 Day 2
Problem 1: Prime Number Iterator
Make an iterator over the prime numbers less than or equal to using a Sieve of Eratosthenes
The sieve should be created when building the Primes struct
You should provide a constructor which does so (Primes(n::Int)
)
The iterator interface is described here
You may wish to define additional functions
Sieve of Eratosthenes:
Allocate a Boolean vector of size , where each element represents whether that number is prime.
They should all start as true
. You can use the function ones(Bool, n)
to make the vector.
(there's also a trues
function, which returns a BitVector
. This'll also work.)
Mark 1 as false
1 isn't prime
Let
While there are numbers marked as prime greater than :
Set to the smallest number marked prime larger than the previous
Mark all multiples of (, , ...) as not prime
Now, all numbers are marked correctly
Hint: 1:2:10
gives you a range over (1, 3, 5, 7, 9)
Problem 2: Outer Product Matrix
Problem 2: Write a matrix type which is the outer product of two vectors
You should only store the vectors
Both should have element type T
, and it should be a subtype of AbstractMatrix{T}
You should implement the methods (docs):
size(::OuterProduct)
getindex(::OuterProduct, i::Int, j::Int)
adjoint(::OuterProduct)
(hint: (uv')' = (vu'))
Try building an instance of OuterProduct in the REPL. Julia can already print it and has matrix-vector and matrix-matrix multiplication defined!
Problem 3: Peano Arithmetic
Peano arithmetic provides a compact axiomatic description of the natural numbers. An informal description is:
There exists 0.
There exists the successor function, .
implies
From this we can recursively construct the naturals. Further, we can define addition recursively:
+(0, 0) = 0
+(x, 0) = x
+(0, x) = x
+(x, S(y)) = S(x + y)
As well as multiplication:
*(0, 0) = 0
diff --git a/day3/index.html b/day3/index.html
index 39d6f0a..dfd14f0 100644
--- a/day3/index.html
+++ b/day3/index.html
@@ -1,4 +1,4 @@
- Day 3 Day 3
Problems
Check whether your solutions for last week's problems were type stable. One of the methods there cannot be type stable. Which is it?
For the Peano numbers problem, in the following code, how many compilations for +
happen?
Zero() + Zero()
+ Day 3 Day 3
Problems
Check whether your solutions for last week's problems were type stable. One of the methods there cannot be type stable. Which is it?
For the Peano numbers problem, in the following code, how many compilations for +
happen?
Zero() + Zero()
Zero() + convert(PeanoNumber, 1)
convert(PeanoNumber, 1) + Zero()
convert(PeanoNumber, 1) + convert(PeanoNumber, 5)
diff --git a/day4.ipynb b/day4.ipynb
index 7fe1a15..b44a131 100644
--- a/day4.ipynb
+++ b/day4.ipynb
@@ -3,7 +3,13 @@
{
"cell_type": "markdown",
"id": "0ae03770-e9c7-4cc3-b400-909b20fa9d8a",
- "metadata": {},
+ "metadata": {
+ "editable": true,
+ "slideshow": {
+ "slide_type": ""
+ },
+ "tags": []
+ },
"source": [
"# Julia Workshop, Day 4: Benchmarking, Debugging, Modules\n",
"\n",
@@ -229,7 +235,7 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 5,
"id": "23fcebe5",
"metadata": {
"editable": true,
@@ -274,7 +280,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 6,
"id": "7c1b5259",
"metadata": {
"editable": true,
@@ -290,7 +296,7 @@
"rand (generic function with 83 methods)"
]
},
- "execution_count": 3,
+ "execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
@@ -312,7 +318,7 @@
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": 7,
"id": "6613169d",
"metadata": {
"editable": true,
@@ -328,7 +334,7 @@
"apply_all (generic function with 2 methods)"
]
},
- "execution_count": 4,
+ "execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
@@ -370,7 +376,7 @@
},
{
"cell_type": "code",
- "execution_count": 18,
+ "execution_count": 8,
"id": "3e184a71",
"metadata": {
"editable": true,
@@ -383,19 +389,19 @@
{
"data": {
"text/plain": [
- "BenchmarkTools.Trial: 8570 samples with 1 evaluation.\n",
- " Range \u001b[90m(\u001b[39m\u001b[36m\u001b[1mmin\u001b[22m\u001b[39m … \u001b[35mmax\u001b[39m\u001b[90m): \u001b[39m\u001b[36m\u001b[1m2.546 ms\u001b[22m\u001b[39m … \u001b[35m 10.926 ms\u001b[39m \u001b[90m┊\u001b[39m GC \u001b[90m(\u001b[39mmin … max\u001b[90m): \u001b[39m0.00% … 0.00%\n",
- " Time \u001b[90m(\u001b[39m\u001b[34m\u001b[1mmedian\u001b[22m\u001b[39m\u001b[90m): \u001b[39m\u001b[34m\u001b[1m3.698 ms \u001b[22m\u001b[39m\u001b[90m┊\u001b[39m GC \u001b[90m(\u001b[39mmedian\u001b[90m): \u001b[39m0.00%\n",
- " Time \u001b[90m(\u001b[39m\u001b[32m\u001b[1mmean\u001b[22m\u001b[39m ± \u001b[32mσ\u001b[39m\u001b[90m): \u001b[39m\u001b[32m\u001b[1m3.522 ms\u001b[22m\u001b[39m ± \u001b[32m844.749 μs\u001b[39m \u001b[90m┊\u001b[39m GC \u001b[90m(\u001b[39mmean ± σ\u001b[90m): \u001b[39m1.15% ± 4.16%\n",
+ "BenchmarkTools.Trial: 7906 samples with 1 evaluation.\n",
+ " Range \u001b[90m(\u001b[39m\u001b[36m\u001b[1mmin\u001b[22m\u001b[39m … \u001b[35mmax\u001b[39m\u001b[90m): \u001b[39m\u001b[36m\u001b[1m2.554 ms\u001b[22m\u001b[39m … \u001b[35m10.702 ms\u001b[39m \u001b[90m┊\u001b[39m GC \u001b[90m(\u001b[39mmin … max\u001b[90m): \u001b[39m0.00% … 0.00%\n",
+ " Time \u001b[90m(\u001b[39m\u001b[34m\u001b[1mmedian\u001b[22m\u001b[39m\u001b[90m): \u001b[39m\u001b[34m\u001b[1m4.271 ms \u001b[22m\u001b[39m\u001b[90m┊\u001b[39m GC \u001b[90m(\u001b[39mmedian\u001b[90m): \u001b[39m0.00%\n",
+ " Time \u001b[90m(\u001b[39m\u001b[32m\u001b[1mmean\u001b[22m\u001b[39m ± \u001b[32mσ\u001b[39m\u001b[90m): \u001b[39m\u001b[32m\u001b[1m4.140 ms\u001b[22m\u001b[39m ± \u001b[32m 1.445 ms\u001b[39m \u001b[90m┊\u001b[39m GC \u001b[90m(\u001b[39mmean ± σ\u001b[90m): \u001b[39m0.98% ± 3.87%\n",
"\n",
- " \u001b[39m█\u001b[39m▄\u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m▃\u001b[39m▄\u001b[39m▁\u001b[39m▁\u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[32m \u001b[39m\u001b[39m \u001b[39m▁\u001b[39m▁\u001b[34m▁\u001b[39m\u001b[39m▂\u001b[39m▂\u001b[39m▂\u001b[39m▃\u001b[39m▃\u001b[39m▃\u001b[39m▃\u001b[39m▃\u001b[39m▃\u001b[39m▃\u001b[39m▃\u001b[39m▄\u001b[39m▄\u001b[39m▃\u001b[39m▃\u001b[39m▃\u001b[39m▃\u001b[39m▃\u001b[39m▂\u001b[39m▂\u001b[39m▁\u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m▁\n",
- " \u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m▆\u001b[39m▆\u001b[39m▄\u001b[39m▆\u001b[39m▄\u001b[39m▄\u001b[39m▅\u001b[39m▅\u001b[39m▆\u001b[39m▆\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m▇\u001b[39m█\u001b[39m▇\u001b[39m▇\u001b[32m▇\u001b[39m\u001b[39m█\u001b[39m█\u001b[39m█\u001b[34m█\u001b[39m\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m▇\u001b[39m▇\u001b[39m▆\u001b[39m▅\u001b[39m▆\u001b[39m▅\u001b[39m▆\u001b[39m \u001b[39m█\n",
- " 2.55 ms\u001b[90m \u001b[39m\u001b[90mHistogram: \u001b[39m\u001b[90m\u001b[1mlog(\u001b[22m\u001b[39m\u001b[90mfrequency\u001b[39m\u001b[90m\u001b[1m)\u001b[22m\u001b[39m\u001b[90m by time\u001b[39m 5.13 ms \u001b[0m\u001b[1m<\u001b[22m\n",
+ " \u001b[39m█\u001b[39m▁\u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m▄\u001b[39m▁\u001b[39m▄\u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[32m \u001b[39m\u001b[39m \u001b[34m \u001b[39m\u001b[39m \u001b[39m \u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▂\u001b[39m▁\u001b[39m▁\u001b[39m▂\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▂\u001b[39m▃\u001b[39m▃\u001b[39m▃\u001b[39m▄\u001b[39m▄\u001b[39m▄\u001b[39m▃\u001b[39m▃\u001b[39m▃\u001b[39m▃\u001b[39m▂\u001b[39m▂\u001b[39m▁\u001b[39m▁\u001b[39m \u001b[39m \u001b[39m \u001b[39m▁\n",
+ " \u001b[39m█\u001b[39m█\u001b[39m▅\u001b[39m▅\u001b[39m▆\u001b[39m▅\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m▇\u001b[39m▇\u001b[39m▆\u001b[39m▇\u001b[39m▆\u001b[39m▆\u001b[39m▇\u001b[39m▇\u001b[39m▆\u001b[39m▆\u001b[39m▇\u001b[39m▆\u001b[39m▆\u001b[39m▇\u001b[32m▆\u001b[39m\u001b[39m▆\u001b[34m▇\u001b[39m\u001b[39m▇\u001b[39m▇\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m \u001b[39m█\n",
+ " 2.55 ms\u001b[90m \u001b[39m\u001b[90mHistogram: \u001b[39m\u001b[90m\u001b[1mlog(\u001b[22m\u001b[39m\u001b[90mfrequency\u001b[39m\u001b[90m\u001b[1m)\u001b[22m\u001b[39m\u001b[90m by time\u001b[39m 6.38 ms \u001b[0m\u001b[1m<\u001b[22m\n",
"\n",
" Memory estimate\u001b[90m: \u001b[39m\u001b[33m2.25 MiB\u001b[39m, allocs estimate\u001b[90m: \u001b[39m\u001b[33m4100\u001b[39m."
]
},
- "execution_count": 18,
+ "execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
@@ -438,7 +444,7 @@
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": 9,
"id": "8dad581f",
"metadata": {
"editable": true,
@@ -455,7 +461,7 @@
},
{
"cell_type": "code",
- "execution_count": 17,
+ "execution_count": 10,
"id": "7e79255e",
"metadata": {
"editable": true,
@@ -470,302 +476,316 @@
"image/svg+xml": [
"\n",
"\n",
- "