Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- int main(int argc, char ** argv) {
- if(argc < 2) printf("need input\n");
- uint32_t limit = argc < 3 ? 25000000 : strtoul(argv[2], NULL, 10);
- uint64_t input = 0;
- char * c = argv[1];
- while(*++c);
- while(c-- != argv[1]) {
- input <<= 8;
- input += *c - '0';
- }
- uint8_t * recipes = malloc(sizeof(uint8_t)*limit);
- recipes[0] = 3;
- recipes[1] = 7;
- uint32_t elf1=0, elf2=1, len=2;
- uint8_t score;
- for(int i=2;i<limit;i++) recipes[i] = 0xae;
- while (len < limit) {
- score = recipes[elf1] + recipes[elf2];
- if (score < 10) {
- recipes[len] = score;
- len += 1;
- } else {
- recipes[len] = score/10;
- recipes[len+1] = score%10;
- len += 2;
- }
- elf1 = (elf1 + recipes[elf1] + 1) % len;
- elf2 = (elf2 + recipes[elf2] + 1) % len;
- if (((*(uint64_t*)(recipes+len-6) & 0xffffffffffff) == input)
- ||((*(uint64_t*)(recipes+len-7) & 0xffffffffffff) == input))
- break;
- }
- if (len >= limit)
- printf("Limit %d reached, try increasing (arg 2)\n", limit);
- else
- printf("%u\n", len-(score<10?6:7));
- free(recipes);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement