Posts on Home
https://www.rowanajmarshall.co.uk/blog/
Recent content in Posts on HomeHugo -- gohugo.iorowanajmarshall@gmail.com (Rowan Marshall)rowanajmarshall@gmail.com (Rowan Marshall)Thu, 14 Feb 2019 18:37:53 +0000Modifying a compiled executable
https://www.rowanajmarshall.co.uk/blog/modifying-executable/
Thu, 14 Feb 2019 18:37:53 +0000rowanajmarshall@gmail.com (Rowan Marshall)https://www.rowanajmarshall.co.uk/blog/modifying-executable/Oh no!
Your boss, Harry, is leaving the company. He was a good guy and a good boss, who appreciated the simple things in life. One of those simple things was a little program called “who-the-boss” which, when run, printed out “Harry the boss!”.
His replacement is called Larry. Larry is a short-tempered man with little patience for anything he considers wrong, which is everything.
One day, he finds Harry’s program on a machine everyone forgot existed.Calling Nim from Python
https://www.rowanajmarshall.co.uk/blog/calling-nim-from-python/
Sun, 27 Jan 2019 15:42:01 +0000rowanajmarshall@gmail.com (Rowan Marshall)https://www.rowanajmarshall.co.uk/blog/calling-nim-from-python/In this post I’ll show you how to write a function in Nim and call it in Python.
Nim To start with we’ll need a Nim function. Here’s a one that takes 2 integers, adds them and returns the result:
called.nim
proc nim_add(num1: int, num2: int): int {.exportc.} = return num1 + num2 Most of this is pretty ordinary, except for the {.exportc.} in the function signature. This is a pragma, which provides metadata about a function to the Nim compiler.Automatic memoization of function calls in Python
https://www.rowanajmarshall.co.uk/blog/automatic-function-caching-python/
Sat, 20 Jan 2018 18:09:11 +0100rowanajmarshall@gmail.com (Rowan Marshall)https://www.rowanajmarshall.co.uk/blog/automatic-function-caching-python/The Fibonacci sequence is the integer sequence where each number is the sum of the previous two numbers, starting with zero and one:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34
Writing a function to calculate an arbitrary fibonacci number is a common problem in interviews and tests, that has an elegant if inefficient way of being solved via recursion.
Here’s a simple solution in Python:
def fib(n): if n < 2: return n else: return fib(n-1) + fib(n-2) Given an integer n, this function will calculate the n’th number in the fibonacci sequence.