infinite-sequence

Linq statement for an infinite sequence of successive halves

こ雲淡風輕ζ 提交于 2020-01-23 05:47:05
问题 Given a starting number, imagine an infinite sequence of its successive halves. 1, 0.5, 0.25, 0.125, ... (Ignore any numerical instabilities inherent in double .) Can this be done in a single expression without writing any custom extension methods or generator methods? 回答1: I don't know of a single-expression way but I found this clever generator code here: http://csharpindepth.com/articles/Chapter11/StreamingAndIterators.aspx public static IEnumerable<TSource> Generate<TSource>(TSource start

What are some useful or interesting infinite generators? [closed]

烂漫一生 提交于 2020-01-17 06:54:37
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . What are some clever uses for infinite generators? I've seen lots of seemingly trivial examples like "list all even numbers" , but I assume there must be others that have more applicability to real-world scenarios. Concrete examples (in any language that support generators)

What are some useful or interesting infinite generators? [closed]

陌路散爱 提交于 2020-01-17 06:54:12
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . What are some clever uses for infinite generators? I've seen lots of seemingly trivial examples like "list all even numbers" , but I assume there must be others that have more applicability to real-world scenarios. Concrete examples (in any language that support generators)

WPF ListBox generate items as user scrolls

与世无争的帅哥 提交于 2019-12-10 19:06:15
问题 I am trying to use a ListBox to display a possibly infinite list of options to a user. Currently, I am simply cutting off the list at an arbitrary point, but I would like to allow the user to scroll down as far as they want. Also, I want to avoid generating non-visible items as much as possible as some computation has to be done to generate each item. I tried writing listBox.ItemsSource = enumerable expecting it to only ask the enumerable for visible items, but instead it tries to read all of

Detecting repetition with infinite input

让人想犯罪 __ 提交于 2019-12-08 06:40:44
问题 What is the most optimal way to find repetition in a infinite sequence of integers? i.e. if in the infinite sequence the number '5' appears twice then we will return 'false' the first time and 'true' the second time. In the end what we need is a function that returns 'true' if the integer appeared before and 'false' if the function received the integer the first time. If there are two solutions, one is space-wise and the second is time-wise, then mention both. I will write my solution in the

Iterate over an infinite sequence in Ruby

◇◆丶佛笑我妖孽 提交于 2019-12-06 20:59:55
问题 I am trying to solve Project Euler problem #12: The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Let us list the factors of the first seven triangle numbers: 1: 1 3: 1,3 6: 1,2,3,6 10: 1,2,5,10 15: 1,3,5,15 21: 1,3,7,21 28: 1,2,4,7,14,28 We can see that 28 is the first triangle number to have over five divisors. What is the

Linq statement for an infinite sequence of successive halves

陌路散爱 提交于 2019-12-05 04:53:49
Given a starting number, imagine an infinite sequence of its successive halves. 1, 0.5, 0.25, 0.125, ... (Ignore any numerical instabilities inherent in double .) Can this be done in a single expression without writing any custom extension methods or generator methods? I don't know of a single-expression way but I found this clever generator code here: http://csharpindepth.com/articles/Chapter11/StreamingAndIterators.aspx public static IEnumerable<TSource> Generate<TSource>(TSource start, Func<TSource,TSource> step) { TSource current = start; while (true) { yield return current; current = step

Iterate over an infinite sequence in Ruby

天涯浪子 提交于 2019-12-05 02:03:37
I am trying to solve Project Euler problem #12: The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Let us list the factors of the first seven triangle numbers: 1: 1 3: 1,3 6: 1,2,3,6 10: 1,2,5,10 15: 1,3,5,15 21: 1,3,7,21 28: 1,2,4,7,14,28 We can see that 28 is the first triangle number to have over five divisors. What is the value of the first triangle number to have over five hundred divisors? Here's the solution that I came up