summaryrefslogtreecommitdiffstats
path: root/mat/advent/7
diff options
context:
space:
mode:
authorsijanec <sijanecantonluka@gmail.com>2020-12-14 12:10:03 +0100
committersijanec <sijanecantonluka@gmail.com>2020-12-14 12:10:03 +0100
commita5bb97398b629e41caf7ca75496d0476aa6d44bd (patch)
tree4fd73762cae08efb507a90f014a30339ec0a1f5a /mat/advent/7
parentMerge branch 'master' of https://git.šijanec.eu/sijanec/sola-gimb-2 (diff)
downloadsola-gimb-2-a5bb97398b629e41caf7ca75496d0476aa6d44bd.tar
sola-gimb-2-a5bb97398b629e41caf7ca75496d0476aa6d44bd.tar.gz
sola-gimb-2-a5bb97398b629e41caf7ca75496d0476aa6d44bd.tar.bz2
sola-gimb-2-a5bb97398b629e41caf7ca75496d0476aa6d44bd.tar.lz
sola-gimb-2-a5bb97398b629e41caf7ca75496d0476aa6d44bd.tar.xz
sola-gimb-2-a5bb97398b629e41caf7ca75496d0476aa6d44bd.tar.zst
sola-gimb-2-a5bb97398b629e41caf7ca75496d0476aa6d44bd.zip
Diffstat (limited to 'mat/advent/7')
-rw-r--r--mat/advent/7/Makefile2
-rwxr-xr-xmat/advent/7/a.outbin0 -> 8432 bytes
-rw-r--r--mat/advent/7/prog.c31
3 files changed, 33 insertions, 0 deletions
diff --git a/mat/advent/7/Makefile b/mat/advent/7/Makefile
new file mode 100644
index 0000000..ee0ed1a
--- /dev/null
+++ b/mat/advent/7/Makefile
@@ -0,0 +1,2 @@
+default:
+ gcc -pedantic prog.c
diff --git a/mat/advent/7/a.out b/mat/advent/7/a.out
new file mode 100755
index 0000000..66f1e58
--- /dev/null
+++ b/mat/advent/7/a.out
Binary files differ
diff --git a/mat/advent/7/prog.c b/mat/advent/7/prog.c
new file mode 100644
index 0000000..7549d6b
--- /dev/null
+++ b/mat/advent/7/prog.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <stdlib.h>
+/* opozorilo za prihodnost:
+ * to je zelo slab način za rešitev naloge. prosim, naredi mi uslugo in ga ne uporabljaj!
+ * -- a, 2020 */
+int main (int argc, char ** argv) {
+ if (argc != 1+1) {
+ fprintf(stderr, "uporaba: %s <številka>\nprimer: %s 300\n", argv[0], argv[0]);
+ return 1;
+ }
+ unsigned long int b = strtol(argv[1], NULL, 10);
+ unsigned long int x = b;
+ unsigned long int y = x;
+ unsigned long int z = x;
+ unsigned long long int i = 0;
+ unsigned long long int r = 0;
+ unsigned long long int s = 0; /* število najdenih in zapiSanih trojk */
+ for (x = b; x > 0; x--) {
+ for (y = x; y > 0; y--) {
+ for (z = y; z > 0; z--) {
+ r++;
+ /* fprintf(stderr, "sum = %lu\n", x+y+z); */
+ if ((x+y+z) % 3 == 0) {
+ s++;
+ }
+ }
+ }
+ }
+ fprintf(stdout, "\rkonec: našel sem skupno %llu trojk, r==%llu.\n", s, r);
+ return 0;
+}