urbanij / infinite-resistor-grid

xkcd nerd sniping

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Infinite grid of resistors problem (xkcd.com/356/)

How to:

Install a CLI SPICE simulator such as ngspice or MacSpice (which also happens to run twice as fast):

brew install ngspice

or

brew install --cask macspice

then compile this Rust script that parses spice outputs

rustc parse_ngspice_output.rs

then run this python script (~40 seconds with the current configuration) to get some results and generate the plots.

python run.py

If everything was a success you should have some .svg plots in your current directory.

If you want to get straight to a single figure you can just run this instead, passing a moderately big even number like 200

python infinite_grid.py 200 | ngspice

or

ln -s /Applications/MacSpice.app/Contents/MacOS/MacSpice /usr/local/bin
python infinite_grid.py 200 | MacSpice

which, after processing a netlist of 79999 resistors, gives a i(v1) = -1.29315e+00 output, meaning an equivalent resistance of 0.77330549433 Ω.


btw the mathematical result gives 4/π - 1/2.

About

xkcd nerd sniping


Languages

Language:Python 86.8%Language:Rust 11.4%Language:Shell 1.8%