- What are Computers?
- Computers vs Calculators
- Computers are programmable
- Computers can run new algorithms
- Transistors, Binary, Logic
- The fundamental things a computer can do is very limited, it just does it very quickly to make up for it.
- Analysing how we using our base-10 numbers, we can apply the same method to only two states. On-or-off, Yes-or-no, Electricity-or-no-electricity to represent arbitrarily large numbers.
- Lots of operations derive from very simple building blocks
- Other data (like text) can be sent as blocks of binary representing the parts that it is made of:
- Images: Pixels are blocks of colour values
- Text: Sequence of numbers we assigned to represent characters
- Computers vs Calculators
- What is an Algorithm?
- A finite sequence of steps
- Advent of Code 2023, Day 1, Part 1 Pair-programming
- (Optional) Set up VSCode on Izabela's machine for live-share
- (Optional) Using Izabela's puzzle input
We logged in with GitHub and solved Day 1 Part 1 together in Pair-programming. Markus doing the python, Izabela bringing the solution / algorithm ideas.
- Define goal: What should the algorithm do
- Get it to work on a single example
- Change the example to test if it still works
- Change it to run on the actual puzzle input
- See if the result is correct
- if not: start debugging!
we ended up with this code, and a correct result on the first try.
# Advent of Code, Day 1
## Algorithm
# 1. What should it do?
# 0. read all the input
# - figure out first and last number in a line
# - HOW?
# - put them together: "1" and "2" turns into "12"
# - "tre7buchet"[3] == "7"
# - HOW?
# - afterwards add them all together
# - HOW?
puzzleFile = open("Puzzle")
lines = puzzleFile.readlines()
totalOfNumbers = 0
lineNumber = 0
while (lineNumber < len(lines)):
text = lines[lineNumber]
lineNumber = lineNumber + 1
firstDigitWeFound = "not found"
lastDigitWeFound = "not found"
counter = 0
while (firstDigitWeFound == "not found"):
character = text[counter]
counter = counter + 1
if character.isdigit(): # if it looks like a number
firstDigitWeFound = character # it's the first one we found!
counter = len(text) - 1
while(counter >= 0 and lastDigitWeFound == "not found"):
character = text[counter]
counter = counter - 1
if character.isdigit():
lastDigitWeFound = character
found = f"{firstDigitWeFound}{lastDigitWeFound}"
foundNum = int(found) # "12" -> 12
print(f"in {text} we found {found}")
totalOfNumbers = totalOfNumbers + foundNum
print(f"our total so far is: {totalOfNumbers}")
print(f"the final total is: {totalOfNumbers}")- Izabela: Look at Day 1 Part 2 and how it differs from Day 1 Part 1. Why is it harder?
- Markus: Figure out how Izabela can stay active learning Python during XMAS break.