From de449e76705ece9355321d3b08eac13d372c84a9 Mon Sep 17 00:00:00 2001 From: Bram Spanoghe <70662421+bspanoghe@users.noreply.github.com> Date: Tue, 17 Mar 2026 10:27:10 +0100 Subject: [PATCH] remove use of `eachindex` it scares the students --- exercises/solved_notebooks/P4_probmod/probmod_2-basics.jl | 4 ++-- exercises/solved_notebooks/P5_mcmc/MCMC_1-intro.jl | 4 ++-- exercises/solved_notebooks/P5_mcmc/MCMC_4-review.jl | 2 +- .../P8_modselect/model_selection_friction_sol.jl | 2 +- .../solved_notebooks/P8_modselect/model_selection_intro.jl | 2 +- exercises/student_notebooks/P5_mcmc/MCMC_1-intro.jl | 4 ++-- .../P8_modselect/model_selection_friction_sol.jl | 2 +- .../student_notebooks/P8_modselect/model_selection_intro.jl | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/exercises/solved_notebooks/P4_probmod/probmod_2-basics.jl b/exercises/solved_notebooks/P4_probmod/probmod_2-basics.jl index fc49a42..be9b08b 100644 --- a/exercises/solved_notebooks/P4_probmod/probmod_2-basics.jl +++ b/exercises/solved_notebooks/P4_probmod/probmod_2-basics.jl @@ -167,7 +167,7 @@ md"### 2: Dirtprism" # ╔═╡ 6b009ba3-83a8-4176-86d4-dd9f70ed29ec @model function dirtprism() rolls = zeros(20) # also possible to write out all 20 rolls by hand - for i in eachindex(rolls) + for i in 1:length(rolls) rolls[i] ~ DiscreteUniform(1, 4) end dicesum = sum(rolls) @@ -292,7 +292,7 @@ count_occurences([5, 107, 364, 5, 5, 364]) # three 5's, one 107 and two 364's # number of students used as an input to the function so you can solve the question for any number of students - this was not asked but it's nice bdays = zeros(n_students) - for bday_idx in eachindex(bdays) + for bday_idx in 1:length(bdays) bdays[bday_idx] ~ DiscreteUniform(1, 365) end occurences = count_occurences(bdays) diff --git a/exercises/solved_notebooks/P5_mcmc/MCMC_1-intro.jl b/exercises/solved_notebooks/P5_mcmc/MCMC_1-intro.jl index c73f3df..02c6944 100644 --- a/exercises/solved_notebooks/P5_mcmc/MCMC_1-intro.jl +++ b/exercises/solved_notebooks/P5_mcmc/MCMC_1-intro.jl @@ -328,7 +328,7 @@ As prior knowledge we can use the fact that it must have evolved _after_ the ray α ~ prior_alpha # prior distribution of parameter N = zeros(length(ts)) # output variable: in this model we have multiple values, so we need to preallocate a vector - for i in eachindex(ts) + for i in 1:length(ts) N_average = α * ts[i] N[i] ~ Poisson(N_average) end @@ -369,7 +369,7 @@ let α ~ Exponential(2) # prior distribution of parameter N = zeros(length(ts)) # output variable: in this model we have multiple values, so we need to preallocate a vector - for i in eachindex(ts) + for i in 1:length(ts) N_average = α * ts[i] N[i] ~ Poisson(N_average) end diff --git a/exercises/solved_notebooks/P5_mcmc/MCMC_4-review.jl b/exercises/solved_notebooks/P5_mcmc/MCMC_4-review.jl index 749e2be..92488ad 100644 --- a/exercises/solved_notebooks/P5_mcmc/MCMC_4-review.jl +++ b/exercises/solved_notebooks/P5_mcmc/MCMC_4-review.jl @@ -63,7 +63,7 @@ md""" y_nest ~ Uniform(0, 1000) v_wasp ~ Gamma(8) # or something similar - for i in eachindex(ts) + for i in 1:length(ts) dist = sqrt((xs[i] - x_nest)^2 + (ys[i] - y_nest)^2) ts[i] ~ Normal(2*dist / v_wasp, 10) end diff --git a/exercises/solved_notebooks/P8_modselect/model_selection_friction_sol.jl b/exercises/solved_notebooks/P8_modselect/model_selection_friction_sol.jl index b6c421a..624e8f3 100644 --- a/exercises/solved_notebooks/P8_modselect/model_selection_friction_sol.jl +++ b/exercises/solved_notebooks/P8_modselect/model_selection_friction_sol.jl @@ -364,7 +364,7 @@ function posterior(AICs) # AICs vector of AIC values AICmin = minimum(AICs) posterior = zeros(length(AICs)) - for i in eachindex(1:length(AICs)) + for i in 1:length(AICs) posterior[i] = exp((AICmin-AICs[i])/2) end diff --git a/exercises/solved_notebooks/P8_modselect/model_selection_intro.jl b/exercises/solved_notebooks/P8_modselect/model_selection_intro.jl index 5b42e6a..13383ad 100644 --- a/exercises/solved_notebooks/P8_modselect/model_selection_intro.jl +++ b/exercises/solved_notebooks/P8_modselect/model_selection_intro.jl @@ -446,7 +446,7 @@ function posterior(AICs) # AICs vector of AIC values AICmin = minimum(AICs) posterior = zeros(length(AICs)) - for i in eachindex(1:length(AICs)) + for i in 1:length(AICs) posterior[i] = exp((AICmin-AICs[i])/2) end diff --git a/exercises/student_notebooks/P5_mcmc/MCMC_1-intro.jl b/exercises/student_notebooks/P5_mcmc/MCMC_1-intro.jl index c40109a..22a26a9 100644 --- a/exercises/student_notebooks/P5_mcmc/MCMC_1-intro.jl +++ b/exercises/student_notebooks/P5_mcmc/MCMC_1-intro.jl @@ -328,7 +328,7 @@ As prior knowledge we can use the fact that it must have evolved _after_ the ray α ~ prior_alpha # prior distribution of parameter N = zeros(length(ts)) # output variable: in this model we have multiple values, so we need to preallocate a vector - for i in eachindex(ts) + for i in 1:length(ts) N_average = α * ts[i] N[i] ~ Poisson(N_average) end @@ -369,7 +369,7 @@ let α ~ Exponential(2) # prior distribution of parameter N = zeros(length(ts)) # output variable: in this model we have multiple values, so we need to preallocate a vector - for i in eachindex(ts) + for i in 1:length(ts) N_average = α * ts[i] N[i] ~ Poisson(N_average) end diff --git a/exercises/student_notebooks/P8_modselect/model_selection_friction_sol.jl b/exercises/student_notebooks/P8_modselect/model_selection_friction_sol.jl index d01d31e..9d57228 100644 --- a/exercises/student_notebooks/P8_modselect/model_selection_friction_sol.jl +++ b/exercises/student_notebooks/P8_modselect/model_selection_friction_sol.jl @@ -358,7 +358,7 @@ function posterior(AICs) # AICs vector of AIC values AICmin = minimum(AICs) posterior = zeros(length(AICs)) - for i in eachindex(1:length(AICs)) + for i in 1:length(AICs) posterior[i] = exp((AICmin-AICs[i])/2) end diff --git a/exercises/student_notebooks/P8_modselect/model_selection_intro.jl b/exercises/student_notebooks/P8_modselect/model_selection_intro.jl index 6157fc2..73f3a01 100644 --- a/exercises/student_notebooks/P8_modselect/model_selection_intro.jl +++ b/exercises/student_notebooks/P8_modselect/model_selection_intro.jl @@ -440,7 +440,7 @@ function posterior(AICs) # AICs vector of AIC values AICmin = minimum(AICs) posterior = zeros(length(AICs)) - for i in eachindex(1:length(AICs)) + for i in 1:length(AICs) posterior[i] = exp((AICmin-AICs[i])/2) end