Re: Program to output a subset of the composite numbers

2018-08-17 Thread Mark Lawrence

On 15/08/18 21:25, tomusa...@gmail.com wrote:

Yes, I will try it! Thank you kindly.



Please provide some context when you reply.  This is the fourth message 
that you've sent but there's no immediate clue to whom you are 
answering.  TIA :-)


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Program to output a subset of the composite numbers

2018-08-16 Thread tomusatov
Yes, I will try it! Thank you kindly.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Program to output a subset of the composite numbers

2018-08-16 Thread tomusatov
I'm sorry I did not correctly state the subset I was after:

"Composite numbers that are one less than twice a composite."

The output would begin:

DATA
15, 27, 35, 39, 49, 50, 51, 55, 63, 65, 69, 75, 77, 87, 91, 95, 99, 111, 115, 
119, 123, 125, 129, 135, 143, 147, 153, 155, 159, 161, 169, 171, 175, 183, 185, 
187, 189, 195, 203, 207, 209, 215, 219, 221
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Program to output a subset of the composite numbers

2018-08-16 Thread tomusatov
Thanks, I think that is an interesting tactic. From there what might the 
language look like to filter out the composites that are not one less than 
twice another composite number?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Program to output a subset of the composite numbers

2018-08-16 Thread tomusatov
DATA 
15, 27, 35, 39, 49, 50, 51, 55, 63, 65, 69, 75, 77, 87, 91, 95, 99, 111, 115, 
119, 123, 125, 129, 135, 143, 147, 153, 155, 159, 161, 169, 171, 175, 183, 185, 
187, 189, 195, 203, 207, 209, 215, 219, 221 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Program to output a subset of the composite numbers

2018-08-15 Thread Peter Otten
tomusa...@gmail.com wrote:

> Thank you very much! Do you also know how I might slightly alter to
> composite numbers that are one less than twice a composite number?
> 
> 15 would be the first number
> Since 8 is composite then
> 
> 2*8=16
> 16 - 1=15 Is composite

Like

>>> def is_composite(n):
... return not is_prime(n)
... 
>>> print(list(islice((i for i in count(3, step=2) if is_composite(i) and 
is_composite((i+1)//2)), 20)))
[15, 27, 35, 39, 49, 51, 55, 63, 65, 69, 75, 77, 87, 91, 95, 99, 111, 115, 
119, 123]

?

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Program to output a subset of the composite numbers

2018-08-15 Thread tomusatov
Thank you very much! Do you also know how I might slightly alter to composite 
numbers that are one less than twice a composite number?

15 would be the first number
Since 8 is composite then

2*8=16
16 - 1=15 Is composite 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Program to output a subset of the composite numbers

2018-08-15 Thread Peter Otten
Steven D'Aprano wrote:

> On Wed, 15 Aug 2018 05:34:06 -0700, tomusatov wrote:
> 
>> I am not terribly familiar with Python, but am currently authoring an
>> integer sequence for www.oeis.org and was wondering if anyone in the
>> community could help me with authoring a Python program that outputs,
>> "Composite numbers that are one less than a composite number."
> 
> 
> Do you have a function to test for primality? For now, I'll assume you do.
> 
> 
> def is_prime(n):
> # Returns True if n is prime, False otherwise.
> # implementation left as an exercise
> 
> 
> # 0 (and 1) are neither prime nor composite; skip them.
> # 2 and 3 are prime; start at the first composite, 4
> i = 4
> for j in range(5, 1001):
> if not is_prime(j):
> print(i)
> i = j

I think that are "any numbers that are one less than a composite number" 
while the OP wants only composite numbers that are one less than a composite 
number". In code

from itertools import count, islice

def cntaoltacn():
prev = None
for i in count(2):
if is_prime(i):
prev = None
else:
if prev is not None:
yield prev
prev = i

print(list(islice(cntaoltacn(), 20)))
# [8, 9, 14, 15, 20, 21, 24, 25, 26, 27, 32, 33, 34, 35, 38, 39, 44, 45, 48, 
49]


> 
> 
> The above will stop at 999. To go forever, use this instead:
> 
> 
> 
> from itertools import count
> i = 4
> for j in count(5):
> if not is_prime(j):
> print(i)
> i = j
> 
> 
> 
> Alternatively, if you have a function which efficiently returns primes
> one at a time, you can do this:
> 
> 
> n = 4  # start at the first composite
> for p in primes(5):  # primes starting at 5
> print(list(range(n, p-1))
> n = p + 1
> 
> 
> 
> This ought to print out lists of composites, starting with:
> 
> []
> []
> [8, 9]
> []
> [14, 15]
> 
> 
> etc. Take care though: I have not tested this code.
> 
> 
> 


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Program to output a subset of the composite numbers

2018-08-15 Thread Steven D'Aprano
On Wed, 15 Aug 2018 05:34:06 -0700, tomusatov wrote:

> I am not terribly familiar with Python, but am currently authoring an
> integer sequence for www.oeis.org and was wondering if anyone in the
> community could help me with authoring a Python program that outputs,
> "Composite numbers that are one less than a composite number."


Do you have a function to test for primality? For now, I'll assume you do.


def is_prime(n):
# Returns True if n is prime, False otherwise.
# implementation left as an exercise


# 0 (and 1) are neither prime nor composite; skip them.
# 2 and 3 are prime; start at the first composite, 4
i = 4
for j in range(5, 1001):
if not is_prime(j):
print(i)
i = j


The above will stop at 999. To go forever, use this instead:



from itertools import count
i = 4
for j in count(5):
if not is_prime(j):
print(i)
i = j



Alternatively, if you have a function which efficiently returns primes 
one at a time, you can do this:


n = 4  # start at the first composite
for p in primes(5):  # primes starting at 5
print(list(range(n, p-1))
n = p + 1



This ought to print out lists of composites, starting with:

[]
[]
[8, 9]
[]
[14, 15]


etc. Take care though: I have not tested this code.



-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Program to output a subset of the composite numbers

2018-08-15 Thread Joel Goldstick
On Wed, Aug 15, 2018 at 8:36 AM  wrote:
>
> I am not terribly familiar with Python, but am currently authoring an integer 
> sequence for www.oeis.org and was wondering if anyone in the community could 
> help me with authoring a Python program that outputs, "Composite numbers that 
> are one less than a composite number."
>
> Thanks!
> Musatov
> --
> https://mail.python.org/mailman/listinfo/python-list

Since composite numbers are all the positive integers that are not
prime and not one, I believe you can find code to produce a sequence
of prime numbers, and you can subtract that sequence from the sequence
of positive integers

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Program to output a subset of the composite numbers

2018-08-15 Thread tomusatov
I am not terribly familiar with Python, but am currently authoring an integer 
sequence for www.oeis.org and was wondering if anyone in the community could 
help me with authoring a Python program that outputs, "Composite numbers that 
are one less than a composite number."

Thanks!
Musatov
-- 
https://mail.python.org/mailman/listinfo/python-list