Luleå University of Technology

LTU courses · Computer Science & Engineering Fundamentals

D0015E

A broad survey course: Hammurabi strategy simulation, Arduino embedded programming, LaTeX typesetting, algorithm complexity analysis, and engineering ethics. Five modules, one course.

Hammurabi Arduino LaTeX Algorithm Analysis Engineering Ethics

Module A: Hammurabi simulation game

Govern ancient Sumeria for 10 years

Hammurabi is one of the earliest computer games, a resource-allocation strategy game named after the 2nd-millennium BC Babylonian king. Each year you decide how many acres to buy or sell, how much grain to feed your people, and how much to plant. Survive 10 years and your rule is evaluated against history's great leaders.

Module A · Hammurabi
Strategy simulation ★ Live demo

Full browser port of the classic Hammurabi game. Govern for 10 years: allocate grain, feed your people, plant crops, buy and sell land. Starve too many or let land per person drop and the people overthrow you.

Resource allocation Random events Strategy 1973 classic
↗ Standalone
Live Demo: Hammurabi
⚔ HAMMURABI
Govern ancient Sumeria for 10 years
Year 1
Population100
Grain2800
Acres1000
Land price18 bu/ac
Starved last year0
Immigrants0
  1. The game lasts 10 years, one decision per year.
  2. Each year: buy or sell acres, feed your people, and plant crops.
  3. Each person needs 20 bushels of grain per year to survive.
  4. Each person can till at most 10 acres.
  5. Each acre needs 1 bushel of seed to plant.
  6. Land price fluctuates from 17 to 26 bushels per acre.
  7. If too many people starve the people will overthrow you.
  8. Survive all 10 years and your rule is ranked against great figures in history.
Module B: Arduino & Embedded Systems

Circuits, sensors, and sound

Physical computing with Arduino. Four circuits exploring digital output, analog input, light-dependent resistors, and tone generation, building from a simple blinking LED up to a melody-playing buzzer that syncs with LEDs.

Module B · Arduino
Project 1: Four circuits

Progressive Arduino exercises: LED blink timing, potentiometer-controlled blink rate, LDR ambient light sensor driving LED brightness, and a buzzer playing a melody with LEDs alternating on each note.

Arduino digitalWrite / analogWrite analogRead tone() PWM
Circuit 1A: Two LEDs blink in sync
int ledRed  = 7;   // Red LED pin
int ledBlue = 6;   // Blue LED pin

void setup() {
    pinMode(ledRed,  OUTPUT);
    pinMode(ledBlue, OUTPUT);
}

void loop() {
    digitalWrite(ledRed,  HIGH);
    digitalWrite(ledBlue, HIGH);
    delay(2000);           // on for 2 seconds
    digitalWrite(ledRed,  LOW);
    digitalWrite(ledBlue, LOW);
    delay(2000);           // off for 2 seconds
}

// Variations tested:
// delay(500) / delay(3500)  →  short flash, long pause
// delay(1)   / delay(1)     →  PWM-like flicker at ~500 Hz
Module C: LaTeX Typesetting

Academic writing with LaTeX

Two mathematical documents typeset in LaTeX. The Koch Snowflake paper proves two theorems about the fractal's infinite perimeter and finite area using formal proof environments. The Ski Slope paper solves a Swedish national exam problem using calculus, finding where a hill is steepest by analysing the second derivative.

Module C · LaTeX
D1: Koch snowflake & D2: Ski slope

Two academic papers using LaTeX theorem/proof environments, aligned equations, figure insertion, and BibTeX citations.

LaTeX amsmath Theorem environments Calculus Fractals
D1_Snöflingan.sty: Koch Snowflake (key excerpts)
\section{A Famous Fractal: The Koch Snowflake}

The \emph{Koch snowflake} is based on work by the Swedish mathematician
Helge von Koch \cite{koch}. It is constructed from an equilateral triangle
by repeating this process infinitely:

\begin{quote}
  \textit{Divide all segments into three equal parts. For each middle
  segment, draw an outward equilateral triangle, then remove the middle.}
\end{quote}

% --- Theorem 1: Infinite perimeter ---
\begin{theorem}
  The Koch snowflake has infinite length.
\end{theorem}

\begin{proof}
Let $N_n = 3 \cdot 4^n$ be the number of segments after $n$ iterations,
and $L_n = s / 3^n$ the length of each segment.  Then
\[
  N_n L_n = 3s \left(\frac{4}{3}\right)^n \to \infty \quad (n \to \infty).
\]
Since $4/3 > 1$, the total length diverges.
\end{proof}

% --- Theorem 2: Finite area ---
\begin{theorem}
  The Koch snowflake has finite area.
\end{theorem}

\begin{proof}
In iteration $n$, the number of new triangles is $T_n = \tfrac{3}{4} \cdot 4^n$
and each has area $a_n = a_0 / 9^n$.  The total area after $n$ iterations:
\[
  A_n = \frac{a_0}{5}\!\left(8 - 3\!\left(\tfrac{4}{9}\right)^{\!n}\right)
  \;\xrightarrow{n\to\infty}\; \frac{8a_0}{5}  \quad \text{(finite)}.
\]
\end{proof}
Module D: Algorithm Analysis

Maximum subarray: three algorithms, three complexities

Finding the largest sum of a contiguous subsequence. Three approaches (O(n³) brute force, O(n²) with reuse, and O(n²) with prefix sums), analysed in a LaTeX report co-authored with a classmate.

Module D · Algorithms
Maximum subarray: Big-O analysis ★ Live demo

Compare all three algorithms visually. Enter a list of numbers and watch each approach find the maximum subarray, with step counts shown live.

O(n³) O(n²) Prefix sums Big-O Bentley 1984
Live Demo: Compare All Three Algorithms
← Highlighted cells = maximum subarray (highest sum contiguous slice)
Cubic: O(n³) brute force
// Three nested loops, all possible subsequences
// Time complexity: O(n³)
static int maxSubCubic(int[] a) {
    int maxSum = 0;
    for (int i = 0; i < a.length; i++) {
        for (int j = i; j < a.length; j++) {
            int sum = 0;
            for (int k = i; k <= j; k++)  // recompute sum each time
                sum += a[k];
            maxSum = Math.max(maxSum, sum);
        }
    }
    return maxSum;
}
// Steps: n³/6  →  if n doubles, steps × 8
Module E: Engineering Ethics & Professional Role

Yrkesrollen: the engineer's professional identity

A written assignment co-authored in LaTeX covering gender equality in tech, engineering virtues, professional licensing, and the ethics of refusing clients. Based on course readings from Sven Ove Hansson's Teknik och etik.

Module E · Ethics
Yrkesrollen assignment

Five questions on gender equality, engineering virtues, licensing, and professional ethics. Written in Swedish, co-authored with a classmate, typeset in LaTeX.

Engineering ethics Gender equality Professional role LaTeX Swedish
↗ PDF
Three benefits of active gender equality work
  1. Better decisions & innovation. Diverse groups have more perspectives and fewer blind spots. This improves user-centred design, risk assessment, and requirements analysis.
  2. Identifying and developing talent. An inclusive workplace attracts more candidates and reduces turnover, saving money and retaining key people long-term.
  3. Customer value, compliance & reputation. Actively promoting equality reduces legal risk, strengthens the brand, and opens new markets as products are designed for a broader audience.

What I learned

Games are state and rules.

Hammurabi is a handful of numbers that change once a year. Most of the work is checking that the player cannot spend more grain, land or people than there are.

Code can reach outside the screen.

With Arduino, a sensor is just a number to read and a lamp is just a pin to set, but the wiring has to be right as well as the code.