weemadarthur's recent activity

  1. Comment on Day 10: Adapter Array in ~comp

    weemadarthur
    Link
    Using functools.lru_cache almost feels like cheating (both parts finish in 300 ms). Part 2 ratings = set([int(r) for r in data.split('\n')]) max_rating = max(ratings) builtin_rating = max_rating +...

    Using functools.lru_cache almost feels like cheating (both parts finish in 300 ms).

    Part 2
        ratings = set([int(r) for r in data.split('\n')])
        max_rating = max(ratings)
        builtin_rating = max_rating + 3
    
        @functools.lru_cache
        def find_next_adapter(current):
            if current == max_rating:
                return 1
            count = 0
            for difference in (1, 2, 3):
                if (current + difference) in ratings:
                    count += find_next_adapter(current + difference)
            return count
    
        print(find_next_adapter(0))
    
    5 votes