🥱 2024 Day 2
This commit is contained in:
		
							parent
							
								
									15024dbdaf
								
							
						
					
					
						commit
						ac8563d39c
					
				
							
								
								
									
										16
									
								
								2024/02/01.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										16
									
								
								2024/02/01.py
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env python3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					INPUT_FILE = 'input.txt'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def main():
 | 
				
			||||||
 | 
					    reports = [list(map(int, vals.split())) for vals in open(INPUT_FILE, 'r').readlines()]
 | 
				
			||||||
 | 
					    safe_reports = 0
 | 
				
			||||||
 | 
					    for report in reports:
 | 
				
			||||||
 | 
					        ok = all([1 <= abs(report[i] - report[i + 1]) <= 3 for i in range(len(report) - 1 )])
 | 
				
			||||||
 | 
					        is_sorted = report == sorted(report) or report == sorted(report, reverse=True)
 | 
				
			||||||
 | 
					        if ok and is_sorted: safe_reports += 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    print(safe_reports)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if __name__ == '__main__':
 | 
				
			||||||
 | 
					    main()
 | 
				
			||||||
							
								
								
									
										1000
									
								
								2024/02/input.txt
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										1000
									
								
								2024/02/input.txt
									
									
									
									
									
										Executable file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Loading…
	
		Reference in New Issue
	
	Block a user