day06: handle no match
This commit is contained in:
		
							parent
							
								
									93c1db7b57
								
							
						
					
					
						commit
						d04337ce03
					
				
					 1 changed files with 2 additions and 1 deletions
				
			
		| 
						 | 
					@ -1,11 +1,12 @@
 | 
				
			||||||
proc decode(data: string, unique: int): int =
 | 
					proc decode(data: string, unique: int): int =
 | 
				
			||||||
  for i in 0..data.high:
 | 
					  for i in 0..data.len - unique:
 | 
				
			||||||
    block inner:
 | 
					    block inner:
 | 
				
			||||||
      let chars = data[i..i + unique - 1]
 | 
					      let chars = data[i..i + unique - 1]
 | 
				
			||||||
      for j in 0..unique - 2:
 | 
					      for j in 0..unique - 2:
 | 
				
			||||||
        if chars[j] in chars[j+1..^1]:
 | 
					        if chars[j] in chars[j+1..^1]:
 | 
				
			||||||
          break inner
 | 
					          break inner
 | 
				
			||||||
      return i + unique
 | 
					      return i + unique
 | 
				
			||||||
 | 
					  return -1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let data = stdin.readAll()
 | 
					let data = stdin.readAll()
 | 
				
			||||||
echo decode(data, 4)
 | 
					echo decode(data, 4)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue