day 4 ivy
This commit is contained in:
		
							parent
							
								
									e7afa95c6d
								
							
						
					
					
						commit
						d6333ce7e8
					
				
							
								
								
									
										1000
									
								
								day04/input
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1000
									
								
								day04/input
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										1
									
								
								day04/input.ivy
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								day04/input.ivy
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										20
									
								
								day04/sol.ivy
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								day04/sol.ivy
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,20 @@ | ||||
| 
 | ||||
| sample = 6 4 rho 2 4 6 8   2 3 4 5   5 7 7 9   2 8 3 7   6 6 4 6   2 6 4 8 | ||||
| ) get "input.ivy" | ||||
| 
 | ||||
| op r overlaps s = not (r[2] < s[1]) or (s[2] < r[1]) | ||||
| op r contains s = (r[1] <= s[1]) and (s[2] <= r[2]) | ||||
| 
 | ||||
| op contains x = (x[1 2] contains x[3 4]) or (x[3 4] contains x[1 2]) | ||||
| op overlaps x = (x[1 2] overlaps x[3 4]) | ||||
| 
 | ||||
| #1 3 overlaps 4 5 | ||||
| #1 5 overlaps 2 7 | ||||
| #contains 1 2 3 4 | ||||
| #contains 5 10 7 8 | ||||
| 
 | ||||
| +/ contains transp sample | ||||
| +/ contains transp input | ||||
| 
 | ||||
| +/ overlaps transp sample | ||||
| +/ overlaps transp input | ||||
							
								
								
									
										34
									
								
								day04/toivy.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										34
									
								
								day04/toivy.py
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,34 @@ | ||||
| #!/usr/bin/env python3 | ||||
| 
 | ||||
| """ | ||||
| Converts a text file containing a list of integers | ||||
| into a format that can be loaded by ivy. | ||||
| """ | ||||
| 
 | ||||
| with open("input") as f: | ||||
|     lines = f.read().splitlines() | ||||
| 
 | ||||
| data = [] | ||||
| for line in lines: | ||||
|     line = line.replace("-", ",") | ||||
|     data.append(line.split(",")) | ||||
| 
 | ||||
| def count(row): | ||||
|     n = 0 | ||||
|     for x in row: | ||||
|         if x.isdigit(): | ||||
|             n += 1 | ||||
|         else: | ||||
|             n += len(x) | ||||
|     return n | ||||
|          | ||||
| cols = max(map(count, data)) | ||||
| 
 | ||||
| print("input = {} {} rho".format(len(data), cols), end="") | ||||
| for row in data: | ||||
|     print("", " ".join( | ||||
|         x if x.isdigit() else repr(x) | ||||
|         for x in row), end="") | ||||
|     n = count(row) | ||||
|     if n < cols: | ||||
|         print(" 0" * (cols - n), end="") | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user