~cdv/aoc-2019-rs

aoc-2019-rs/run -rwxr-xr-x 705 bytes
c11aef2aChris Vittal Day 24: Use cycle finding for part 1 1 year, 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
import argparse
import os
import sys
from datetime import datetime

import pytz

TZ = pytz.timezone('America/New_York')
TIME = datetime.now(tz=TZ)
BIN = 'cargo'


def main():
    """Main"""
    parser = argparse.ArgumentParser()
    parser.add_argument('day', nargs='?')

    args = parser.parse_args()
    day = int(args.day) if args.day is not None else TIME.day
    if day > 25 or day < 1:
        raise ValueError("day = {day}, must be between 1 and 25")

    args = [BIN, 'run', '--release', '--bin', f'day{day:02d}']
    fd = os.open(f'input/day_{day:02d}.txt', os.O_RDONLY)
    os.dup2(fd, 0)
    os.close(fd)
    os.execvp(BIN, args)


if __name__ == "__main__":
    main()