summaryrefslogtreecommitdiffstats
path: root/mat/advent/7/prog.c
diff options
context:
space:
mode:
Diffstat (limited to 'mat/advent/7/prog.c')
-rw-r--r--mat/advent/7/prog.c31
1 files changed, 31 insertions, 0 deletions
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;
+}