diff --git a/check b/check index 2a419bff2a2959d327cc896a6ab8fe1c23dd6e19..95d28acf181946e329fca6cc5bf928d7547b3d58 100755 --- a/check +++ b/check @@ -1,2 +1,7 @@ #!/bin/bash +if [ $# -eq 0 ]; then + echo "Usage: check <input file>" + exit 0 +fi + ./loesung <$1 | ./check_result $1 diff --git a/loesung.c b/loesung.c index 89de1cba8669b795d59395d923a6c0b368fbfe95..ea40b12e6f210ebd88c58d4b8ae2e1407b7bfc6f 100755 --- a/loesung.c +++ b/loesung.c @@ -55,7 +55,7 @@ typedef struct Field { uint32_t num_odd; } Field; -// returns 0 if successful, nonzero if failed +// gibt 0 zurueck, wenn Initialisierung Erfolgreich durchgelaufen ist int field_init(Field *this) { memset(this, 0, sizeof(Field)); this->tiles = malloc(sizeof(Tile)); @@ -64,7 +64,8 @@ int field_init(Field *this) { return this->tiles == 0; } -// if an error occurs, all memory get freed +// fuegt p_tile zum dynamischen Array hinzu, im Fehlerfall muss immernoch +// der reservierte Speicher speicher freigegeben werden int field_push(Field *this, Tile *p_tile) { if (this->size == this->num_tiles) { if (this->size == 1u<<31) return 1; // catch overflow @@ -196,10 +197,8 @@ int field_neighbours(Field *this) { top = begin_line; begin_line = cur; // neue Zeile } - // ermitteln der Zeilen-Beziehung - if (begin_line != 1 && t[top].x < t[begin_line].x - 1) { - // Zeilensprung => Warten bis zur naechsten Zeile angekommen - } else if (t[top].x == t[cur].x - 1) { + // ermitteln der Zeilen-Beziehung, nur wenn obere Zeile ein ueber der aktuellen ist + if (t[top].x == t[cur].x - 1) { // finden, ob paar nach oben existiert O(n) fuer alle Nachbarn nach oben/unten. for(;t[top].y < t[cur].y && top < begin_line; top++); diff --git a/visualize.py b/visualize.py index 1a4093efdace8c6b3da79ea5d48fa7f94bc66762..e38d8eeba8ab83b2aa58f92cfe2ba3177744ccc9 100755 --- a/visualize.py +++ b/visualize.py @@ -2,9 +2,12 @@ import sys import matplotlib.pyplot as plt import numpy as np -inp = sys.argv[1] -def load(): +def main(): + if len(sys.argv) != 1: + print("Usage: visualize <input file>") + return + inp = sys.argv[1] f = open(inp) xs = [] ys = [] @@ -16,6 +19,6 @@ def load(): plt.scatter(xs, ys, marker="s") plt.show() -while True: - load() +if __name__ == "__main__": + main() diff --git a/visualize_result.py b/visualize_result.py index b4000aac902d60ea1cdc8062520258dc0cd655ea..5ae47010cefa5cb377a5570fe4c14ce01502c8a7 100755 --- a/visualize_result.py +++ b/visualize_result.py @@ -2,9 +2,12 @@ import sys import matplotlib.pyplot as plt import numpy as np -inp = sys.argv[1] -def load(): +def main(): + if len(sys.argv) != 1: + print("Usage: visualize <output file>") + return + inp = sys.argv[1] f = open(inp) xs = [] ys = [] @@ -19,6 +22,6 @@ def load(): plt.plot(xs, ys, marker="s") plt.show() -while True: - load() +if __name__ == "__main__": + main()