2
$\begingroup$

I need a function such that if input is $n$ it outputs an $n$-digit number. I need a mathematical function.

For example:

$$\begin{align}\mathrm{ANY}(2) &= 22 \\ \mathrm{ANY}(3) &= 333 \\ \mathrm{ANY}(n) &= nnn\ldots n \quad (n \text{ times})\end{align}$$

I think $\mathrm{ANY}(n)$ is something like:

$$\begin{align}\mathrm{ANY}(2) &= (10^1 + 10^2) * 2 \\ \mathrm{ANY}(3) &= (10^1 + 10^2 + 10^3) * 3 \\ \mathrm{ANY}(n) &= (10^1 + 10^2 + \ldots + 10^n) * n\end{align}$$

My question is can we further simplify the equation: $10^1 + 10^2 + \ldots + 10^n$? Or is it not possible?

Additionally, I need just any $n$-digit number on $n$ input, not necessary like $22$, $333$, $4444$, $\ldots$. In case simplification is not possible then suggest me any other function? I have no much idea if its possible.
Also domain to my $\mathrm{ANY}$ function can be $1$ to $100$.

I need to solve some problem in computer science.

$\endgroup$
3
  • $\begingroup$ if my question is wrong I can remove it and try to find answer myself. $\endgroup$ Mar 28, 2013 at 19:24
  • $\begingroup$ what is to happen if $n>9$ $\endgroup$
    – Maesumi
    Mar 28, 2013 at 19:32
  • $\begingroup$ @Maesumi actually I just need any n digit number don't bothers if it 11111 11111 1 or 22222 22222 2 $\endgroup$ Mar 28, 2013 at 19:34

3 Answers 3

4
$\begingroup$

I suppose simpler functions would be $\mathrm{any}(n) = 10^{n-1}$, e.g. outputting $\mathrm{any}(3) = 100$, or $\mathrm{any}(n) = 10^n - 1$, e.g. outputting $\mathrm{any}(3) = 999$.

To get the exact function you specified, you could use the formula for geometric series to obtain $\mathrm{any}(3) = (\frac{10^{n} - 1}{9}) \cdot n$. Note that this does not give you an $n$-digit number for $n \geq 10$.

$\endgroup$
2
  • $\begingroup$ thanks :) sorry it was so simple I mean your first solution. $\endgroup$ Mar 28, 2013 at 19:43
  • $\begingroup$ @FixedPoint: Yes, that formula works, but the formula suggested by the OP leads to $\mathrm{any}(n)=(10^n-1)/9 \cdot n$ (note the extra $n$) which gets an unwanted extra digit once $n \geq 10$. $\endgroup$
    – TMM
    Mar 29, 2013 at 0:23
3
$\begingroup$

This one gives you only till $n\leq 9$. You could take the geometric series which says that $$\sum_{k=0}^n q^k = \frac{q^{n+1}-1}{q-1}$$ which is in your case $$\frac{1}{10}\cdot \left( \frac{10^{n+1}-1}{9}-1\right)\cdot n$$ the $-1$ is there because you don't have the naught term.

If you only want an arbitrary $n$ digit number take $$10^{n-1}$$ if you want alle the same digit take $$\frac{10^n-1}{9} \cdot \text{your favorite digit}$$

To get any number from 10 till 99 with your exact formula take $$\frac{1}{100} \cdot \sum_{k=1}^\frac{n}{2} 100^k \cdot n=\frac{1}{99} \cdot (10^n-1)\cdot n$$ for $n$ even and $$\frac{1}{10} \cdot \sum_{k=1}^\frac{n-1}{2} 100^k \cdot n + \left\lfloor\frac{n}{10}\right\rfloor=\frac{1}{99} (10^{n}-10)\cdot n +\left\lfloor\frac{n}{10}\right\rfloor$$

$\endgroup$
10
  • 1
    $\begingroup$ Note that when $n \geq 10$, the number of digits will be off. $\endgroup$ Mar 28, 2013 at 19:31
  • $\begingroup$ Yes I understood your equation. Thanks $\endgroup$ Mar 28, 2013 at 19:44
  • $\begingroup$ BTW what is naught term ? yes i confuse you people. $\endgroup$ Mar 28, 2013 at 19:46
  • 1
    $\begingroup$ It is the term for $k=0$ don't know if it is a usual expression $\endgroup$ Mar 28, 2013 at 19:47
  • 1
    $\begingroup$ @GrijeshChauhan updated my solution try again, it gives you the wanted pattern :) $\endgroup$ Mar 28, 2013 at 19:59
0
$\begingroup$

so if you are okay with

any(1)=1

any(2)=11

any(3)=111

and so on then $$any(N)=\frac{10^N-1}{9}$$ will work for any number of digits so the domain is all natural numbers. You can get a number with whatever number of digits you need.

$\endgroup$
1
  • $\begingroup$ Why the downvote? This any(N) does give you a N digit number for any natural number N. any(20)=11111111111111111111 $\endgroup$ Mar 29, 2013 at 0:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .