File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed 
src/main/scala/eu/sim642/adventofcode2024 Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -8,16 +8,21 @@ object Day25 {
88  def  isKey (grid : Grid [Boolean ]):  Boolean  = 
99    grid.head.forall(identity)
1010
11+   def  fits (key : Grid [Boolean ], lock : Grid [Boolean ]):  Boolean  = 
12+     key.correspondsGrid(lock)((k, l) =>  ! (k &&  l))
13+ 
1114  def  countLockKeyFits (lockKeys : Seq [Grid [Boolean ]]):  Int  =  {
1215    val  (keys, locks) =  lockKeys.partition(isKey)
1316    (for  {
1417      key <-  keys
1518      lock <-  locks
16-       if  key.correspondsGrid(lock)((k, l)  =>   ! (k  &&  l) )
19+       if  fits(key, lock )
1720    } yield  ()).size
1821  }
1922
20-   def  parseLockKeys (input : String ):  Seq [Grid [Boolean ]] =  input.split(" \n\n "  ).map(_.linesIterator.map(_.map(_ ==  '#' ).toVector).toVector).toSeq
23+   def  parseLockKey (s : String ):  Grid [Boolean ] =  s.linesIterator.map(_.map(_ ==  '#' ).toVector).toVector
24+ 
25+   def  parseLockKeys (input : String ):  Seq [Grid [Boolean ]] =  input.split(" \n\n "  ).map(parseLockKey).toSeq
2126
2227  lazy  val  input :  String  =  scala.io.Source .fromInputStream(getClass.getResourceAsStream(" day25.txt"  )).mkString.trim
2328
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments