Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #58447
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Rosetta: Sequence of non-squares |
| Date | 2017-05-01 18:24 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <oe7ug7$1paj$1@gioia.aioe.org> (permalink) |
> Show that the following remarkable formula gives the sequence
> of non-square natural numbers:
>
> n + floor(1/2 + sqrt(n))
>
> Print out the values for n in the range 1 to 22.
>
> Show that no squares occur for n less than one million
nsq = Enumerator.new{|y|
n = 0
loop {n += 1 ; y.yield(n + Math.sqrt(n).round)}
}
nsq.take 22
===>
[2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23,
24, 26, 27]
def square? n
m = Math.sqrt(n)
m.floor == m
end
nsq.lazy.take(999_999).none?{|n| square? n}
===>
true
In Forth?
--
[E]verything that happens in the world is for the benefit of the Jewish
People.... G-D ... created the world for the sake of the Jewish People, and it
is our responsibility to implement the Torah---absolute morality and the
blueprint of creation---in it.
www.IsraelNationalNews.com/Articles/Article.aspx/2125#.UUnBZxx4xn8
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
Rosetta: Sequence of non-squares "Robert L." <No_spamming@noWhere_7073.org> - 2017-05-01 18:24 +0000
csiph-web