November 2018
Intermediate to advanced
460 pages
14h 1m
English
We will define the simulation in two distinct ways. In the first we use an immutable type, and in the second we use a mutable type.
All the definitions are contained in the walk.jl file, so please inspect it now. We start with defining the types:
abstract type AbstractPoint endstruct PointI <: AbstractPoint x::Int y::Intendmutable struct PointM <: AbstractPoint x::Int y::IntendPointM(p::PointM) = PointM(p.x, p.y)
Now we define two functions, one for calculating the sum of absolute values of the position of the point, and one that moves the point:
d(p::AbstractPoint) = abs(p.x) + abs(p.y)move(p::PointI, d::PointI) = PointI(p.x+d.x, p.y+d.y)move(p::PointM, d::PointM) = (p.x += d.x; p.y += d.y; p)
We are ready to define the simulation, ...
Read now
Unlock full access