Jump to content

Talk:Sequence of non-squares: Difference between revisions

no edit summary
No edit summary
Line 38:
:IEEE754 guarantees almost 7 decimal digits (6.9something iirc) for normal 32-bit floats and the last computer architecture I've ever heard of that used non-IEEE754 floats was the DEC VAX. Certainly anything x87-based should abide by that. Since log(2) is about 0.3, this means square roots should be stable and OK for this task up to about 10^6.6 or there abouts. Since we're only supposed to test a million numbers, I see no problem here anywhere (if someone feels like testing it, it should break down a little over 4 million for 32-bit floats, a little over 2e15 for 64-bit floats). Or am I missing something here somewhere?
[[User:Sgeier|Sgeier]] 21:02, 28 September 2009 (UTC)
 
See GAP implementation for a way to use integers all the way. Of course, it will be best suited to languages with bigints, like python or ocaml, but others will do as long as you don't go past MAXINT/100. You also need to implement integer square root if it's not available in your language (not too difficult). The main idea is Sqrt(100*n) = 10*Sqrt(n) (let's call it x), so you get the first decimal of Sqrt(n) as x mod 10.
[[User:Toucan|Toucan]] 08:27, 15 June 2011 (UTC)
 
== Zero ==
Line 63 ⟶ 66:
 
In some programming languages round may give different results. E. g. in Scheme: "Round returns the closest integer to x, ''rounding to even when x is halfway between two integers''. Rationale: Round rounds to even for consistency with the default rounding mode specified by the IEEE floating point standard." But since we are only rounding the square roots of integers, in this case we would not run into problems like these. Maybe it's because [http://en.wikipedia.org/wiki/Floor_function floor] has been well-defined in mathematics and [http://en.wikipedia.org/wiki/Rounding round] hasn't. [[Special:Contributions/131.155.116.18|131.155.116.18]] 17:09, 30 November 2009 (UTC)
 
 
== Ambiguity ==
The task only asks to check that there are no squares in the sequence, but then we don't check that there are all non-squares ! However, it's easy to keep track of "the next square to come", and check that we go through all integers up to that number, then compute the next square, etc. Easiest with a generator, but a loop will do.
[[User:Toucan|Toucan]] 08:27, 15 June 2011 (UTC)
506

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.