day 14 ivy solution
This commit is contained in:
		
							parent
							
								
									0247ce727a
								
							
						
					
					
						commit
						b6512dc6c1
					
				
							
								
								
									
										1
									
								
								day14/input.ivy
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								day14/input.ivy
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										38
									
								
								day14/sol.ivy
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								day14/sol.ivy
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,38 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					) get "input.ivy"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					dims = 101 103 # width, height
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					op t steps A = (A[;1 2] + t * A[;3 4]) mod dims
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					op show coords =
 | 
				
			||||||
 | 
					    pic = (*/dims) rho '.'
 | 
				
			||||||
 | 
					    pic[dims decode transp coords] = '#'
 | 
				
			||||||
 | 
					    transp dims rho pic
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					op qscore coords =
 | 
				
			||||||
 | 
					    x = coords[;1]
 | 
				
			||||||
 | 
					    y = coords[;2]
 | 
				
			||||||
 | 
					    m = floor dims / 2
 | 
				
			||||||
 | 
					    q1 = +/ (x < m[1]) and (y < m[2])
 | 
				
			||||||
 | 
					    q2 = +/ (x > m[1]) and (y < m[2])
 | 
				
			||||||
 | 
					    q3 = +/ (x < m[1]) and (y > m[2])
 | 
				
			||||||
 | 
					    q4 = +/ (x > m[1]) and (y > m[2])
 | 
				
			||||||
 | 
					    */(q1, q2, q3, q4)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# qscore@ (iota */dims) @steps A
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					op v minq t =
 | 
				
			||||||
 | 
					    t < 0: v[1]
 | 
				
			||||||
 | 
					    q = qscore (t steps v[3])
 | 
				
			||||||
 | 
					    q < v[2]: (t, q, box v[3]) minq (t-1)
 | 
				
			||||||
 | 
					    v minq (t-1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					op find A = (-1 1e100, box A) minq (*/dims)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#show 8270 steps input
 | 
				
			||||||
 | 
					qscore 100 steps input
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					t = find input
 | 
				
			||||||
 | 
					show (t steps input)
 | 
				
			||||||
 | 
					"t = ", t
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user