Click here to Skip to main content
15,901,426 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Coding Challenge - ANSWER Pin
PeejayAdams5-Dec-17 22:48
PeejayAdams5-Dec-17 22:48 
GeneralRe: Coding Challenge - ANSWER Pin
Paulo_JCG12-Dec-17 4:59
professionalPaulo_JCG12-Dec-17 4:59 
GeneralRe: Coding Challenge - ANSWER Pin
Dave Kreskowiak12-Dec-17 5:24
mveDave Kreskowiak12-Dec-17 5:24 
GeneralRe: Coding Challenge - Morris Sequence Pin
Paulo_JCG12-Dec-17 4:53
professionalPaulo_JCG12-Dec-17 4:53 
GeneralRe: Coding Challenge - Morris Sequence Pin
Member 1319430215-Mar-18 5:07
Member 1319430215-Mar-18 5:07 
GeneralRe: Coding Challenge - Morris Sequence Pin
Dave Kreskowiak15-Mar-18 5:53
mveDave Kreskowiak15-Mar-18 5:53 
GeneralRe: Coding Challenge - Morris Sequence Pin
Member 1319430215-Mar-18 6:23
Member 1319430215-Mar-18 6:23 
GeneralRe: Coding Challenge - Morris Sequence Pin
Member 1319430215-Mar-18 7:05
Member 1319430215-Mar-18 7:05 
Here's the code, it allows a param to specify the level, default is 100.

uint16384_t allows computation to slightly above level 40000.

#include <chrono>
#include <ctime>
#include <boost multiprecision="" cpp_int.hpp="">

// g++ xxx.cpp -std=c++11 -march=corei7
using namespace std;
using namespace boost::multiprecision;

typedef number<cpp_int_backend<1024 *="" 16,="" 1024="" unsigned_magnitude,="" unchecked,="" void=""> > uint16384_t;

uint32_t maxLevel = 100;

static chrono::time_point<chrono::system_clock> start, timeFinished;

const uint32_t levelSize[] = { 4, 7, 12, 12, 4, 5, 12, 6, 8, 10, // 1-10
10, 14, 12, 14, 18, 42, 42, 26, 14, 28, // 11-20
14, 24, 24, 5, 7, 10, 10, 8, 2, 9, // 21-30
9, 23, 2, 6, 32, 32, 8, 3, 5, 6, // 31-40
10, 18, 18, 6, 10, 8, 7, 8, 12, 20, // 41-50
34, 34, 20, 10, 7, 7, 11, 13, 21, 17, // 51-60
2, 1, 4, 7, 14, 14, 7, 4, 6, 8, // 61-70
10, 16, 28, 28, 9, 12, 12, 16, 18, 24, // 71-80
23, 16, 6, 5, 15, 6, 10, 10, 3, 27, // 81-90
27, 5 }; // 91-92


vector<uint32_t> levelEvolution[] = {

{63},
{64, 62},
{65},
{66},
{68}, // 1-5

{69},
{84, 55},
{70},
{71},
{76}, // 6-10

{77},
{82},
{78},
{79},
{80}, // 11-15

{81, 29, 91},
{81, 29, 90},
{81, 30},
{75, 29, 92},
{75, 32}, // 16-20

{72},
{73},
{74},
{83},
{86}, // 21-25

{87},
{88},
{89, 92},
{1},
{3}, // 26-30

{4},
{2, 61, 29, 85},
{5},
{28},
{24, 33, 61, 29, 91}, // 31-35

{24, 33, 61, 29, 90},
{7},
{8},
{9},
{10}, // 36-40

{21},
{22},
{23},
{11},
{19}, // 41-45

{12},
{13},
{14},
{15},
{18}, // 46-50

{16},
{17},
{20},
{6, 61, 29, 92},
{26}, // 51-55

{27},
{25, 29, 92},
{25, 29, 67},
{25, 29, 85},
{25, 29, 68, 61, 29, 89}, // 56-60

{61},
{33},
{40},
{41},
{42}, // 61-65

{43},
{38, 39},
{44},
{48},
{54}, // 66-70

{49},
{50},
{51},
{52},
{47, 38}, // 71-75

{47, 55},
{47, 56},
{47, 57},
{47, 58},
{47, 59}, // 76-80

{47, 60},
{47, 33, 61, 29, 92},
{45},
{46},
{53}, // 81-85

{38, 29, 89},
{38, 30},
{38, 31},
{34},
{36}, // 86-90

{35},
{37} // 91-92

};

uint16384_t levelCounts[92];
uint16384_t evolvedLevelCounts[92];

int main(int argc, char** argv)
{
if (argc != 1)
{
maxLevel = atoi(argv[1]);
if (maxLevel < 9)
{
maxLevel = 10;
}
}

start = chrono::system_clock::now();
time_t start_time = chrono::system_clock::to_time_t(start);

cout << "Starting run of " << maxLevel << " levels at " << ctime(&start_time) << endl;

for (auto& sequence: levelEvolution)
{
for (auto& seq: sequence )
{
--seq; // Adjust indices for 0-based array
}
}


for (uint32_t i = 0; i < 92; ++i)
{
levelCounts[i] = 0;
}

// Prime the counts for the starting level (9).

levelCounts[23] = 1;
levelCounts[38] = 1;

uint16384_t * workingCounts = levelCounts;
uint16384_t * evolvedCounts = evolvedLevelCounts;

for (uint32_t i = 9; i <= maxLevel; ++i)
{
for (uint32_t j = 0; j < 92; ++j)
{
evolvedCounts[j] = 0;
}

for (uint32_t j = 0; j < 92; ++j)
{
if (workingCounts[j] != 0)
{
for (auto& level: levelEvolution[j])
{
evolvedCounts[level] += workingCounts[j];
}
}
}

uint16384_t totals = 0;
for (uint32_t j = 0; j < 92; ++j)
{
if (evolvedCounts[j] != 0)
{
totals += evolvedCounts[j] * levelSize[j];
}
}
cout << i << " " << totals << endl;

swap(workingCounts, evolvedCounts);
}

timeFinished = chrono::system_clock::now();
chrono::duration<double> elapsed_seconds = timeFinished - start;
time_t end_time = chrono::system_clock::to_time_t(timeFinished);

cout << "finished computation at " << ctime(&end_time)
<< "elapsed time: " << elapsed_seconds.count() << "secs" << endl;
}
GeneralRe: Coding Challenge - Morris Sequence Pin
Dave Kreskowiak15-Mar-18 7:34
mveDave Kreskowiak15-Mar-18 7:34 
GeneralRe: Coding Challenge - Morris Sequence Pin
Member 1319430215-Mar-18 8:24
Member 1319430215-Mar-18 8:24 
GeneralThey're getting better. Pin
Jörgen Andersson30-Nov-17 7:58
professionalJörgen Andersson30-Nov-17 7:58 
GeneralRe: They're getting better. Pin
CPallini30-Nov-17 8:14
mveCPallini30-Nov-17 8:14 
GeneralRe: They're getting better. Pin
MarkTJohnson30-Nov-17 8:32
professionalMarkTJohnson30-Nov-17 8:32 
GeneralRe: They're getting better. Pin
ZurdoDev30-Nov-17 8:47
professionalZurdoDev30-Nov-17 8:47 
GeneralRe: They're getting better. Pin
Jeremy Falcon30-Nov-17 10:56
professionalJeremy Falcon30-Nov-17 10:56 
GeneralRe: They're getting better. Pin
Jörgen Andersson30-Nov-17 18:38
professionalJörgen Andersson30-Nov-17 18:38 
GeneralRe: They're getting better. Pin
Munchies_Matt30-Nov-17 21:09
Munchies_Matt30-Nov-17 21:09 
GeneralRIP Gomer Pyle (Jim Nabors) Pin
Cornelius Henning30-Nov-17 7:34
professionalCornelius Henning30-Nov-17 7:34 
GeneralRe: RIP Gomer Pyle (Jim Nabors) Pin
Marc Clifton30-Nov-17 7:38
mvaMarc Clifton30-Nov-17 7:38 
GeneralRe: RIP Gomer Pyle (Jim Nabors) Pin
raddevus30-Nov-17 8:11
mvaraddevus30-Nov-17 8:11 
GeneralRe: RIP Gomer Pyle (Jim Nabors) Pin
MarkTJohnson30-Nov-17 8:34
professionalMarkTJohnson30-Nov-17 8:34 
GeneralImportant! Updated Allergy Information Pin
PeejayAdams30-Nov-17 5:42
PeejayAdams30-Nov-17 5:42 
GeneralRe: Important! Updated Allergy Information Pin
Dave Kreskowiak30-Nov-17 5:49
mveDave Kreskowiak30-Nov-17 5:49 
GeneralRe: Important! Updated Allergy Information Pin
Richard MacCutchan30-Nov-17 5:50
mveRichard MacCutchan30-Nov-17 5:50 
GeneralRe: Important! Updated Allergy Information Pin
David Crow30-Nov-17 7:35
David Crow30-Nov-17 7:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Straw Poll

Were you affected by the geomagnetic storms this past weekend?
Communication disruptions, electrified pipes, random unexplained blue-screens in Windows - the list of effects is terrifying.
  Results   507 votes