JS (ez)
This commit is contained in:
		
							parent
							
								
									21e6980087
								
							
						
					
					
						commit
						3a3d8dbe38
					
				
							
								
								
									
										22
									
								
								js/2015/1/problem.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								js/2015/1/problem.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | |||||||
|  | const fs = require('node:fs'); | ||||||
|  | 
 | ||||||
|  | fs.readFile('../data/2015/1/input.txt', (err, input) => { | ||||||
|  |   let floor = 0; | ||||||
|  |   for (c of input) { | ||||||
|  |     const paren = String.fromCharCode(c); | ||||||
|  |     if (paren == '(') floor++; | ||||||
|  |     else if (paren == ')') floor--; | ||||||
|  |   } | ||||||
|  |   console.log(`Part 1: ${floor}`); | ||||||
|  | 
 | ||||||
|  |   floor = 0; | ||||||
|  |   let steps = 0; | ||||||
|  |   for (c of input) { | ||||||
|  |     const paren = String.fromCharCode(c); | ||||||
|  |     if (paren == '(') floor++; | ||||||
|  |     else if (paren == ')') floor--; | ||||||
|  |     steps++; | ||||||
|  |     if (floor < 0) break; | ||||||
|  |   } | ||||||
|  |   console.log(`Part 2: ${steps}`); | ||||||
|  | }); | ||||||
							
								
								
									
										6
									
								
								js/bin/run
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										6
									
								
								js/bin/run
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,6 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | 
 | ||||||
|  | year=$1 | ||||||
|  | day=$2 | ||||||
|  | 
 | ||||||
|  | time node $year/$day/problem.js | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user