Creator of DiceDB, ex-Google Dataproc, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses
In a rapidly developing city, house prices change over time based on their neighborhood’s influence. The city can be represented as an N×N grid, where each cell represents a property with a certain price.
The price evolution of each house is influenced by:
The price P(x, y, t) at position (x, y) at time t follows standard diffusion.
Given the following inputs,
Simulates the price evolution over 10 years and output
N = 50 # 50x50 grid
T = 5 # Simulate for 5 years
alpha = 0.2 # Diffusion coefficient
beta = 0.05 # Development factor
# Initial condition: central high-price district
P0 = np.zeros((N, N))
P0[20:30, 20:30] = 1000000 # Million-dollar properties in center
P0[0:10, 0:10] = 500000 # Another wealthy area
Here’s the code for reference and some notes on the solution below.
This simulation models how house prices spread and evolve across a city using principles similar to heat diffusion in physics. The key ideas are:
The code uses what’s called a reaction-diffusion equation:
dP/dt = α∇²P + βP
where:
initial city layout:
P0[20:30, 20:30] = 1000000 # A central expensive district
P0[0:10, 0:10] = 500000 # A secondary wealthy area
P0 += 200000 * X # Prices increase from left to right
This creates:
So, to see how the prices evolve over time, we divide time into small steps (dt = 0.01 years) and for each step:
Post computing everything we output the required stats and visualize the price distribution.
Arpit's Newsletter read by 125,000 engineers
Weekly essays on real-world system design, distributed systems, or a deep dive into some super-clever algorithm.