News for hackers. Stuff that matters.
Re:A new house number ... by antirez on Friday October 02, 2009 @07:22AM (#856782)
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
Re:A new house number ... by RiderOfGiraffes on Friday October 02, 2009 @08:08AM (#856831)

    >>> from math import pi
    >>> 1/sum( [1/(pi*n)**2 for n in xrange(1,1000)] )
    6.00365160802217
Re:A new house number ... by jrockway on Friday October 02, 2009 @11:42AM (#857270)

    Prelude> 1/sum ([1..1000] >>= \x -> [(pi*x)**(-2)])
    6.003647956020607
Re:A new house number ... by apgwoz on Friday October 02, 2009 @08:21AM (#856848)
let's not get all fizzbuzz-y in here...
Re:A new house number ... by antirez on Friday October 02, 2009 @08:23AM (#856852)
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.

Re:A new house number ... by RiderOfGiraffes on Friday October 02, 2009 @08:36AM (#856877)
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.

Re:A new house number ... by antirez on Friday October 02, 2009 @09:14AM (#856930)
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.
Re:A new house number ... by andrewparker on Friday October 02, 2009 @08:43AM (#856887)
Sorry if this is obvious, dusting off the math mind here... How is this solved without brute force computation?
Re:A new house number ... by RiderOfGiraffes on Friday October 02, 2009 @08:51AM (#856897)
It's neither obvious nor easy. It was an outstanding problem in the mid 1700's, and it was Euler that solved it but some superbly reckless arguments.

Euler's original paper:

http://www.17centurymaths.com/contents/euler/e041tr.pdf

The bottom of this page has a more modern treatment, although it takes a lot for granted:

http://www.math.wpi.edu/IQP/BVCalcHist/calc3.html

Another treatment of Euler's proof is here:

http://library.thinkquest.org/28049/Summing%20reciprocals.ht...

Re:A new house number ... by stilist on Friday October 02, 2009 @09:06AM (#856918)
Last link needs to swap %20 for the space.
Re:A new house number ... by RiderOfGiraffes on Friday October 02, 2009 @09:10AM (#856923)
Done - thanks.
Re:A new house number ... by Edinburger on Friday October 02, 2009 @07:55AM (#856816)
I'm glad I am not your mailman.
Re:A new house number ... by RiderOfGiraffes on Friday October 02, 2009 @08:57AM (#856904)
Re:A new house number ... by robertk on Friday October 02, 2009 @12:13PM (#857335)
You need parentheses around the -1. Otherwise the series is divergent. I presume you do not live at a divergent address? :)
Re:A new house number ... by RiderOfGiraffes on Saturday October 03, 2009 @01:27PM (#858944)
That depends on which school you went to, but point taken. I've inserted the parentheses.
Re:A new house number ... by jacquesm on Friday October 02, 2009 @09:59AM (#857012)
Humor for mathematicians. I really should come to attend one of your talks. Need 48 hour days. And a calculus course.
Re:A new house number ... by bhousel on Friday October 02, 2009 @09:53AM (#857005)
Or the local EMS, Fire, Police, etc..

Seriously, I'd get that changed. There are plenty of reasons someone might want to find your house quickly.

Re:A new house number ... by anamax on Friday October 02, 2009 @11:50AM (#857290)
People often need to solve the problem of finding a house where the number is readily apparent.

In some/many places, one could find that house by interpolation. (In the US, even numbers tend to be on one side of the street and odd numbers on the other. And they're almost always in-order.) With an apartment, things can be more complicated.

That said, there are instances of "vanity addresses", where "<some number> 5th Ave" appears to not be on 5th Ave.

I don't know what one does in Japan, where the numbers are supposedly assigned chronologically. (Hmm - I wonder what triggers number generation and if they ever reuse or allow transfers.)

Re:A new house number ... by jgrahamc on Friday October 02, 2009 @07:03AM (#856753)
Feels annoying to me that the pi^2 is left inside the infinite sum at the bottom:

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

Re:A new house number ... by RiderOfGiraffes on Friday October 02, 2009 @07:48AM (#856807)
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.

Re:A new house number ... by bonsaitree on Friday October 02, 2009 @08:58AM (#856905)
It's just intentional obfuscation. Just like the double inversion.
Re:A new house number ... by RiderOfGiraffes on Friday October 02, 2009 @09:03AM (#856913)
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?
Re:A new house number ... by ynniv on Friday October 02, 2009 @11:46AM (#857281)
Re:A new house number ... by aeroevan on Friday October 02, 2009 @01:01PM (#857447)
Re:A new house number ... by abalashov on Friday October 02, 2009 @07:42AM (#856799)
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.
Re:A new house number ... by modoc on Friday October 02, 2009 @09:34AM (#856968)
It works as a visitor filtering mechanism. "You must be at least this good at maths..."