You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							47 lines
						
					
					
						
							957 B
						
					
					
				
			
		
		
	
	
							47 lines
						
					
					
						
							957 B
						
					
					
				using DelimitedFiles
 | 
						|
 | 
						|
course = readdlm("day2input.txt")
 | 
						|
 | 
						|
depth = 0
 | 
						|
horizontal = 0
 | 
						|
 | 
						|
for row in 1:size(course, 1)
 | 
						|
    global horizontal, depth
 | 
						|
    direction = course[row, 1]
 | 
						|
    value = course[row, 2]
 | 
						|
    if direction == "forward"
 | 
						|
        horizontal += value
 | 
						|
    elseif direction == "up"
 | 
						|
        depth -= value
 | 
						|
    elseif direction == "down"
 | 
						|
        depth += value
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
println("depth = ", depth)
 | 
						|
println("horiz = ", horizontal)
 | 
						|
println("prod  = ", depth * horizontal)
 | 
						|
 | 
						|
depth = 0
 | 
						|
horizontal = 0
 | 
						|
aim = 0
 | 
						|
 | 
						|
for row in 1:size(course, 1)
 | 
						|
    global horizontal, depth, aim
 | 
						|
    direction = course[row, 1]
 | 
						|
    value = course[row, 2]
 | 
						|
    if direction == "forward"
 | 
						|
        horizontal += value
 | 
						|
        depth += value * aim
 | 
						|
    elseif direction == "up"
 | 
						|
        aim -= value
 | 
						|
    elseif direction == "down"
 | 
						|
        aim += value
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
println("depth = ", depth)
 | 
						|
println("horiz = ", horizontal)
 | 
						|
println("aim   = ", aim)
 | 
						|
println("prod  = ", depth * horizontal)
 |