minor ch 14 exercises fixes

This commit is contained in:
Bogumił Kamiński 2022-10-14 12:39:14 +02:00
parent 6a8b3ae160
commit ae41462776

View File

@ -15,10 +15,9 @@ average number of items from this set that were drawn at least once.
Call the function running this simulation `boot`. Call the function running this simulation `boot`.
<details> <details>
<summary>Solution</summary> <summary>Solution</summary>
Solution (there are many other approaches you could use): There are many other approaches you could use:
``` ```
using Statistics using Statistics
@ -45,11 +44,8 @@ Make this function single threaded. Check how long
this function runs for `n=1000` and `k=1_000_000`. this function runs for `n=1000` and `k=1_000_000`.
<details> <details>
<summary>Solution</summary> <summary>Solution</summary>
Solution:
``` ```
function simboot(k::Integer, n::Integer) function simboot(k::Integer, n::Integer)
result = [boot(n) for _ in 1:k] result = [boot(n) for _ in 1:k]
@ -83,11 +79,8 @@ Call the function `simbootT`. Check how long this function runs for `n=1000` and
`k=1_000_000`. `k=1_000_000`.
<details> <details>
<summary>Solution</summary> <summary>Solution</summary>
Solution:
``` ```
using ThreadsX using ThreadsX
@ -125,11 +118,8 @@ does not do any allocations internally). Call these new functions `boot!` and
functions. functions.
<details> <details>
<summary>Solution</summary> <summary>Solution</summary>
Solution:
``` ```
function boot!(n::Integer, pool) function boot!(n::Integer, pool)
table = pool[Threads.threadid()] table = pool[Threads.threadid()]
@ -180,11 +170,10 @@ use the `@timed` macro in your solution.
Start the server. Start the server.
<details> <details>
<summary>Solution</summary> <summary>Solution</summary>
Solution (I used the simplest single-threaded code here; this is a complete I used the simplest single-threaded code here; this is a complete
code of the web service): code of the web service:
``` ```
using Genie using Genie
@ -234,11 +223,8 @@ the following parameters:
* `k=1.5` and `n=1000` * `k=1.5` and `n=1000`
<details> <details>
<summary>Solution</summary> <summary>Solution</summary>
Solution:
``` ```
julia> using HTTP julia> using HTTP
@ -279,11 +265,8 @@ Collect the data generated by a web service into the `df` data frame for
`k = [10^i for i in 3:6]` and `n = [10^i for i in 1:3]`. `k = [10^i for i in 3:6]` and `n = [10^i for i in 1:3]`.
<details> <details>
<summary>Solution</summary> <summary>Solution</summary>
Solution:
``` ```
using DataFrames using DataFrames
@ -329,11 +312,8 @@ julia> df
Replace the `value` column in the `df` data frame by its contents in-place. Replace the `value` column in the `df` data frame by its contents in-place.
<details> <details>
<summary>Solution</summary> <summary>Solution</summary>
Solution:
``` ```
julia> select!(df, :status, :time, :value => AsTable) julia> select!(df, :status, :time, :value => AsTable)
12×7 DataFrame 12×7 DataFrame
@ -362,11 +342,8 @@ Checks that execution time roughly scales proportionally to the product
of `k` times `n`. of `k` times `n`.
<details> <details>
<summary>Solution</summary> <summary>Solution</summary>
Solution:
``` ```
julia> using DataFramesMeta julia> using DataFramesMeta
@ -397,10 +374,8 @@ Plot the expected fraction of seen elements in the set as a function of
`n` by `k` along with 95% confidence interval around these values. `n` by `k` along with 95% confidence interval around these values.
<details> <details>
<summary>Solution</summary> <summary>Solution</summary>
Solution:
``` ```
using Plots using Plots
gdf = groupby(df, :k, sort=true) gdf = groupby(df, :k, sort=true)