Created
December 14, 2018 20:17
-
-
Save lethern/16916dc082263b82703ad0399413a0f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <list> | |
| using namespace std; | |
| list<int> A ={ 3,7 }; | |
| list<int>::iterator elf1 = A.begin(); | |
| list<int>::iterator elf2 = ++A.begin(); | |
| void move_A_iterator( list<int>::iterator & it, int steps ) { | |
| while( steps-- ) { | |
| ++it; | |
| if( it == A.end() ) | |
| it = A.begin(); | |
| } | |
| } | |
| void simulate() { | |
| int sum = *elf1 + *elf2; | |
| if( sum >= 10 ) { | |
| A.push_back( 1 ); | |
| } | |
| A.push_back( sum % 10 ); | |
| int steps = *elf1 + 1; | |
| move_A_iterator( elf1, steps ); | |
| steps = *elf2 + 1; | |
| move_A_iterator( elf2, steps ); | |
| } | |
| void print_all() { | |
| for( auto it = A.begin(); it != A.end(); ++it ) { | |
| printf( "%d ", *it ); | |
| } | |
| printf( "\n" ); | |
| } | |
| int main() { | |
| int expected_amount = 9 + 10; | |
| while( A.size() < expected_amount ) { | |
| simulate(); | |
| } | |
| //print_all(); | |
| auto last_it = std::prev( A.end(), (10 + A.size()- expected_amount)); | |
| for( int i=0; i < 10; ++i ) { | |
| printf( "%d", *last_it ); | |
| ++last_it; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment