Return the highest possible placement value based on the input

-4

1

Introduction

The challenge itself was something I came across and had to try and figure out for a personal of project of mine. I ended up branching out and asking family members if they could provide an equation to meet the requirements.

Note: I have (with the help of others) found a solution for this but now I'm just trying to see how others would approach this.

Challenge

Take the following scenario where the left hand side number is N (the input):

N    Output
0 -> 9
1 -> 99
2 -> 999
3 -> 9999
4 -> 99,999
5 -> 999,999
...
15 -> 9,999,999,999,999,999

So, essentially, for an input number N, your program must provide the highest integer with N + 1 decimal places.

Note: Commas are not required to separate the numbers, I placed them above purely for readability.

Criteria of Success

The criteria of success is based on the following:

  • Shortest in terms of code size

Script47

Posted 2018-04-29T19:07:24.153

Reputation: 175

Also can we output as a list ie [9, 9, 9] – Okx – 2018-04-29T19:10:04.967

1@Okx no, it has to be a single number. So 3 => 9999 and cannot be [9,9,9,9]. – Script47 – 2018-04-29T19:10:42.810

15Top of Hot Network Questions with a score of one. I'm thinking the idea about preventing HNQ when number of answers > score is a decent one. – CAD97 – 2018-04-29T21:01:25.863

@CAD97 meta it? – Script47 – 2018-04-29T21:26:04.027

@Script47 It was brought up on Mother Meta but nothing was ever done about it.

– Esolanging Fruit – 2018-04-30T05:24:10.043

3

Someone should write an answer in 99, although I'm not sure how to do multiply/power in that esolang. ;)

– Kevin Cruijssen – 2018-04-30T07:12:35.420

3You're getting a lot of downvotes because of the overly complicated explanation for what is, essentially, either print n+1 9s or print 10^n-1 – Jo King – 2018-04-30T12:41:06.987

1

@KevinCruijssen challenge accepted

– Giuseppe – 2018-04-30T12:56:58.987

3@Script47 It seems arbitrary to print N + 1 nines instead of just just N nines. – Adám – 2018-04-30T13:38:22.150

Answers

4

Neim, 3 bytes

>9

Explanation:

>      Increment input
 9    Repeat 9

Try it online!

Okx

Posted 2018-04-29T19:07:24.153

Reputation: 15 025

Holy moly, 3 bytes? That's insanity. – Script47 – 2018-04-29T19:17:56.623

4@Script Nothing surprising. Javascript/Python takes 3 builtins, this also takes 3 builtins. – user202729 – 2018-04-30T01:50:02.663

5

05AB1E, 3 bytes

Code:

>°<

Uses the 05AB1E encoding. Try it online!

Explanation:

>      # Increment the implicit input
 °     # Compute 10 ** (input + 1)
  <    # Decrement the result

Adnan

Posted 2018-04-29T19:07:24.153

Reputation: 41 965

4

Proton, 11 bytes

(1+)+("9"*)

Try it online!

This is a function.

Explanation

(1+)+("9"*)  Function
 1+          Anonymous function; add the input to 1
      "9"*   Anonymous function; multiply "9" by the input
    +        Function Composition; add the input to 1 then multiply "9" by this number
(  ) (    )  Brackets for order of operations

:o proton beats python with its function composition for once :D

HyperNeutrino

Posted 2018-04-29T19:07:24.153

Reputation: 26 575

Alternatives with same byte-count: ("9"*)+(+9) or ("9"*)+(9+). +(+n) prepends, +(n+) appends to the string ("9"*) which is the same as in @HyperNeutrino's answer above. – Kevin Cruijssen – 2018-04-30T10:05:42.843

@KevinCruijssen Oh cool, thanks! I forgot that "9"+9 worked in Proton – HyperNeutrino – 2018-04-30T15:17:09.473

4

APL+WIN, 9 5 bytes

Thanks to ngn for -3 bytes and Adám for -1 byte

Prompts for integer input:

1⎕/⍕9

Graham

Posted 2018-04-29T19:07:24.153

Reputation: 3 184

Save a byte with '9'⍕9. – Adám – 2018-04-29T23:18:29.617

and another three with (1+⎕)⍴ -> 1⎕/ – ngn – 2018-04-29T23:35:09.933

@ngn Very clever! – Adám – 2018-04-30T08:28:33.600

4

J, 7 bytes

Anonymous tacit prefix function

9^&.>:]

Try it online!

9^] nine raised to the power of the argument

&.… while both nine and the argument are under the influence of

  >: increment

I.e. increment nine and the argument, then power, then un-increment, i.e. decrement. Effectively ((9+1)^(n+1))-1.

Adám

Posted 2018-04-29T19:07:24.153

Reputation: 37 779

Also 7 bytes for output as a string: '9'$~>: – Galen Ivanov – 2018-04-30T06:36:10.747

1@GalenIvanov Sure, but this solution is way cooler :-) – Adám – 2018-04-30T08:40:57.767

1Of course, your solution is incomparably cooler. it's always a pleasure to use &. :) – Galen Ivanov – 2018-04-30T09:30:28.323

1@GalenIvanov Yes, I hope to get Under into APL next year, . – Adám – 2018-04-30T11:27:39.993

4

99, 90 bytes

 999
9999 9 9
99999 99 9 9999 9
999 999 9999 9
			




99999
999 999 9
 999999 999
 9 9999

Try it online!

Possibly not optimal, but it was fun to write.

EDIT: looks like I was right, as Jo King outgolfed me by not incrementing the input and being smarter about the gotos.

 999			assign input to tri-nine
9999 9 9		assign 0 to quad-nine
99999 99 9 9999 9	assign 81 to quint-nine for printing
999 999 9999 9		increment tri-nine
			




99999			print 81/nine (the numeral nine)
999 999 9		decrement tri-nine
 999999 999		if tri-nine is zero exit program (goto outside program)
 9 9999			else goto line nine

Giuseppe

Posted 2018-04-29T19:07:24.153

Reputation: 21 077

2Well done. Too bad the byte-count isn't 99 as well. ;p – Kevin Cruijssen – 2018-04-30T13:11:52.987

4

99, 69 bytes

9999 9 9
99999 99 9 9999 9
 999






99999
 99 999
999 999 9
 9 9999

Try it online!

Appropriate (but it's a pity that this didn't end up at 99 bytes)

Explanation

9999 9 9           9999 = 9-9
99999 99 9 9999 9  99999 = 99-9+(9-9)-9 = 9*9
 999               999 = input*9



Filler to get up to line 9


99999      Print (9*9)/9 as a number
 99 999    Jump to line 99 if 999 is 9-9
999 999 9  999 = 999 - 9
 9 9999    Jump unconditionally to line 9

Jo King

Posted 2018-04-29T19:07:24.153

Reputation: 38 234

2the number 9 now just looks weird to me. – Giuseppe – 2018-04-30T13:16:48.003

3

Actually, 3 bytes

u╤D

Explanation:

u    Increment input
 ╤   10 ** x
  D  Decrement

Try it online!

Okx

Posted 2018-04-29T19:07:24.153

Reputation: 15 025

3

Haskell, 14 13 bytes

f n=10*10^n-1

Or for string output 15 bytes, f n='9'<$[0..n]

Thanks to @EsolangingFruit for a byte.

Try it online!

Angs

Posted 2018-04-29T19:07:24.153

Reputation: 4 825

f n=10*10^n-1 saves a byte. – Esolanging Fruit – 2018-04-30T04:13:07.807

3

MATL, 6 bytes

Q10w^q

Try it online!

Explanation:

Q       % Grab input and increment by 1
 10     % Push 10
   w    % Swap stack
    ^   % Raise 10 to the power of input+1
     q  % Decrement by 1

Stewie Griffin

Posted 2018-04-29T19:07:24.153

Reputation: 43 471

3

Pyth, 4

*\9h

Online test.

Explanation

    Q  # Implicit input
   h   # Increment
*\9    # Repeat string "9" n+1 times

Digital Trauma

Posted 2018-04-29T19:07:24.153

Reputation: 64 644

Nice, I got t^Th, also 4 bytes.

– hakr14 – 2018-04-30T02:24:00.493

I got *p\9 with length 4. https://pyth.herokuapp.com/?code=%2ap%5C9&input=1&test_suite=1&test_suite_input=0&debug=0

– NeverHopeless – 2018-04-30T14:13:12.067

@NeverHopeless I see it works, but how? e.g. with input 4, I think this translates to print "9", 4 times; yet 5 "9"s are a printed? – Digital Trauma – 2018-04-30T15:50:20.937

1

@DigitalTrauma, by enabling debugging I found that there are two print functions 'Pprint' and 'imp_print' in this statement imp_print(times(Pprint("9"),Q)) and it is written here: https://pyth.herokuapp.com/rev-doc.txt that p <any> Print A, with no trailing newline. **Return A**. So my understanding is that Pprint prints Q times and 'p' token return that character which is printed by 'imp_print' that is why it appears Q+1 times.

– NeverHopeless – 2018-05-02T05:45:56.260

@NeverHopeless Makes sene - thanks! – Digital Trauma – 2018-05-02T17:03:45.947

3

dc, 8

A?1+^1-p

Try it online!

Explanation

A         # Push 10
 ?        # Push input
  1+      # Increment input
    ^     # Raise 10 to the (input + 1)th power
     1-   # Decrement
       p  # Print

Digital Trauma

Posted 2018-04-29T19:07:24.153

Reputation: 64 644

3

Zsh, 19 bytes

Zsh does a better job than Bash (needs eval):

printf 9%.s {0..$1}

Try it online!

Alternative, 20 bytes

This works for both Zsh and Bash (due to Digital Trauma):

echo $[10**($1+1)-1]

Try it online!

ბიმო

Posted 2018-04-29T19:07:24.153

Reputation: 15 345

1Shorter for bash: echo $[10**($1+1)-1] – Digital Trauma – 2018-04-30T06:31:34.770

@DigitalTrauma: Oh nice, works for Zsh as well (edited it in)! – ბიმო – 2018-04-30T08:19:38.887

2

Python 3, 16 bytes

lambda a:"9"*-~a

Try it online!

Just a simple anonymous function.

HyperNeutrino

Posted 2018-04-29T19:07:24.153

Reputation: 26 575

2

JavaScript (Node.js), 18 bytes

x=>"9".repeat(x+1)

Try it online!

DanielIndie

Posted 2018-04-29T19:07:24.153

Reputation: 1 220

1Or alternatively n=>10**-~n-1 – Arnauld – 2018-04-29T19:42:32.977

Though I never specified, it would be ideal to get it a int rather than a string. Nevertheless, good answer. – Script47 – 2018-04-29T21:30:12.720

@Arnauld it seems that with with your code when n = 15 the output is 10000000000000000. – Script47 – 2018-04-29T21:32:33.760

@Script47 JS can't support numbers greater than 9007199254740991. So, yes, it works up to n=14. – Arnauld – 2018-04-29T21:36:03.693

@Arnauld ah, right, did not know that. Thank you very much. Any ideas why it is limited as such? Meaning, was it because of technological limitations when JS first came and it hasn't changed or is it something else? – Script47 – 2018-04-29T21:37:00.637

@Script47 Here is why. (Of course, you can manipulate numbers greater than that, but they will be rounded.)

– Arnauld – 2018-04-29T21:44:29.077

4Alternative to @Arnauld's version: n=>"10e"+n-1 – ETHproductions – 2018-04-30T02:37:22.643

2

Jelly, 4 bytes

‘⁵*’

Try it online!

‘⁵*’ - Main link. Argument: n (integer)
‘    - n+1
 ⁵*  - 10 ** (n+1)
   ’ - (10 ** (n+1)) - 1

user80240

Posted 2018-04-29T19:07:24.153

Reputation:

2

Husk, 4 bytes

R'9→

Try it online!

R'9→  -- example input: 3
   →  -- increment: 4
R'9   -- replicate the character '9': ['9','9','9','9']
      -- implicitly print "9999"

ბიმო

Posted 2018-04-29T19:07:24.153

Reputation: 15 345

2

Japt, 5 4 bytes

°Uî9

Try it online!

Shaved off that one byte thanks to Shaggy's clever eyes. You can see the edit history for a number of 5-byte solutions.

Nit

Posted 2018-04-29T19:07:24.153

Reputation: 2 667

14 bytes: °Uî9 – Shaggy – 2018-04-29T23:35:19.393

@Shaggy Nice! You should post it as an answer. – Nit – 2018-04-30T04:50:03.353

It's just a variation on your first solution so work away. Also, I have a 3 byte solution to post after lunch. – Shaggy – 2018-04-30T12:13:10.473

2

Canvas, 3 bytes

╵9×

Try it here!

╵    increment the input
 9   push "9"
  ×  repeat the "9" input+1 times

dzaima

Posted 2018-04-29T19:07:24.153

Reputation: 19 048

2

Brain-Flak, 48 bytes

({}()){({}<(((((()()()){}()){}){}){}())>[()])}{}

Try it online!

This uses the -A to enable ASCII output. Bonus round: A version without -A.

Brain-Flak, 50 bytes

({}(())){({}<((({})(({}){}){}){})>[()])}{}({}[()])

Try it online!

James

Posted 2018-04-29T19:07:24.153

Reputation: 54 537

46 bytes – Jo King – 2018-04-30T05:14:39.750

2

Momema, 21 bytes

a00+1*0-8 9a=+*0-+1_A

Try it online! Requires the -i interpreter flag.

Explanation

A brief rundown of Momema's features:

  • Its only data type is the unbounded integer. It has a double-ended tape (indexed by unbounded integers) where every number is initialized to zero.
  • Strings of digits are integer literals which evaluate to themselves. Leading zeroes are parsed as their own integers.
  • +ab evaluates to the sum of a and b.
  • -a evaluates to the negation of a.
  • *a evaluates to the value of cell a on the tape.
  • =a evaluates to 0 if a evaluates to 0, and = otherwise.
  • At the top level, ab stores b at cell a on the tape. Attempting to write a number to -8 writes its decimal representation to STDOUT instead.
  • At the top level, [w]a (where [w] is any string of lowercase letters) acts like "relative jump forward by a jump instructions that share the label [w]."
  • The Momema reference implementation accepts a flag -i, which activates interactive mode. In interactive mode, _[W] (where [W] is any string of uppercase letters) is called a hole and evaluates to a number read from STDIN. However, it caches the number with its label, so if a hole with the same label is ever evaluated again it will be reused.

Knowing this, here's how you expand this program:

a   0                                                                                       # do {
0   (+ 1 (* 0))                                                                             #   n = n + 1
-8  9                                                                                       #   print 9
a   (= (+ (* 0) (- (+ 1 _A))))                                                              # while (n != input)

(This still parses, by the way; the Momema parser treats parentheses the same way as whitespace.)


a   0

Jumps forward by 0 a instructions (i.e. does nothing). This is only here to serve as a jump target later.

0   (+ 1 (* 0))

Increments the value of cell 0 (initially 0) and stores it back in cell 0.

-8  9

-8 is memory-mapped for numeric I/O, so this outputs 9 to STDOUT.

a   (= (+ (* 0) (- (+ 1 _A))))

Compute tape[0] - (input + 1). If it is zero (i.e. both sides were equal), then = maps the result to 0, making it a no-op. Control runs off of the end of the program. However, if it is nonzero, this is a 1. Since there are no a instructions after here, it wraps around to the beginning of the program.

Esolanging Fruit

Posted 2018-04-29T19:07:24.153

Reputation: 13 542

2

brainfuck, 24 23 bytes

thanks to Jo King for -1 byte

-[++>+[+<]>]>+<,+[->.<]

Try it online! Takes input as ASCII

ovs

Posted 2018-04-29T19:07:24.153

Reputation: 21 408

Most people wouldn't begrudge you removing that leading > – Jo King – 2018-04-30T07:50:05.120

@JoKing The next time I should have a closer look while copying from the esolang page :). Thank you – ovs – 2018-04-30T07:54:35.997

2

Whitespace, 79 bytes

[S S S T    S T S N
_Push_10][S N
S _Duplicate_10][S N
S _Duplicate_10][S N
S _Duplicate_10][T  N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve_input][N
S S N
_Create_Label_LOOP][S S S T N
_Push_1][T  S S T   _Subtract][S N
S _Duplicate][N
T   T   S N
_If_negative_Jump_to_Label_EXIT][S N
T   _Swap][S T  S S T   S N
_Copy_2st][T    S S N
_Multiply][S N
T   _Swap][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_EXIT][T   S S S _Add][T   N
S T _Print_as_integer]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Explanation in pseudo-code:

Integer i = STDIN as integer
Integer j = 10
Start LOOP:
  i = i - 1
  If i is negative (-1): Go to function PRINT_AND_EXIT
  j = j * 10
  Go to next iteration of LOOP

function PRINT_AND_EXIT:
  j = j + i (Since i=-1 at this point, this is basically j = j - 1)
  Print j as integer
  Exit with error

Example run (n=4):

Command   Explanation                   Stack              HEAP    STDIN   STDOUT  STDERR

SSSTSTSN  Push 10                       [10]
SNS       Duplicate top (10)            [10,10]
SNS       Duplicate top (10)            [10,10,10]
SNS       Duplicate top (10)            [10,10,10,10]
TNTT      Read STDIN as integer         [10,10,10]         {10:4}  4
TTT       Retrieve                      [10,10,4]          {10:4}
NSSN      Create Label_LOOP             [10,10,4]          {10:4}
 SSSTN     Push 1                       [10,10,4,1]        {10:4}
 TSST      Subtract (4-1)               [10,10,3]          {10:4}
 SNS       Duplicate top (3)            [10,10,3,3]        {10:4}
 NTTSN     If neg.: Jump to Label_EXIT  [10,10,3]          {10:4}
 SNT       Swap top two                 [10,3,10]          {10:4}
 STSSTSN   Copy 2nd                     [10,3,10,10]       {10:4}
 TSSN      Multiply (10*10)             [10,3,100]         {10:4}
 SNT       Swap top two                 [10,100,3]         {10:4}
 NSNN      Jump to Label_LOOP           [10,100,3]         {10:4}

 SSSTN     Push 1                       [10,100,3,1]       {10:4}
 TSST      Subtract (3-1)               [10,100,2]         {10:4}
 SNS       Duplicate top (2)            [10,100,2,2]       {10:4}
 NTTSN     If neg.: Jump to Label_EXIT  [10,100,2]         {10:4}
 SNT       Swap top two                 [10,2,100]         {10:4}
 STSSTSN   Copy 2nd                     [10,2,100,10]      {10:4}
 TSSN      Multiply (100*10)            [10,2,1000]        {10:4}
 SNT       Swap top two                 [10,1000,2]        {10:4}
 NSNN      Jump to Label_LOOP           [10,1000,2]        {10:4}

 SSSTN     Push 1                       [10,1000,2,1]      {10:4}
 TSST      Subtract (2-1)               [10,1000,1]        {10:4}
 SNS       Duplicate top (1)            [10,1000,1,1]      {10:4}
 NTTSN     If neg.: Jump to Label_EXIT  [10,1000,1]        {10:4}
 SNT       Swap top two                 [10,1,1000]        {10:4}
 STSSTSN   Copy 2nd                     [10,1,1000,10]     {10:4}
 TSSN      Multiply (1000*10)           [10,1,10000]       {10:4}
 SNT       Swap top two                 [10,10000,1]       {10:4}
 NSNN      Jump to Label_LOOP           [10,10000,1]       {10:4}

 SSSTN     Push 1                       [10,10000,1,1]     {10:4}
 TSST      Subtract (1-1)               [10,10000,0]       {10:4}
 SNS       Duplicate top (0)            [10,10000,0,0]     {10:4}
 NTTSN     If neg.: Jump to Label_EXIT  [10,10000,0]       {10:4}
 SNT       Swap top two                 [10,0,10000]       {10:4}
 STSSTSN   Copy 2nd                     [10,0,10000,10]    {10:4}
 TSSN      Multiply (10000*10)          [10,0,100000]      {10:4}
 SNT       Swap top two                 [10,100000,0]      {10:4}
 NSNN      Jump to Label_LOOP           [10,100000,0]      {10:4}

 SSSTN     Push 1                       [10,100000,0,1]    {10:4}
 TSST      Subtract (0-1)               [10,100000,-1]     {10:4}
 SNS       Duplicate top (-1)           [10,100000,-1,-1]  {10:4}
 NTTSN     If neg.: Jump to Label_EXIT  [10,100000,-1]     {10:4}
NSSSN      Create Label_EXIT            [10,100000,-1]     {10:4}
TSSS       Add (10000+-1)               [10,99999]         {10:4}
TNST       Print as integer             [10]               {10:4}          99999
                                                                                   error

Stops program with error: No exit defined.

Kevin Cruijssen

Posted 2018-04-29T19:07:24.153

Reputation: 67 575

1

Perl 5, 7 bytes

$_=9x$_

Try it online!

steve

Posted 2018-04-29T19:07:24.153

Reputation: 2 276

1

You don't need the quotes there. Try it online!

– Xcali – 2018-04-30T01:03:02.757

Good spot, thx. – steve – 2018-04-30T05:14:27.067

1

AWK, 26 bytes

{for(;a++<$1;){printf"9"}}

Try it online!

steve

Posted 2018-04-29T19:07:24.153

Reputation: 2 276

1

Julia, 14 bytes

f(n)="9"^(n+1)

That's if the result can be a string.

spacetyper

Posted 2018-04-29T19:07:24.153

Reputation: 121

1

SNOBOL4 (CSNOBOL4), 30 bytes

	OUTPUT =DUPL(9,INPUT + 1)
END

Try it online!

Giuseppe

Posted 2018-04-29T19:07:24.153

Reputation: 21 077

1

Gol><>, 5 bytes

PR`9H

Try it online!

This is a Gol><> function which takes the stack content as input.

Example full program & How it works

1AG9G
PR`9H

1AG    Register row 1 as function G
   9G  Call G with stack [9]

P      Increment
 R`9   Push char '9' that many times
    H  Print the stack content as chars and halt

Bubbler

Posted 2018-04-29T19:07:24.153

Reputation: 16 616

1

TI-Basic, 7 bytes

10^(Ans+1)-1

Fairly straightforward...

Timtech

Posted 2018-04-29T19:07:24.153

Reputation: 12 038

1Yeah, no idea why this got flagged. – Nissa – 2018-04-30T01:21:00.107

@Ste Blame SE automatic bots. Why must answers here have explanation? – user202729 – 2018-04-30T01:57:29.823

1

CJam, 6 bytes

qi)'9*

Try it online!

Esolanging Fruit

Posted 2018-04-29T19:07:24.153

Reputation: 13 542

1

Befunge-98 (FBBI), 13 12 bytes

-1 byte thanks to Jo King

&#9':_@#\-1,

Try it online!

ovs

Posted 2018-04-29T19:07:24.153

Reputation: 21 408

1

IBM/Lotus Notes Formula, 16 bytes

@Power(10;i+1)-1

Simple port of my Python answer. One of the nice things about formula is that if you pass it a list it will apply the same function to each list member.

enter image description here

ElPedro

Posted 2018-04-29T19:07:24.153

Reputation: 5 301

1

Symbolic Python, 40 37 bytes

__=-~(_==_)
_=(__+__**-~__)**-~_+~_+_

Try it online!


Ungolfed

# implicit input stored in _
__  = -~(_==_)             # __ = -~True = 1 + True = 1 + 1 = 2
_=(__+__**-~__)**-~_+~_+_  # _  = (2 + 2 ** -~2) ** -~_ + ~_ + _ 
                                = (2 + 2**3) ** (_ + 1) - -~_ + _
                                = 10 ** (_ + 1) - (_ + 1) + _
                                = 10 ** (_ + 1) - 1
# implicit output of _

other 37 byte solutions

__=_==_
_=(-~__*-~-~-~-~__)**-~_+~_+_

Try it online!

_=(-~(_==_)*-~-~-~-~(_==_))**-~_+~_+_

Try it online!


Symbolic Python, 29 bytes

multiplies the string '9' by _ + 1

_=`-~-~(_==_)*-~-~(_==_)`*-~_

Try it online!

ovs

Posted 2018-04-29T19:07:24.153

Reputation: 21 408

1

Charcoal, 5 4 bytes

×9⊕N

Try it online!

Explanation

×9     Repeat "9"
  ⊕N ++(next number as input) times

ASCII-only

Posted 2018-04-29T19:07:24.153

Reputation: 4 687

1

Tcl, 26 bytes

puts [expr 10*10**$argv-1]

Try it online!

ASCII-only

Posted 2018-04-29T19:07:24.153

Reputation: 4 687

1

Common Lisp, 30 bytes

(lambda(n)(1-(expt 10(1+ n))))

Try it online!

ASCII-only

Posted 2018-04-29T19:07:24.153

Reputation: 4 687

1

JavaScript (ES6), 18 bytes

Just throwing out a recursive solution to the problem:

f=n=>n?9+f(n-1):''

Evaluates the expression ''+9+9+9+9... (depending on n).

Because the first operand is a string, all the + operators are treated as concatenation instead of addition.

In my Chrome, works up to f(11424) before hitting a stack overflow.

f=n=>n?9+f(n-1):''

for(i = 0; i < 100; i += 10) {
  console.log(f(i));
}

Rick Hitchcock

Posted 2018-04-29T19:07:24.153

Reputation: 2 461

1

PHP, 25 bytes

Try it online

Code

(Passing $arguments to the script)

<?=str_repeat(9,$argv+1);

Or a recursive function, 42 Bytes

Try it online!

function f($u){echo($u<0)?"":"9".f($u-1);}

Francisco Hahn

Posted 2018-04-29T19:07:24.153

Reputation: 591

0

Phooey, 11 bytes

&.+1[$i9-1]

Try it online!

Explanation

&.+1[$i9-1]
&.              take numeric input
  +1            add 1
    [   -1]     until that is zero:
     $i9        output 9s

Conor O'Brien

Posted 2018-04-29T19:07:24.153

Reputation: 36 228

0

Attache, 9 bytes

{N!-~_&9}

Try it online!

Alternatives

10 bytes: {"9"*t-~_}

13 bytes: (pointfree) 9&Resize@1&`+

Explanation

{N!-~_&9}     
{       }     anonymous lambda taking input `_`
   -~_        input + 1
      &9      9s repeated that much (array of 9s)
 N!           cast to integer

Conor O'Brien

Posted 2018-04-29T19:07:24.153

Reputation: 36 228

0

Red, 24 bytes

func[n][loop n[prin"9"]]

Outputs a string

Try it online!

Galen Ivanov

Posted 2018-04-29T19:07:24.153

Reputation: 13 815

0

Python 2, 20 18 bytes

lambda i:10**-~i-1

Try it online!

Don't think it needs an explanation.

-2 with thanks to @ovs

ElPedro

Posted 2018-04-29T19:07:24.153

Reputation: 5 301

0

Triangularity, 31 bytes

...)...
..IE@..
.)10^).
@_+....

Try it online!

Also 31 bytes

...)...
..IE)..
.@_rM..
"9"}""J

Try it online!

Mr. Xcoder

Posted 2018-04-29T19:07:24.153

Reputation: 39 774

0

Java 8, 27 25 bytes

n->n+=Math.pow(10,n+1)+~n

Try it online.

This is basically a shorter version of n->(long)Math.pow(10,n+1)-1, because n+=...-n saves a byte in comparison to (long).... (And combining -n-1 to +~n saves a second byte in this case.)

Kevin Cruijssen

Posted 2018-04-29T19:07:24.153

Reputation: 67 575

0

Swift 4, 47 34 32 bytes

-13 -15 bytes thanks to @Mr. Xcoder

{(0...$0).map{_ in"9"}.joined()}

Try it online!

ASCII-only

Posted 2018-04-29T19:07:24.153

Reputation: 4 687

{(0...$0).map{_ in"9"}.joined()} saves another 2 bytes. Honestly, I should sometimes follow my own tips. – Mr. Xcoder – 2018-04-30T12:09:37.807

0

Prolog (SWI), 34 23 20 bytes

X+Y:-Y is 10*10^X-1.

Try it online!

Call as <input>+<result variable>.

ASCII-only

Posted 2018-04-29T19:07:24.153

Reputation: 4 687

0

Excel, 12 bytes

=10^(A1+1)-1

Or alternatively, to better handle larger values (>10) for 13 bytes

=REPT(9,A1+1)

Wernisch

Posted 2018-04-29T19:07:24.153

Reputation: 2 534

0

Ruby, 11 bytes

->n{?9*-~n}

Try it online!

G B

Posted 2018-04-29T19:07:24.153

Reputation: 11 099

0

C (gcc) (-lm), 22 bytes

f(n){n=pow(10,-~n)-1;}

Try it online!

Saved 4 bytes thanks to Kevin Cruijssen.

Mr. Xcoder

Posted 2018-04-29T19:07:24.153

Reputation: 39 774

Why the int? Just f(n){n=pow(10,-~n)-1;} also works, doesn't it? – Kevin Cruijssen – 2018-05-01T07:54:49.783

0

Cubix, 15 bytes

Iu9)^>Os(?@.>sW

Try it online!

Expands to the following cube:

    I u
    9 )
^ > O s ( ? @ .
> s W . . . . .
    . .
    . .

Giuseppe

Posted 2018-04-29T19:07:24.153

Reputation: 21 077

0

Japt -P, 3 bytes

ò@9

Try it


Explanation

ò       :Range [0,input]
 @      :Pass each through a function
  9     :  Return 9
        :Implicitly join and output

Shaggy

Posted 2018-04-29T19:07:24.153

Reputation: 24 623

0

GolfScript, 6 bytes

~)'9'*

Try it online!

Explanation:

~)'9'* Full program, implicit input
       Stack: '5'
~      Evaluate
       Stack: 5
 )     Increment
       Stack: 6
  '9'  Push '9'
       Stack: 6 '9'
     * Repeat
       Stack: '999999'
       Implicit output

GolfScript, 7 bytes

~)10\?(

Try this one!

Explanation:

~)10\?( Full program, implicit input
        Stack: '5'
~)      Evaluate and increment (as above)
        Stack: 6
  10\?  Raise 10 to that power
        Stack: 1000000
      ( Decrement
        Stack: 999999
        Implicit output

wastl

Posted 2018-04-29T19:07:24.153

Reputation: 3 089

0

Stax, 4 bytes

^|Av

Run and debug it

Packed would not be any shorter.

Explanation:

^|Av Full program, implicit input
^    Increment
 |A  Raise ten to that power
   v Decrement
     Implicit output

Stax, 4 bytes

^'9*

Run and debug it

^'9* Full program, implicit input
^    Increment
 '9* Repeat "9"
     Implicit output

wastl

Posted 2018-04-29T19:07:24.153

Reputation: 3 089