src/bug_06.cpp
// Solution for both 6.0 and 6.1, but a very bad one.
// I know how to detect a loop without big history arrays,
// but couldn't come up with how to count loop size and entering step number.
// At least not during 30 minutes I gave this problem.
Solution for both 6.0 and 6.1, but a very bad one.
I know how to detect a loop without big history arrays,
but couldn't come up with how to count loop size and entering step number.
At least not during 30 minutes I gave this problem.
Solution for both 6 . 0 and 6 . 1 but a very bad one . I know how to detect a loop without big history arrays but couldn ' t come up with how to count loop size and entering step number . At least not during 30 minutes I gave this problem .
void BugFix<6>::solve1st()
{
	std::vector<size_t> blocks, blocks_copy;
	int number = 0;
	while (*mIn >> number)
	{
		blocks.push_back(number);
	}
	bool stop = false;
	size_t period = 0;
	size_t repeatInd = 0;
	std::vector<std::string> history;
	history.push_back(toString(blocks));
	while (!stop)
	{
		distribute(blocks, findMax(blocks));
		++period;
		auto const toStr = toString(blocks);
		for (size_t i = 0; i < history.size(); ++i)
		{
			if (toStr == history[i])
			{
				repeatInd = i;
				stop = true;
				break;
			}
		}
		if (!stop)
			history.push_back(toStr);
	}
	*mOut << period << " " << history.size() - repeatInd << std::endl;
}
void BugFix < 6 > :: solve1st ( ) { std :: vector < size_t > blocks , blocks_copy ; int number = 0 ; while ( * mIn >> number ) { blocks . push_back ( number ) ; } bool stop = false ; size_t period = 0 ; size_t repeatInd = 0 ; std :: vector < std :: string > history ; history . push_back ( toString ( blocks ) ) ; while ( ! stop ) { distribute ( blocks , findMax ( blocks ) ) ; ++ period ; auto const toStr = toString ( blocks ) ; for ( size_t i = 0 ; i < history . size ( ) ; ++ i ) { if ( toStr == history [ i ] ) { repeatInd = i ; stop = true ; break ; } } if ( ! stop ) history . push_back ( toStr ) ; } * mOut << period << " " << history . size ( ) - repeatInd << std :: endl ; }
Solution for both 6.0 and 6.1, but a very bad one.
Solution for both 6 . 0 and 6 . 1 but a very bad one .