day 01
This commit is contained in:
		
						commit
						9b75ff3744
					
				
					 2 changed files with 21 additions and 0 deletions
				
			
		
							
								
								
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | |||
| solve | ||||
| input | ||||
							
								
								
									
										19
									
								
								day-01/solve.nim
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								day-01/solve.nim
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,19 @@ | |||
| import std/[algorithm, math, os, strutils, sugar] | ||||
| 
 | ||||
| let lst = stdin.readAll().strip() | ||||
| 
 | ||||
| let elves = lst.split("\n\n") | ||||
| 
 | ||||
| var totals = collect: | ||||
|   for elf in elves: | ||||
|     let elfInts = collect: | ||||
|       for cal in elf.split("\n"): | ||||
|         parseInt(cal) | ||||
|     sum(elfInts) | ||||
| 
 | ||||
| totals.sort(order = Descending) | ||||
| 
 | ||||
| if paramStr(1) == "1": | ||||
|   echo(totals[0]) | ||||
| elif paramStr(1) == "2": | ||||
|   echo(sum(totals[0..2])) | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue