Finding an substring in an infinite sequence

I’m trying to find a substring in an infinite sequence of numbers (Similar to Substring in a infinite sequence of numbers) and am a little stuck on improving my algorithm. I know there is already an answer given in the question I linked above, but I want to try and improve my brute force algorithm.

Given a sequence $ S = \{12345678910…n-1n | S \in \mathbb{Z}:\}$ , the algorithm tries to compute the first index of a pattern $ P$ in the string. For instance, $ \mathrm{find}(P = 456) == 3$ as the sequence $ 456$ is located at index $ 3$ . I have a very simple algorithm that generates a sequence till the substring is found, and then goes through the sequence to return the index of the substring. This algorithm is very slow for for large $ N$ and I want to improve it:

def find_position(string):      # Build a window of size len(string) and init from 1 -> m     windowSize = len(string)     window = [str(i) for i in range(1, windowSize + 1)]     result = ''.join(window)      # Loop till match     while string not in result:          # Remove front and add back         window.append(str(int(window[-1]) + 1))          # Join window and match         result = ''.join(window)      return result.index(string) 

This algorithm is like a very basic Rabin-Karp without any hashing but just regular string matching. I am not too sure if adding a rolling hash would speed up this algorithm in any way because the slow aspect of the algorithm is generating and appending to the sequence and then checking if the string is contained in the window.

Any ideas on how to improve this algorithm?

Can we represent $\sqrt{2}$ exactly even with infinite bits in mantissa

Can we represent $ \sqrt{2}$ exactly even with infinite bits in mantissa in floating point notation or otherwise. We actually have to prove this is not possible. But why can’t we if we have infinite bits? Infinite bits means the binary representation of the mantissa can be indefinitely large. The mantissa is in IEEE 754 32 bit format and in a hypothetical world where we don’t have a bound on the number of bits which can be used to represent it.

Users want to create tables with many columns and infinite scrolling rows – how do we handle this?

I have a situation where users are capable of creating their own searches on extensive data sets, using a query-like user interface. Our users come from a strong Excel background and are used to working with dozens or more columns in those.

Our search system provides a full screen interface with infinite scrolling and fixed headers, as sometimes these searches can return millions of records. We tested limiting the number of columns on a search to 12, but users were vocal about their desire to have more.

We get asked to add horizontal scrolling, but this works poorly with the existing system of fixed headers and infinite scrolling, in addition to generally making for a poor user experience.

Because the users select the columns themselves and can write custom columns using mathematical functions or aggregates on previous columns, it is difficult to predict the final appearance or content of the searches and not likely possible to condense multiple columns into a single cell.

Are there any patterns or shortcuts to provide what the customer is asking for without compromising experience or functionality?

How do I prevent players from flying too low in an infinite sky?

Let’s say I have a game that allows the player completely free, open world flight, and the world itself is a bunch of floating islands. This creates some problems with flying too low, such as reaching the fake cloud “floor”, being stuck without being able to get back up, and so on. How can I prevent this without introducing some jarring invisible “floor” that repels the player if he slams into it?

I thought about having some sort of in-universe wind near the “bottom” that might decelerate the player and then push him/her back up, but I’d like to hear some more ideas that might be less artificial.

What is an example of a Turing-recognizable infinite word, which is not Turing-decidable?

I am confused about Turing Machines that are able to decide languages that contain infinite words.

  1. Are languages with an infinite amount of only finite strings always decidable?

  2. How can a Turing Machine halt on an infinite input string?

  3. Can Turing Machines loop on finite strings?

  4. What is the difference between an infinite input string that a Turing Machines can halt on and an infinite input string that a Turing Machine cannot halt on (decidable vs recognizable)?

It’s a lot of questions but they are related, please help me.

How to detect infinite loop exist in linear bounded automata (LBA)?

The following theorem from Michael Sipser’s book “Introduction to the Theory of Computation” states:

$ A_{\textrm{LBA}}= \{ \langle M, w \rangle \mid \text{$ M$ is an LBA that accepts string $ w$ } \}$ .

THEOREM: $ A_{\mathrm{LBA}}$ is decidable.

On the proof part, it states:

The idea for detecting when $ M$ is looping is that as $ M$ computes on $ w$ , it goes from configuration to configuration. If $ M$ ever repeats a configuration, it would go on to repeat this configuration over and over again and thus be in a loop.

I do not understand this: “If $ M$ ever repeats a configuration, it would go on to repeat this configuration over and over again”. What if $ M$ only repeat one configuration, then halts?

minimum moves for Knight on a infinite chessboard

You are given an infinite chessboard, a knight, a source and a destination.(Normal chess rules apply) we are required to get move knight from source to destination in minimum moves possible.

I can only think of a bfs solution. Is there a better solution possible?

The question is further extended by adding obstacles to the board. How to solve this question what will be the complexity.(I basically need a answer for this.)

Thank you.

Infinite loop “saving document” with libreoffice

A docx document in Libreoffice at one point got into an infinite loop where the status line flashed “saving document”. I was not able to interrupt it. I managed to close the window and save to ODT, but certain objects was lost in that file format, – apparently.

I am wondering what made Libreoffice get into this infinite loop and whether there are any tricks to make it stop and save the document?

Besides “saving document”, I see a popup window with “Error saving the document : General Error. General input/output error.”