From f1cb5a7594a4a0001d12ad91ad025ad5860d14d8 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Tue, 25 Oct 2022 12:36:57 +0200 Subject: [PATCH] Solved task 1 to 10, missing final exercise --- .../Julia Intro - exercise.jl | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/exercise/1. Introduction Julia/Julia Intro - exercise.jl b/exercise/1. Introduction Julia/Julia Intro - exercise.jl index ebec37f..557ebe4 100644 --- a/exercise/1. Introduction Julia/Julia Intro - exercise.jl +++ b/exercise/1. Introduction Julia/Julia Intro - exercise.jl @@ -1,5 +1,5 @@ ### A Pluto.jl notebook ### -# v0.19.12 +# v0.19.14 using Markdown using InteractiveUtils @@ -70,7 +70,7 @@ md" " # ╔═╡ b5fff126-6215-11eb-1018-bd2e4f638f65 -n = missing +n = 10 # ╔═╡ 3249157e-6267-11eb-3dca-8949d7c0e3c9 md" @@ -82,7 +82,7 @@ Unicode characters can be entered using the tab completion of $\mathrm{\LaTeX}$- " # ╔═╡ ce1d05da-6267-11eb-136c-23c5c54a1559 -😱 = 3 +α = 3 # ╔═╡ 1695a810-6268-11eb-3932-fb8885097f70 md""" @@ -118,7 +118,7 @@ md" " # ╔═╡ d285737a-662f-11eb-390e-1d1e2437de71 -a2 = missing +a2 = 2^8 # ╔═╡ 5d04cbea-6630-11eb-3bee-c182aa912653 md" @@ -130,7 +130,7 @@ When an expression contains more than one operator, the order of evaluation depe " # ╔═╡ 0ae0cf56-6632-11eb-262a-191ea74ec517 -a3 = missing +a3 = 2^(4+4) # ╔═╡ 0fe8c31e-663a-11eb-1acb-17d3d7615e64 md""" @@ -155,7 +155,7 @@ md" # ╔═╡ 8d509116-663b-11eb-0e98-dd27598740fe function double(x) - return missing + return 2 * x end # ╔═╡ 06c9bcec-663d-11eb-3062-85c0983a79eb @@ -173,7 +173,7 @@ Read the julia documentation on [Conditional Evaluation](https://docs.julialang. # ╔═╡ 9fd96950-6651-11eb-25f7-c964ab504b4a function heaviside(x) - return missing + return x < 0 ? 0 : 1 end # ╔═╡ 34824462-6654-11eb-2b38-19d14aa309af @@ -191,7 +191,11 @@ A prime number is only evenly divisible by itself and 1. # ╔═╡ 6895356c-6655-11eb-3849-b3fa387df754 function isprime(x) - return missing + if x < 2 return false end + for i in 2:trunc(Int, sqrt(x)) + if x % i == 0 return false end + end + return true end # ╔═╡ 9687bc24-666c-11eb-3b1e-edb5c448bad8 @@ -226,7 +230,7 @@ Take a look into the documentation and assign an 8-bit unsigned integer of any v """ # ╔═╡ fb73ea0c-66d7-11eb-001c-23033aee228a -m = missing +m = UInt8(4) # ╔═╡ 2b99da2c-666d-11eb-1c64-337654a9d8f2 md""" @@ -248,7 +252,7 @@ md""" # ╔═╡ 66c4f3fc-66db-11eb-0927-ebe1d40eeb3b function sumup(n) - return missing + return sum(1:n) end # ╔═╡ 575d9e52-6468-11eb-2f95-63cd3920f91a @@ -270,7 +274,7 @@ md""" """ # ╔═╡ 055baa32-66e7-11eb-20fc-575565bda51b -v = missing +v = collect(1:10) # ╔═╡ 91c222ea-66e6-11eb-28ce-c1f1424525c8 md""" @@ -289,7 +293,7 @@ md""" """ # ╔═╡ d8f306ca-66e9-11eb-3728-156d0328250b -w = missing +w = [2*i for i in 1:500] # ╔═╡ 673cc322-666e-11eb-107f-2b9bd6826ad5 md""" @@ -313,7 +317,7 @@ md""" """ # ╔═╡ a87e36c4-66eb-11eb-223e-a1b077dca672 -B = missing +B = A./π # ╔═╡ 0aa99f86-6f97-11eb-2141-2d35c3e0857d md""" @@ -1651,7 +1655,7 @@ version = "1.4.1+0" # ╔═╡ Cell order: # ╟─349d7534-6212-11eb-2bc5-db5be39b6bb6 # ╠═96ec00fc-6f14-11eb-329e-19e4835643db -# ╠═6abc4d6a-da75-42bf-a62a-b98bb69585aa +# ╟─6abc4d6a-da75-42bf-a62a-b98bb69585aa # ╟─237ef27e-6266-11eb-3cf4-1b2223eabfd9 # ╠═6c060eec-6266-11eb-0b23-e5be08d78823 # ╟─830c9ed0-6266-11eb-27ba-07773c842fed