diff options
author | sijanec <sijanecantonluka@gmail.com> | 2020-12-14 12:10:03 +0100 |
---|---|---|
committer | sijanec <sijanecantonluka@gmail.com> | 2020-12-14 12:10:03 +0100 |
commit | a5bb97398b629e41caf7ca75496d0476aa6d44bd (patch) | |
tree | 4fd73762cae08efb507a90f014a30339ec0a1f5a /mat/advent | |
parent | Merge branch 'master' of https://git.šijanec.eu/sijanec/sola-gimb-2 (diff) | |
download | sola-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')
-rw-r--r-- | mat/advent/7/Makefile | 2 | ||||
-rwxr-xr-x | mat/advent/7/a.out | bin | 0 -> 8432 bytes | |||
-rw-r--r-- | mat/advent/7/prog.c | 31 |
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 Binary files differnew file mode 100755 index 0000000..66f1e58 --- /dev/null +++ b/mat/advent/7/a.out 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; +} |