day0

Day 0: Short Title

The elves want something.

The input is …

Alert

Hey! Set the name below!


Example:

Here is the starting position:

example = """
paste here
ok
""".strip()
exfile = f"data/{NAME}_example.txt"
with open(exfile, "w") as f:
    f.write(example.strip())

with open(exfile) as f:
    example = f.readlines()

print(example)
['paste here\n', 'ok']

Describe example…

Define f & g

Code
def f():
    pass

def g():
    pass

source

g

 g ()

source

f

 f ()
Code
def f(x: int,   # An x
               y: int,   # A y
              )-> str:   # An xy
    """Find the ...."""
    return "f"

def g(x: int) -> None:
    """Find the ...."""
    pass

source

g

 g (x:int)

Find the ….


source

f

 f (x:int, y:int)

Find the ….

Type Details
x int An x
y int A y
Returns str An xy
f(3,4)
g(2)

Say some more

Code
# Probably more defs here.
_ = "A simple example"

assert True    # Make a test

Define h

assert True

Thoughts…

Note…

Code
def h() -> str:
    return "What, another stub?"

source

h

 h ()
Note

It took \(x\) minutes to get here. Or now we… Or … something.

h()
'What, another stub?'

Solve Example

Test Case 1

Should be

test1 = """
Paste a test case here
"""
h()
'What, another stub?'

Test Case 2

test2 = """
Another
"""
h()
h()
'What, another stub?'

Final Test

E.g.: Answer would be CMZ.

Code
def get_answer(x: int,   # An x
               y: int,   # A y
              )-> str:   # An xy
    """Find the ...."""
    return "CMZ"

source

get_answer

 get_answer (x:int, y:int)

Find the ….

Type Details
x int An x
y int A y
Returns str An xy

Test that

assert get_answer(3,1) == "CMZ"

Part 1

Get the data

input_name = f"data/{NAME}_input.txt"
with open(f"data/{NAME}_input.txt") as f:
    data = [x.strip() for x in f.readlines()]
data[:3]
FileNotFoundError: [Errno 2] No such file or directory: 'data/day0_input.txt'

Run

g(data)

Part 2

Note

Something chnaged! Part 2 is different!

Do the thing…

But first do a sanity check on your idea…

# Ensure we can baz the foo.
stack1 = [3,4,5,6]
stack2 = [1]
for x in reversed([stack1.pop() for i in range(3)]):
    stack2.append(x)
stack2

Okay, implement that.

Code
def baz_the_foo(
    n:   int|str,  # Move this many
    old: list,     # From this stack
    new: list,     # To this stack
    )-> None:      # MODIFIES the stacks!
    """Move `n` things from `from_col` to `to_col` AS A GROUP."""
    for x in reversed([old.pop() for i in range(int(n))]):
        new.append(x)

source

baz_the_foo

 baz_the_foo (n:int|str, old:list, new:list)

Move n things from from_col to to_col AS A GROUP.

Type Details
n int | str Move this many
old list From this stack
new list To this stack
Returns None MODIFIES the stacks!

Run

old = [3,4,5,6,7,8,9,10]
new = [1,2]
baz_the_foo(3, old, new)
print(old, new)

Footer: nbdev magic