Created
          August 9, 2023 12:12 
        
      - 
      
- 
        Save kolemannix/10ba68b519ff787800c466fcd3cb8528 to your computer and use it in GitHub Desktop. 
    aoc_day6_fast
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def day6fast(chars: Iterator[Char], targetNum: Int): Option[Int] = { | |
| val buffer = scala.collection.mutable.ListBuffer.empty[Char] | |
| try { | |
| var i = 0 | |
| while (true) { | |
| val c = chars.next() | |
| if (buffer.length == targetNum) { | |
| buffer.dropInPlace(1) | |
| } | |
| buffer.append(c) | |
| if (buffer.distinct.size == targetNum) return Some(i + 1) | |
| i += 1 | |
| } | |
| None | |
| } catch { | |
| case _ => None | |
| } | |
| } | |
| day6fast("mjqjpqmgbljsphdztnvjfqwrcgsmlb".iterator, 14) | |
| day6fast("bvwbjplbgvbhsrlpgdmjqwftvncz".iterator, 14) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment