summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2020-04-07 09:44:50 +0200
committerjonsykkel <jonrevold@gmail.com>2020-04-07 09:44:50 +0200
commit60577b2b48358d81f141e54821308191ea701a0b (patch)
tree1fd8a05f6d0f2d8b38f14fabfdf8542f98bf0a25
parent0cd2f683be106cae58df7cac11a37ef7ed679fcc (diff)
downloadct_sequence-60577b2b48358d81f141e54821308191ea701a0b.tar.gz
ok
-rw-r--r--makefile2
-rw-r--r--src/a3.c38
-rw-r--r--src/def.h4
3 files changed, 42 insertions, 2 deletions
diff --git a/makefile b/makefile
index c7670c9..3423546 100644
--- a/makefile
+++ b/makefile
@@ -55,7 +55,7 @@ ifneq ($(run),)
run_cmd := @echo "run $(bin)"
run_cmd += && cd bin
run_cmd += && echo "----------------------------------------------------------------"
- run_cmd += && time ./$(out_file) 100000000
+ run_cmd += && time ./$(out_file) -a3 100000000
run_cmd += ; echo "----------------------------------------------------------------"
run_cmd += && cd ..
endif
diff --git a/src/a3.c b/src/a3.c
new file mode 100644
index 0000000..dfe9b34
--- /dev/null
+++ b/src/a3.c
@@ -0,0 +1,38 @@
+#include "def.h"
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+void a3_init(uint64_t n);
+void a3_loop(uint64_t x0,uint64_t x1);
+
+algo_t a3 = {
+ .name = "a3",
+ .nmax = 1ULL<<32,
+ .init = a3_init,
+ .loop = a3_loop,
+};
+
+static uint16_t *m_fast; //mammory
+static uint32_t *m_slow; //mammory
+
+void a3_init(uint64_t n){
+ size_t size; //size
+
+ t = 0;
+ size = sizeof(uint32_t)*n;
+ m_slow = calloc(size,1);
+ if(!m_slow) fuk("memory\n");
+}
+
+void a3_loop(uint64_t x0,uint64_t x1){
+ uint32_t x1_32 = x1;
+ for(uint32_t x = x0;x < x1_32;x++){
+ uint32_t r; //index readed
+
+ r = m_slow[t];
+ m_slow[t] = x;
+ t = r == 0 ? 0 : x-r;
+ }
+}
+
diff --git a/src/def.h b/src/def.h
index 2ce6a94..0f3072a 100644
--- a/src/def.h
+++ b/src/def.h
@@ -25,14 +25,16 @@ extern uint64_t t;
extern algo_t a0;
extern algo_t a1;
extern algo_t a2;
+extern algo_t a3;
static algo_t *algos[] = {
[0] = &a0,
[1] = &a1,
[2] = &a2,
+ [3] = &a3,
};
-#define ALGO_CUNT (sizeof(algos)/sizeof(algo_t *))
+#define ALGO_CUNT (sizeof(algos)/sizeof(algo_t *))
void fuk(char const *fmt,...);