day 1 solution
This commit is contained in:
		
							parent
							
								
									829c87d96d
								
							
						
					
					
						commit
						1646399f9f
					
				
							
								
								
									
										1000
									
								
								day01/input
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1000
									
								
								day01/input
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										4
									
								
								day01/sample1.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								day01/sample1.in
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | |||||||
|  | 1abc2 | ||||||
|  | pqr3stu8vwx | ||||||
|  | a1b2c3d4e5f | ||||||
|  | treb7uchet | ||||||
							
								
								
									
										7
									
								
								day01/sample2.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								day01/sample2.in
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,7 @@ | |||||||
|  | two1nine | ||||||
|  | eightwothree | ||||||
|  | abcone2threexyz | ||||||
|  | xtwone3four | ||||||
|  | 4nineeightseven2 | ||||||
|  | zoneight234 | ||||||
|  | 7pqrstsixteen | ||||||
							
								
								
									
										2
									
								
								day01/sol.awk
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								day01/sol.awk
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | |||||||
|  | { gsub("[^0-9]", " "); gsub("[0-9]", "& "); n = $1 $NF; T += n; print n } | ||||||
|  | END { print T } | ||||||
							
								
								
									
										18
									
								
								day01/sol2.awk
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								day01/sol2.awk
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,18 @@ | |||||||
|  | { | ||||||
|  |  d1 = ""; | ||||||
|  |  d2 = ""; | ||||||
|  |  if (match($0, "one|two|three|four|five|six|seven|eight|nine|[0-9]")) { d1 = substr($0,RSTART,RLENGTH) } | ||||||
|  |  for (i = length($0); i > 0; i--) { | ||||||
|  |     s = substr($0, i); | ||||||
|  |     if (match(s, "one|two|three|four|five|six|seven|eight|nine|[0-9]")) { d2 = substr(s,RSTART,RLENGTH); break; } | ||||||
|  |  } | ||||||
|  |  n = d1 d2; | ||||||
|  |  print n; | ||||||
|  |  gsub("one","1",n); gsub("two","2",n); gsub("three","3",n); | ||||||
|  |  gsub("four","4",n); gsub("five","5",n); gsub("six","6",n); | ||||||
|  |  gsub("seven","7",n); gsub("eight","8",n); gsub("nine","9",n); | ||||||
|  |  T += n; | ||||||
|  |  print $0, n; | ||||||
|  | } | ||||||
|  | #{ print $0 } | ||||||
|  | END { print T } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user