Questions tagged [infinite-sequence]
24 questions
1
vote
5 answers
Detecting repetition with infinite input
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…

maayank
- 4,200
- 2
- 24
- 23
1
vote
3 answers
Haskell - Negating even numbers in infinite stream
I am trying to generate a list of infinite numbers
0,1,-2,3,-4,5,-6...
So far I got
evenise x | x == 0 = 0
| even x = -x
| otherwise = x
s = foldl (\x -> evenise x) 0 [1..]
However I am getting the error
Occurs check:…

ali
- 846
- 2
- 18
- 34
0
votes
1 answer
c++20 infinite ranges/views compiler error
So I watched a video (14:30) about the new c++ 20 features and wanted to try out infinite ranges.
I wrote this code:
#include
#include
#include
using std::cout;
using std::endl;
bool primeCheck(const int&);
int…

FalcoGer
- 2,278
- 1
- 12
- 34
0
votes
1 answer
infinite sequence in SML
I have to code a function that receives a sequence (finite or infinite) and returns an identical sequence with the only difference that if an exception occurs during the sequence then the function returns the sequence to its beginning.
In other…

Arie
- 23
- 5
0
votes
3 answers
What are some useful or interesting infinite generators?
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…

Justin Morgan
- 2,427
- 2
- 16
- 19
0
votes
3 answers
Print an infinite sequence using generator
I'm trying to create a generator that prints out a specified infinite sequence. Currently, I have the following code:
def numGen():
for i in range(1,13):
yield i
Which then gives me:
>>> y = numGen()
>>> y

BrxttB
- 103
- 1
- 9
0
votes
1 answer
multi-directional infinte sequence - ML
I want to use the datatype sequence that is defined as follows:
datatype 'a seq = Nil | Cons of 'a * (unit-> 'a seq);
exception EmptySeq;
fun head(Cons(x,_)) = x | head Nil = raise EmptySeq;
fun tail(Cons(_,xf)) = xf() | tail Nil = raise…

wannabe programmer
- 653
- 1
- 9
- 23
0
votes
3 answers
Doing Tic Tac Toe game with GUI interface on java, facing runtime error after including new method
So I am making a tic tac toe game with user friendly GUI interface. I have almost completed the game but there seems to be a problem with my checkWin function. Up to this point, everything was working just fine until I added the checkWin function…

user3290306
- 11
- 1
- 2
- 4
0
votes
1 answer
Searching strategy in an infinte list
I am listening to a 3rd party web-service, when the services starts it generates a stream of objects which I am receiving. I have to search for a specific object within given amount of time and do some processing if the object is found or throw an…

Ravi Gupta
- 4,468
- 12
- 54
- 85