Added day 2 and 3, but didn't do them in rust like I wanted to.
This commit is contained in:
		
							
								
								
									
										2500
									
								
								2022/2/data.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2500
									
								
								2022/2/data.txt
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -8,6 +8,12 @@ enum RPS {
 | 
			
		||||
	Scissors,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum Result {
 | 
			
		||||
	Lose = 1,
 | 
			
		||||
	Draw,
 | 
			
		||||
	Win,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
RPS ToRPS(char c)
 | 
			
		||||
{
 | 
			
		||||
	if(c == 'A' || c == 'X')
 | 
			
		||||
@@ -46,6 +52,28 @@ bool Won(RPS us, RPS them)
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
RPS Which(RPS them, Result desired)
 | 
			
		||||
{
 | 
			
		||||
	if(desired == Result::Draw)
 | 
			
		||||
		return them; // same
 | 
			
		||||
 | 
			
		||||
	switch(them)
 | 
			
		||||
	{
 | 
			
		||||
	case RPS::Rock:
 | 
			
		||||
		if(desired == Result::Lose)
 | 
			
		||||
			return RPS::Scissors;
 | 
			
		||||
		return RPS::Paper;
 | 
			
		||||
	case RPS::Paper:
 | 
			
		||||
		if(desired == Result::Lose)
 | 
			
		||||
			return RPS::Rock;
 | 
			
		||||
		return RPS::Scissors;
 | 
			
		||||
	case RPS::Scissors:
 | 
			
		||||
		if(desired == Result::Lose)
 | 
			
		||||
			return RPS::Paper;
 | 
			
		||||
		return RPS::Rock;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Points(RPS us, RPS them)
 | 
			
		||||
{
 | 
			
		||||
	int rtn = 0;
 | 
			
		||||
@@ -73,16 +101,27 @@ int main()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	unsigned long total = 0;
 | 
			
		||||
	unsigned long new_total = 0;
 | 
			
		||||
 | 
			
		||||
	for(std::string line; std::getline(ifs, line); )
 | 
			
		||||
	{
 | 
			
		||||
		char them = line[0];
 | 
			
		||||
		char us = line[2];
 | 
			
		||||
 | 
			
		||||
		Result r = Result::Lose;
 | 
			
		||||
		if(us == 'Y')
 | 
			
		||||
			r = Result::Draw;
 | 
			
		||||
		else if(us == 'Z')
 | 
			
		||||
			r = Result::Win;
 | 
			
		||||
 | 
			
		||||
		RPS todo = Which(ToRPS(them), r);
 | 
			
		||||
 | 
			
		||||
		total += Points(ToRPS(us), ToRPS(them));
 | 
			
		||||
		new_total += Points(todo, ToRPS(them));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	std::cout << "Total: " << total << std::endl;
 | 
			
		||||
	std::cout << "    Total: " <<     total << std::endl;
 | 
			
		||||
	std::cout << "New Total: " << new_total << std::endl;
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user