Skip to content

Instantly share code, notes, and snippets.

@melnaquib
Last active August 29, 2015 13:55
Show Gist options
  • Save melnaquib/8720992 to your computer and use it in GitHub Desktop.
Save melnaquib/8720992 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
(void) argc;
(void) argv;
//stores the last two terms, and the new sum
int terms[] = {1, 2, 3};
//stores indeces used to access the above array,
// it cycles periodically, so one time I'm summing the last two which are the 0th and 1st into 2nd term, the new one
//next time I sum the the last two, which now are the 2nd and the 0th into the new sum which is the 1st, so on and so forth...
const char INDECES[3][3] = {
{0, 1, 2},
{1, 2, 0},
{2, 0, 1}
};
const char *indeces = INDECES[2];
int TERM_MAX = 4000000;
long int sum = terms[1];
do {
if(!(terms[indeces[0]] & 1))
sum += terms[indeces[0]];
//cycle indices
if(0 == indeces[0])
indeces = INDECES[1];
else if(1 == indeces[0])
indeces = INDECES[2];
else
indeces = INDECES[0];
terms[indeces[0]] = terms[indeces[1]] + terms[indeces[2]];
} while(terms[indeces[0]] < TERM_MAX);
fprintf(stderr, "%i", sum);
return 0;
}
@emad-elsaid
Copy link

انا دماغى لفت من الحل ده ... feeling dizzy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment