= """
example paste here
ok
""".strip()
day0
Day 0: Short Title
The elves want something.
The input is …
Example:
Here is the starting position:
= f"data/{NAME}_example.txt"
exfile with open(exfile, "w") as f:
f.write(example.strip())
with open(exfile) as f:
= f.readlines()
example
print(example)
['paste here\n', 'ok']
Describe example…
Define f & g
Code
def f():
pass
def g():
pass
g
g ()
f
f ()
Code
def f(x: int, # An x
int, # A y
y: -> str: # An xy
)"""Find the ...."""
return "f"
def g(x: int) -> None:
"""Find the ...."""
pass
g
g (x:int)
Find the ….
f
f (x:int, y:int)
Find the ….
Type | Details | |
---|---|---|
x | int | An x |
y | int | A y |
Returns | str | An xy |
3,4)
f(2) g(
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?"
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
int, # A y
y: -> str: # An xy
)"""Find the ...."""
return "CMZ"
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
= f"data/{NAME}_input.txt"
input_name with open(f"data/{NAME}_input.txt") as f:
= [x.strip() for x in f.readlines()]
data 3] data[:
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.
= [3,4,5,6]
stack1 = [1]
stack2 for x in reversed([stack1.pop() for i in range(3)]):
stack2.append(x) stack2
Okay, implement that.
Code
def baz_the_foo(
int|str, # Move this many
n: list, # From this stack
old: list, # To this stack
new: -> 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)
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
= [3,4,5,6,7,8,9,10]
old = [1,2]
new 3, old, new)
baz_the_foo(print(old, new)
Footer: nbdev magic