day 2, trivial, mostly parsing
This commit is contained in:
		
							
								
								
									
										25
									
								
								d02/part1.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								d02/part1.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
m_red=12
 | 
			
		||||
m_green =13
 | 
			
		||||
m_blue = 14
 | 
			
		||||
 | 
			
		||||
R = 0
 | 
			
		||||
for i,l in enumerate(sys.stdin.readlines()):
 | 
			
		||||
    _, l = l[:-1].split(':')
 | 
			
		||||
    tirages = l.split(';')
 | 
			
		||||
    possible = True
 | 
			
		||||
    for tirage in tirages:
 | 
			
		||||
        cubes = tirage.split(',')
 | 
			
		||||
        for cube in cubes:
 | 
			
		||||
            _, q, c = cube.split(' ')
 | 
			
		||||
            q = int(q)
 | 
			
		||||
            if c == 'red' and q>m_red:
 | 
			
		||||
                possible = False
 | 
			
		||||
            if c == 'green' and q>m_green:
 | 
			
		||||
                possible = False
 | 
			
		||||
            if c == 'blue' and q>m_blue:
 | 
			
		||||
                possible = False
 | 
			
		||||
    R += possible * (i+1)
 | 
			
		||||
 
 | 
			
		||||
print(R)
 | 
			
		||||
							
								
								
									
										22
									
								
								d02/part2.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								d02/part2.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
R = 0
 | 
			
		||||
for i,l in enumerate(sys.stdin.readlines()):
 | 
			
		||||
    _, l = l[:-1].split(':')
 | 
			
		||||
    tirages = l.split(';')
 | 
			
		||||
    m_red = m_green = m_blue = 0
 | 
			
		||||
    for tirage in tirages:
 | 
			
		||||
        cubes = tirage.split(',')
 | 
			
		||||
        for cube in cubes:
 | 
			
		||||
            _, q, c = cube.split(' ')
 | 
			
		||||
            q = int(q)
 | 
			
		||||
            if c == 'red':
 | 
			
		||||
                m_red = max(m_red, q)
 | 
			
		||||
            if c == 'green':
 | 
			
		||||
                m_green = max(m_green, q)
 | 
			
		||||
            if c == 'blue':
 | 
			
		||||
                m_blue = max(m_blue, q)
 | 
			
		||||
    p = m_red * m_green* m_blue 
 | 
			
		||||
    R += p
 | 
			
		||||
print(R)
 | 
			
		||||
		Reference in New Issue
	
	Block a user