How do I create a function that takes binary as input and generates certain Cartesian coordinates based on the binary value and index?

148 Views Asked by At

Given an input such as 00111011, I would like to generate a set of Cartesian coordinates such as:

$$\{(0, 2), (1, 2), (2, 2), (3, 2), (4, 3), (5, 3)\}$$

enter image description here

I can easily write a computer program that does it, but I was curious if it's possible to write a mathematical function that does the same thing.

Sadly, I don't even know where to begin with this one.

Maybe something like this:

Let $B$ be a binary string such as 001111011. Let $i \in \mathbb{Z}$. Let $B_i$ represent the value of the string at index $i$. We want to define a function $f:B\to\mathbb{N}\times \mathbb{N}$.

Not sure how to proceed from here. Any ideas?

1

There are 1 best solutions below

0
On BEST ANSWER

Suppose our sequence is $B_1,B_2,\ldots$. Then $f:\mathbb{N}\to\mathbb{N}^2$ is only defined for $i$ when $B_i=1$. When $B_i$ is equal to $1$, note that the $x$-value is just the number of $1$s before it -- that is, $\sum\limits_{j<i}B_j$, and the $y$-value is just $i-x$-value (as achille hui mentioned in comments).

Therefore, for any $n$ such that $B_n=1, f(n)=\left(\sum\limits_{j<i}B_j,\,\,i-\sum\limits_{j<i}B_j\right)$, and your set of coordinates is just the range of $f$.