summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2020-03-30 19:44:58 +0200
committerjonsykkel <jonrevold@gmail.com>2020-03-30 19:44:58 +0200
commitdedabf9d1e86d31b0a5776077bfae778dd901c0d (patch)
tree37a6d9a3e894dcb1faebe343598b03f252e544d9
parent0795d9dbd0872d07462dfea0e3b5591b5bb3f9b1 (diff)
downloadct_pouring-dedabf9d1e86d31b0a5776077bfae778dd901c0d.tar.gz
bubl
-rw-r--r--src/main.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index ee816c1..8737af3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -9,7 +9,6 @@ int main(int argc,char **argv){
int32_t l;
int32_t r;
- /*
srand(20);
w = 10000;
i = malloc(sizeof(int32_t)*w);
@@ -17,16 +16,18 @@ int main(int argc,char **argv){
for(int32_t x = 0;x < w;x++){
i[x] = (int32_t)rand() & 0xFFFF;
}
- */
- int32_t _i[] = {0,0,0,0,4,1,3,4,1,3,2,0,4,3,2,1,5,2,0,4,3,1,5,2,1,3,0,2,4,2,5,0,1,3,3};
+ /*
+ int32_t _i[] = {4, 3, 7, 8, 9, 9, 9, 6, 6, 10, 9, 5, 9, 3, 10, 5, 5, 7, 8, 8, 8, 8, 8, 4, 9, 6, 9, 7, 5, 6, 5, 9, 10, 7, 1, 2, 5, 2, 8, 6, 3, 1, 8, 3, 5, 7, 6, 2, 4, 5, 4, 8, 10, 2, 4, 5, 6, 6, 7, 9, 2, 5, 7, 6, 9, 4, 8, 1, 8, 10, 7, 7, 7, 5, 6, 1, 3, 1, 2, 10, 2, 5, 3, 5, 5, 8, 5, 4, 3, 6, 8, 6, 9, 9, 2, 9, 5, 4, 6, 3};
w = sizeof(_i)/sizeof(*_i);
i = _i;
+ */
+
+ /*
l = 0;
r = w-1;
v = 0;
-
while(1){
for(int32_t x = l;x <= r;x++){
if(!i[x]) continue;
@@ -50,6 +51,39 @@ cunt:
i[x] &= ~z;
}
}
+ */
+
+ v = 0;
+
+ int32_t c;
+
+ while(1){
+ while(w){
+ if(*i) goto cunt;
+ i++;
+ w--;
+ }
+ break;
+
+cunt:
+ c = 0;
+ l = 0;
+
+ i[0]--;
+ for(int32_t x = 1;x < w;x++){
+ int32_t z;
+
+ i[x]--;
+ z = i[x]>>31;
+ i[x] &= ~z;
+ c += (x-l-1) & ~z;
+ l = (l & z) | (x & ~z);
+ }
+
+ w = l+1;
+ v += c;
+ }
+
printf("%d\n",v);