Added day 7
This commit is contained in:
		
							
								
								
									
										2000
									
								
								day07/input.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2000
									
								
								day07/input.txt
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										4
									
								
								day07/part1.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								day07/part1.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					abba=(s)=>(s.split("").reduce((a, b, i, c)=>((i < 3) ? (a) : (((c[i] == c[i - 3]) && (c[i - 1] == c[i - 2]) && (c[i] != c[i - 1])) || a)), false));
 | 
				
			||||||
 | 
					var input = require("fs").readFileSync("input.txt").toString().replace(/\r/g, "");
 | 
				
			||||||
 | 
					var ips = input.split("\n").filter((s)=>(abba(s))).filter((s)=>(!s.match(/\[[^\]]+\]/g).reduce((a, b)=>(abba(b) || a), false)));
 | 
				
			||||||
 | 
					console.log(ips.length)
 | 
				
			||||||
							
								
								
									
										4
									
								
								day07/part2.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								day07/part2.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					aba=(s)=>(s.split("").reduce((a, b, i, c)=>{if(((c[i] == c[i - 2]) && (c[i] != c[i - 1]))){a.push(c[i-1] + c[i] + c[i-1]);} return a;}, []));
 | 
				
			||||||
 | 
					var input = require("fs").readFileSync("input.txt").toString().replace(/\r/g, "");
 | 
				
			||||||
 | 
					var ips = input.split("\n").filter((s)=>(aba(s.split(/\[[^\]]+\]/g).join("")).reduce((a, b)=>((s.match(/\[[^\]]+\]/g).join("").indexOf(b) != -1) || a), false)))
 | 
				
			||||||
 | 
					console.log(ips.length)
 | 
				
			||||||
		Reference in New Issue
	
	Block a user