diff --git a/2020/day11/ex1-slow.bash b/2020/day11/ex1-slow.bash index 3a40432..3f89fe3 100755 --- a/2020/day11/ex1-slow.bash +++ b/2020/day11/ex1-slow.bash @@ -12,9 +12,9 @@ declare floor function adj() { local -i r="$1" n="$2" c="$3" count=0 - local -a prow=(${rows[r-1]}) - local -a row=(${rows[r]}) - local -a nrow=(${rows[r+1]}) + local -a prow=("${rows[r-1]}") + local -a row=("${rows[r]}") + local -a nrow=("${rows[r+1]}") #echo #echo p="${prow[*]}" #echo r="${row[*]}" @@ -51,7 +51,7 @@ function run() { changed=0 seated=0 for ((r=1; r<=NROWS; ++r)); do - row=(${rows[r]}) + row=("${rows[r]}") newrow=(0) for ((c=1; c<=RLENGTH; ++c)); do newrow+=("${row[c]}") @@ -61,13 +61,13 @@ function run() { case ${row[c]} in 0) continue ;; - 1) if (( $(adj $r $c 2) == 0 )); then + 1) if (( $(adj "$r" "$c" 2) == 0 )); then ((++changed)) newrow[c]=2 fi #printf "[%d][%d]: %s %s %d\n" $r $c "${row[c]}" "${newrow[c]}" $(adj $r $c 2) ;; - 2) if (( $(adj $r $c 2) >= 4 )); then + 2) if (( $(adj "$r" "$c" 2) >= 4 )); then ((++changed)) newrow[c]=1 fi diff --git a/2020/libsrc/debug.c b/2020/libsrc/debug.c index 9c5f981..cc18075 100644 --- a/2020/libsrc/debug.c +++ b/2020/libsrc/debug.c @@ -1,6 +1,6 @@ /* debug.c - debug/log management * - * Copyright (C) 2021 Bruno Raoult ("br") + * Copyright (C) 2021-2022 Bruno Raoult ("br") * Licensed under the GNU General Public License v3.0 or later. * Some rights reserved. See COPYING. * @@ -22,8 +22,9 @@ #include "bits.h" #include "debug.h" -#define NANOSEC 1000000000 /* nano sec in sec */ -#define MILLISEC 1000000 /* milli sec in sec */ +#define NS_SEC 1000000000 /* nano sec in sec */ +#define MS_SEC 1000000 /* microsec in sec */ +#define NS_MS 1000 /* nano in micro */ static long long timer_start; /* in nanosecond */ static u32 debug_level=0; @@ -41,7 +42,7 @@ void debug_init(u32 level) debug_level_set(level); if (!clock_gettime(CLOCK_MONOTONIC, &timer)) { - timer_start = timer.tv_sec * NANOSEC + timer.tv_nsec; + timer_start = timer.tv_sec * NS_SEC + timer.tv_nsec; } else { timer_start = 0; @@ -54,10 +55,9 @@ inline static long long timer_elapsed() struct timespec timer; clock_gettime(CLOCK_MONOTONIC, &timer); - return (timer.tv_sec * NANOSEC + timer.tv_nsec) - timer_start; + return (timer.tv_sec * NS_SEC + timer.tv_nsec) - timer_start; } - /* void debug - log function * @timestamp : boolean * @indent : indent level (2 spaces each) @@ -77,8 +77,8 @@ void debug(u32 level, bool timestamp, u32 indent, const char *src, if (timestamp) { long long diff = timer_elapsed(); - printf("%lld.%03lld ", diff/NANOSEC, (diff/1000000)%1000); - printf("%010lld ", diff); + printf("%lld.%03lld ", diff / NS_SEC, (diff % NS_SEC) / NS_MS); + printf("%010lldμs ", diff / NS_MS); } if (src) { diff --git a/2022/RESULTS.txt b/2022/RESULTS.txt index a3e1bc7..903e97d 100644 --- a/2022/RESULTS.txt +++ b/2022/RESULTS.txt @@ -5,17 +5,17 @@ +++++++++++++++++ part 1 aoc.bash: res=66719 time: 0:00.03 real, 0.02 user, 0.00 sys - context-switch: 0+1, page-faults: 0+274 + context-switch: 0+1, page-faults: 0+257 -aoc-c : res=66719 +aoc-c: res=66719 time: 0:00.00 real, 0.00 user, 0.00 sys - context-switch: 0+1, page-faults: 0+89 + context-switch: 0+1, page-faults: 0+88 +++++++++++++++++ part 2 aoc.bash: res=198551 time: 0:00.03 real, 0.03 user, 0.00 sys - context-switch: 2+1, page-faults: 0+283 + context-switch: 2+1, page-faults: 0+259 -aoc-c : res=198551 +aoc-c: res=198551 time: 0:00.00 real, 0.00 user, 0.00 sys - context-switch: 5+1, page-faults: 0+87 + context-switch: 0+1, page-faults: 0+87