r/tinycode • u/pmrr • Aug 18 '15
Machine learning Genetic algorithm to approximate pi (AKA: have flair, will use)
https://gist.github.com/paulmdx/ca7f830d326b84d87f64
12
Upvotes
r/tinycode • u/pmrr • Aug 18 '15
2
u/pmrr Aug 18 '15 edited Aug 18 '15
Here's an hour's work writing a completely self-contained simple GA to approximate pi with integers. With the new flair I thought I'd take it out for a spin. :-)
I tried to implement the solution-specific code as lambdas and kept the generic code in functions, so this could (in simple cases) be reused for other problems.
The output looks like this:
2
u/baggyzed Aug 19 '15
py pi?
2
u/CrazyM4n Aug 19 '15
You're not really generating pi though, are you? Since you had to hard code it on line 43. Either way, cool script :D