Konzeptphase: Die Modelle sind fertig, Workshops und Baustation in Vorbereitung. Alles ist offen und frei nutzbar.
← Informatik-Challenge← Informatics challenge
Informatik-Challenge 1 · Programmieren · Klasse 8–13Informatics challenge 1 · Programming · grades 8–13

Vom Höhenmodell zum SteinFrom height map to bricks

Unsere Modelle entstehen aus Geodaten: Ein Programm macht aus dem Höhenmodell kleine Würfel (Voxel), fasst sie zu echten Steinen zusammen und prüft, ob alles hält. Genau diese drei Schritte programmierst du hier in JavaScript – mit echten Daten aus unserem Modell der Bruchhauser Steine bei Olsberg.

Our models are computed from geodata: a program turns the height model into little cubes (voxels), merges them into real bricks and checks that everything holds. You program exactly these three steps here in JavaScript – with real data from our model of the Bruchhauser Steine near Olsberg.

Level 1 · Steine zählen

Ein Höhenmodell sagt für jedes Feld, wie hoch das Gelände ist. Hier ist es ein Ausschnitt von 16 × 16 Noppen am Goldstein, einem der Felsen der Bruchhauser Steine (1 Noppe ≈ 2,1 m in echt). Jede Zahl ist eine Säule aus so vielen Steinlagen. Die einfachste Bauanleitung: Jede Lage jeder Säule wird ein 1 × 1-Stein.

Aufgabe: Schreibe die Funktion, die zählt, wie viele 1 × 1-Steine das sind.

countBricks(heights) → Zahl
  • heights[y][x] ist die Höhe an der Stelle (x, y): eine Liste von Zeilen, y = 0 ist die südlichste Zeile.
  • Die Tests probieren erst kleine Karten aus, dann den echten Ausschnitt.

Level 1 · Count the bricks

A height model tells you how high the ground is at every cell. Here it is an excerpt of 16 × 16 studs at the Goldstein, one of the rocks of the Bruchhauser Steine (1 stud ≈ 2.1 m in reality). Every number is a column of that many brick layers. The simplest building plan: every layer of every column becomes one 1 × 1 brick.

Task: write the function that counts how many 1 × 1 bricks that is.

countBricks(heights) → number
  • heights[y][x] is the height at (x, y): a list of rows, y = 0 is the southernmost row.
  • The tests try small maps first, then the real excerpt.
Strg+Enter führt ausruns

Dein Code läuft nur in deinem Browser (Web Worker, Zeitlimit 4 s) und wird nur dort gespeichert. Hilfe beim Suchen: console.log(…) schreibt hier unten hin.Your code runs only in your browser (web worker, 4 s time limit) and is stored only there. Debugging: console.log(…) prints below the editor.

TestsTests

    Tipp 1: Wie sind die Daten aufgebaut?Hint 1: how is the data organised?

    heights ist eine Liste von Zeilen. heights.length ist die Anzahl der Zeilen, heights[y] ist eine Zeile und heights[y][x] eine einzelne Zahl. Probier console.log(heights.length, heights[0]).

    heights is a list of rows. heights.length is the number of rows, heights[y] is one row and heights[y][x] a single number. Try console.log(heights.length, heights[0]).

    Tipp 2: Zwei SchleifenHint 2: two loops

    Eine äußere Schleife über die Zeilen, eine innere über die Spalten. Nimm heights[y].length für die innere Grenze – dann klappt es auch mit nicht quadratischen Karten.

    An outer loop over the rows, an inner one over the columns. Use heights[y].length as the inner limit – then it also works for maps that are not square.

    for (let y = 0; y < heights.length; y++) {
      for (let x = 0; x < heights[y].length; x++) {
        // …
      }
    }
    Tipp 3: Was zählt man?Hint 3: what do you count?

    Eine Säule der Höhe 5 braucht 5 Steine. Du musst also nur alle Zahlen addieren: count += heights[y][x];

    A column of height 5 needs 5 bricks. So you just add up all the numbers: count += heights[y][x];

    Die DatenThe data

    Beide Ausschnitte stammen aus unserem fertigen Modell der Bruchhauser Steine (1 Noppe ≈ 2,1 m). Du kannst sie herunterladen und auch in Python oder einer anderen Sprache verwenden.

    Both excerpts come from our finished model of the Bruchhauser Steine (1 stud ≈ 2.1 m). You can download them and use them in Python or any other language, too.