- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1
Prepare for 2024 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
        
      
    
  
     Merged
                    Changes from 1 commit
      Commits
    
    
            Show all changes
          
          
            5 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
              Empty file.
          
    
              Empty file.
          
    
  
    
      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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import datetime | ||
|  | ||
| import click | ||
|  | ||
| from . import days | ||
|  | ||
|  | ||
| @click.command() | ||
| @click.option( | ||
| "-i", | ||
| "--input", | ||
| "data", | ||
| type=click.File(mode="rt", encoding="utf8"), | ||
| default="-", | ||
| help="Problem input file", | ||
| ) | ||
| @click.option("-t", "--time", is_flag=True, help="Print elapsed time afterwards") | ||
| @click.argument("day", required=True) | ||
| def main(day: int, time: bool, data: str) -> None: | ||
| runner_class = days.get_runner(day) | ||
|  | ||
| start = datetime.datetime.now() | ||
|  | ||
| part1, part2 = runner_class.run_both(data) | ||
|  | ||
| if time: | ||
| click.echo(f"Elapsed: {datetime.datetime.now() - start}", err=True) | ||
|  | ||
| click.echo(part1) | ||
| click.echo(part2) | ||
|  | ||
|  | ||
| if __name__ == "__main__": | ||
| main() | ||
  
    
      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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import importlib | ||
| from abc import ABC, abstractmethod | ||
| from typing import Any, Tuple, cast | ||
|         
                  bertptrs marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
|  | ||
|  | ||
| class Runner(ABC): | ||
| @classmethod | ||
| @abstractmethod | ||
| def run_both(cls, data: str) -> Tuple[Any, Any]: | ||
| pass | ||
|  | ||
| @classmethod | ||
| @abstractmethod | ||
| def part1(cls, data: str) -> Any: | ||
| pass | ||
|  | ||
| @classmethod | ||
| @abstractmethod | ||
| def part2(cls, data: str) -> Any: | ||
| pass | ||
|  | ||
|  | ||
| class SeparateRunner(Runner): | ||
| @classmethod | ||
| def run_both(cls, data: str) -> Tuple[Any, Any]: | ||
| return (cls.part1(data), cls.part2(data)) | ||
|  | ||
|  | ||
| class CombinedRunner(Runner): | ||
| @classmethod | ||
| def part1(cls, data: str) -> Any: | ||
| return cls.run_both(data)[0] | ||
|  | ||
| @classmethod | ||
| def part2(cls, data: str) -> Any: | ||
| return cls.run_both(data)[1] | ||
|  | ||
|  | ||
| def get_runner(day: int) -> type[Runner]: | ||
| runner_module = importlib.import_module(f".day{day}", package=__name__) | ||
|  | ||
| assert issubclass(runner_module.DayRunner, Runner) | ||
|  | ||
| return cast(type[Runner], runner_module.DayRunner) | ||
  
    
      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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from typing import Any | ||
|  | ||
| from . import SeparateRunner | ||
|  | ||
|  | ||
| class DayRunner(SeparateRunner): | ||
| @classmethod | ||
| def part1(cls, _data: str) -> Any: | ||
| return "Hello" | ||
|  | ||
| @classmethod | ||
| def part2(cls, _data: str) -> Any: | ||
| return "world!" | 
  
    
      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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| [project] | ||
| name = "aoc-2024" | ||
| version = "0.1.0" | ||
| description = "Advent of Code 2024 solutions programs" | ||
| readme = "README.md" | ||
| requires-python = ">=3.12" | ||
| dependencies = [ | ||
| "click>=8.1.7", | ||
| "numpy>=2.1.2", | ||
| ] | ||
|  | ||
| [dependency-groups] | ||
| dev = [ | ||
| "mypy>=1.13.0", | ||
| "ruff>=0.7.3", | ||
| ] | ||
|  | ||
| [tool.ruff.lint] | ||
| select = ["F", "E", "I"] | ||
|  | ||
| [tool.mypy] | ||
| strict = true | 
Large diffs are not rendered by default.
      
      Oops, something went wrong.
      
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.