reset password
Author Message
lren2
Posts: 5
Posted 12:49 Feb 01, 2019 |

My dilemma is: the instructions say that you want it to generate all the numbers but only take the first two. Python cannot hold a list theoretically like Haskel (For example, list = [x: x>4]). So for the Python version, do you just want an infinite printing of Goldbach's other conjuncture numbers  ?  Or can I get by and just print a few of the first Goldbach's other conjuncture numbers?

 

Any help is appreciated. 

mkuko
Posts: 13
Posted 13:05 Feb 01, 2019 |

From my understanding python can work in a lazy manner similar to Haskell.

I haven't completed it myself but this stackoverflow answer seems helpful in figuring it out.

https://stackoverflow.com/questions/23305439/get-list-of-subset-from-infinite-generator-in-python 

Method 4 is similar to what the assignment suggests with using itertools takewhile.

Last edited by mkuko at 13:06 Feb 01, 2019.
asalin14
Posts: 12
Posted 13:09 Feb 01, 2019 |

I took advantage of yield in Python. For every counter example found, I yielded that value. The yield function’s generator can act like an infinite list.

I also created a custom take function that takes in a generator) and the number of elements to yield.

I am assuming this solution is fine but would like Dr. Abbott to confirm that this method is acceptable.

jpatel77
Posts: 44
Posted 16:37 Feb 01, 2019 |

Python does provide a way to represent Haskell’s “list = [ x : x>4]”. You just type count(4) and this will give you an iterator that gives sequential digits till infinity. This was mentioned by Dr Abbott as well in the class. Here’s is doc for that https://docs.python.org/2/library/itertools.html#itertools.count 

Edit: Looking at your question again, I believe I misunderstood it. @ASALIN14’s answer makes sense though.

Last edited by jpatel77 at 16:41 Feb 01, 2019.
rabbott
Posts: 1649
Posted 18:08 Feb 01, 2019 |

I agree with all the preceding answers.

Good question and good answers.

Well done. 

Last edited by rabbott at 18:10 Feb 01, 2019.