turner-townsend-backend-ass.../README.md

1.9 KiB

Turner & Townsend backend assessment

These programs need Python 3.10+ and pytest.

Original assessment: https://github.com/turner-townsend/backend-assessment

The Collatz Conjecture

Takes numeric input and calculates the number of steps in the Collatz sequence needed to reach 1

Usage

python collatz/collatz.py

Example

Please enter a whole number: 1
Result: 0 steps needed to reach 1
Please enter a whole number: 3
Step #1: odd, multiply by 3 and add 1 -> 10
Step #2: even, divide by 2 -> 5
Step #3: odd, multiply by 3 and add 1 -> 16
Step #4: even, divide by 2 -> 8
Step #5: even, divide by 2 -> 4
Step #6: even, divide by 2 -> 2
Step #7: even, divide by 2 -> 1
Result: 8 steps needed to reach 3
Please enter a whole number: 0
Result: 0 steps needed to reach 0
Please enter a whole number: !£$
ERROR: integer required

Tests

pytest collatz

Roman Numerals

A simple Roman numerals number converter

Usage

python roman/roman.py

Example

Please enter some Roman numerals: I
I = 1
Please enter some Roman numerals: IV
IV = 1 + 5 = 6
Please enter some Roman numerals: MCMXCIV
MCMXCIV = 1000 + 100 + 1000 + 10 + 100 + 1 + 5 = 2216
Please enter some Roman numerals: !£$
ERROR: Invalid input

Tests

pytest roman

Fifth Stack

A simple stack-based language called Fifth

Usage

python stack/stack.py

Commands

  • PUSH <n> - push integer onto stack
  • POP - remove top element
  • SWAP - swap top two elements
  • DUP - duplicate top element
  • +, -, *, / - arithmetic operations
  • EXIT - quit

Example

stack is []
PUSH 3
stack is [3]
PUSH 11
stack is [3, 11]
+
stack is [14]
DUP
stack is [14, 14]
PUSH 2
stack is [14, 14, 2]
*
stack is [14, 28]
SWAP
stack is [28, 14]
/
stack is [2]
+
ERROR: two numbers required
POP
stack is []
EXIT

Tests

pytest stack