Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Now try BQN (Advent of Code 2020 Problem 2):

    Split ←((⊢-˜+`׬)∘=⊔⊢)                                               
     input2←' 'Split¨•file.Lines "../2020/2.txt"  # change string to your file location
    
    Day2←{                                                               
       f←⊑{(⊑)+↕1+|-´}‿{-1}  # Select the [I]ndex generator [F]unction
       I←{F •BQN¨  '-' Split ⊑}  # [I]ndices used to determine if the     
       C←{⊑1⊑}                   # [C]haracter appears in the             
       P←{⊑⌽}                    # [P]assword either                      
       Part1←(I∊˜·+´C=  P)¨        # a given number of times                
       Part2←(1= ·+´C=I⊏P)¨        # or at one of a pair of indices         
       ⊑+´◶Part1‿Part2                                                        
    }
    
    •Show { Day2 input2}¨↕2





Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: