

A new house number ... - RiderOfGiraffes
http://thelastdanishpastry.deviantart.com/art/We-moved-into-a-new-house-138857094

======
antirez
I had to write the following to understand this is going to converge to 6:

    
    
        >> 1/((1..1000000).map{|n| (1/((n*3.14)**2))}.inject{|a,b| a+b})
        => 5.99392169730553

~~~
RiderOfGiraffes

        >>> from math import pi
        >>> 1/sum( [1/(pi*n)**2 for n in xrange(1,1000)] )
        6.00365160802217

~~~
antirez
Shorter but, "ad hoc" like everything in Python (the reason I never liked it).
The Ruby version looks like math, if you know the concepts of map and reduce
it's trivial to understand what's going on.

Compare this with sum() + "for n" and "xrange". Also if I remember some Python
correctly "xrange" is almost like "range" but it's something like a lazy
version, another ad-hoc stuff.

Sorry, didn't resisted.

~~~
RiderOfGiraffes
Each to his/her own. This isn't intended to be a language war. If you prefer
map and reduce then you can have them:

    
    
      >>> from math import pi
      >>> add = float.__add__
      >>> def f(x): return (pi*x)**(-2)
      >>> 1/reduce(add, map(f,range(1,1000)) )
      6.0036796863530508
    

Or, as a one-liner:

    
    
      >>> 1/reduce(float.__add__, map(lambda x:1.0/(3.1416*x)**2,range(1,1000)) )
    

People who aren't mathmos often find the list comprehensions more
comprehensible, hence the version I wrote not as a competitor, but as an
alternative, to yours.

Horses for courses. Personally, I've found the Python version to look more
like math when I choose to express it like math, but I'm programming, so why
not make it look like what I'm doing? Golf is a stupid game in programming.
Understandability is the goal, but different readers find different things
natural.

That's never going to go away.

~~~
antirez
I guess it's really a matter of tastes indeed. My point is that, no matter the
fact that I can try to mimic the Python idiomatic way or the reverse, there is
a real difference between this languages, and is a difference that I see in
many other languages, splitting them into two families: the "tools" languages
that try to provide already build abstractions able to solve common problems,
and the "concepts" languages where there are just a few rules you can combine
to solve problems. I love the latter approach.

------
Edinburger
I'm glad I am not your mailman.

~~~
RiderOfGiraffes
It's not me - I live at <http://www.penzba.co.uk/my_house_number.png>

~~~
robertk
You need parentheses around the -1. Otherwise the series is divergent. I
presume you do not live at a divergent address? :)

~~~
RiderOfGiraffes
That depends on which school you went to, but point taken. I've inserted the
parentheses.

------
jgrahamc
Feels annoying to me that the pi^2 is left inside the infinite sum at the
bottom:

<http://equationater.com/3887e31ec88fbf35d331554e06353358.png>

~~~
RiderOfGiraffes
I think the reasoning there is that sum(1/(n^2)) is rather well-known to be
pi^2/6. They then need to invert and remove the pi^2.

I think it's a reasonable part of the game to put the pi on the inside.

~~~
bonsaitree
It's just intentional obfuscation. Just like the double inversion.

~~~
RiderOfGiraffes
I'm not sure what you mean by the double inversion. You inverting a sum of
invertions - that can't be undone in any sensible way. Can you explain a
little more what you mean?

------
ynniv
Hey, a use for Wolfram Alpha! [
[http://www.wolframalpha.com/input/?i=sum%281%2F%28n+*+pi%29%...](http://www.wolframalpha.com/input/?i=sum%281%2F%28n+*+pi%29%5E2%2C+n%3D1%2C+inf%29)
]

~~~
aeroevan
This works for me:
[http://www.wolframalpha.com/input/?i=%28sum+1%2F+%28n+*+pi%2...](http://www.wolframalpha.com/input/?i=%28sum+1%2F+%28n+*+pi%29+^2+from+n+%3D+1+to+inf)

------
abalashov
Congratulations, now I'll never find your address if you invite me over. Last
math I took was "advanced" algebra & trigonometry my junior year of high
school.

~~~
modoc
It works as a visitor filtering mechanism. "You must be at least _this_ good
at maths..."

