# Opposite of the digital root!

Also known as the [analog root]

(Opposite of the digital root!) ;)

The digital root of a number is the continuous summation of its digits until it is a single digit, for example, the digital root of 89456 is calculated like this:

8 + 9 + 4 + 5 + 6 = 32

3 + 2 = 5

The digital root of 89456 is 5.

Given a digit as input via STDIN, print/return all of the possible two digit numbers that have that digital root. If you need it to, it can include itself, e.g. 05

These are all of the possible inputs and outputs:

(You get to choose whether or not to include the leading zero for the digit itself)

## I/O

0 => 0 or 00 or nothing

1 => 01 and/or 1, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91 - Make sure that 1 does not return 100

2 => 02 and/or 2, 11, 20, 29, 38, 47, 56, 65, 74, 83, 92

3 => 03 and/or 3, 12, 21, 30, 39, 48, 57, 66, 75, 84, 93

4 => 04 and/or 4, 13, 22, 31, 40, 49, 58, 67, 76, 85, 94

5 => 05 and/or 5, 14, 23, 32, 41, 50 ,59, 68, 77, 86, 95

6 => 06 and/or 6, 15, 24, 33, 42, 51, 60, 69, 78, 87, 96

7 => 07 and/or 7, 16, 25, 34, 43, 52, 61, 70, 79, 88, 97

8 => 08 and/or 8, 17, 26, 35, 44, 53, 62, 71, 80, 89, 98

9 => 09 and/or 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99

No standard loopholes, and it's , so the shortest answer in bytes wins.

• does the number itself count as a two digit number? (05)? May 29, 2017 at 0:44
• Inverse challenge May 29, 2017 at 0:48
• What should the output be for 0? And again, in a case like this where there are only 10 possible inputs, it would be of great benefit to supply the outputs in your challenge. May 29, 2017 at 0:50
• Your decision on how to handle zero invalidates many of the answers that were posted. It would be considerate to let the participants know you have made a decision. May 29, 2017 at 2:48
• is the opposite of a digital root an analog root? May 29, 2017 at 3:32

## JavaScript (ES6), 2731 30 bytes

Returns 0 for 0 or an array of solutions otherwise.

n=>n&&[...1e9+''].map(_=>n+=9)


### Demo

let f =

n=>n&&[...1e9+''].map(_=>n+=9)

for(n = 0; n < 10; n++) {
console.log(n, JSON.stringify(f(n)));
}

• A downvote without any comment doesn't help much to improve the answer... May 29, 2017 at 7:27
• To some it might be unclear which part is the actual codegolfed function, and which part is a demonstration. It might be a good idea to just put the function itself straight below the JavaScript line. May 29, 2017 at 20:09
• @DavidMulder Thanks for the suggestion. That's actually the way I answer most of the time. Updated. May 29, 2017 at 20:24
• Nice solution! Sorry for dragging up an old solution but could you drop the + to save another byte? Though it would not work with stdin string that way I suppose. Jan 12, 2018 at 11:03
• @CraigAyre I'm not sure where this + came from... Updated. Thanks! Jan 12, 2018 at 11:25

# 05AB1E, 1312 9 bytes

тL<ʒSOSOQ


Try it online!

## Explanation

тL<ʒSOSOQ   Main link. Argument n
тL<         List from 1 to 100, then decrement to get 0 to 99
ʒ        Filter
SOSO    Sum of all chars, twice
Q   Compare to input

• I think you can replace the infinite loop by SOSO, since the number will never be bigger than 99. May 29, 2017 at 10:32
• @Adnan Don't think, I assure you he can. May 29, 2017 at 10:46
• тL< isn't really shorter than plain 99Ý. ;) May 29, 2017 at 10:48
• @EriktheOutgolfer Well, I was probably trying to hard to save a byte there ;D May 29, 2017 at 10:54
• Main "link"? Since when 05AB1E has links? It's not Jelly. May 30, 2017 at 3:11

# Jelly, 8 bytes

11Ḷ×9+ȧ@


Try it online!

Different algorithm than my other answer.

# Brain-Flak, 46 bytes

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


Try it online!

## Explanation

This answer uses an idea from Megatom's answer namely using the stack height as the difference between the loop counter and the increment. Like previous answers this answer has a large outer loop to catch all the zeros. Inside the loop we push 10 to act as a counter, we then start another nested loop. In this loop we decrement the counter by 1

({}[()])


Then we pop the top two items, which are the counter and the last item we calculated. We add these to the stack height in order to counter balance the decrementation, we then push this twice, once for output and once so that it can be consumed to calculate the next result. Pushing things twice means we accidentally push an additional value which needs to be removed at the end of execution.

The reason this just barely beats Megatom is Megatom's answer is forced to get its stack heights while the last result is still on the stack. This means they are forced to use a rather expensive [()] to decrease the total by one. By moving the duplicate to the end of the loop I am able to avoid having to use [()] at the cost of an additional {} at the very end of the program. If Megatom were to use this strategy his answer would look like:

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


also 46 bytes.

# Brain-Flak, 52 bytes

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


Try it online!

## Explanation

The main outerloop makes a special case for input of zero. If zero is input we jump over the entire loop, pop zero and then output nothing. Otherwise we enter the loop. Here we push loop 10 times each time adding 9 to the top of the stack, keeping old values. Since 9 preserves digital sums this will get us the next value. Once the loop has expired we use the zero it generated to exit the loop which is then popped by the {} at the end.

# Brain-Flak, 56 bytes

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


Try it online!

## Explanation

This version works very similarly to the last one, except we loop 9 times instead of 10 leaving out the original value. In order to do this we have to rearrange the way we handle memory a bit. All of the bytes we might have saved using this method get put into cleanup.

• The 46 doesn’t preserve the original number :(
– Jo King
Jan 15, 2018 at 2:28
• @JoKing Yeah, it just does the 2 digit cases. Which I think is kind of the intention of the question, so that makes me pretty happy. Jan 15, 2018 at 2:34
• Nice Job! You earned the bounty. Jan 15, 2018 at 19:45

f takes an integer and returns a list of integers.

f d=[d,d+9..99^0^0^d]


Try it online!

• Starts with the digit d and generates the range with every 9th number up to a bound of 99, except for the tricky case of 0.
• To stop early for 0, uses that the power 0^d==1 for 0 and ==0 for all other digits. Thus 99^0^0^d gives 1 for 0 but 99 for anything else.

## Pyke, 6 bytes

ITV
9+


Try it here!

ITV\n9+ - if input: (don't print anything for 0 case)
TV\n9+ -  repeat 10 times:
\n   -    print ^
9+ -   ^ += 9


# Python 2, 29 bytes

lambda n:n and range(n,100,9)


Try it online!

# Brachylog, 12 bytes

0g|g{t+₉}ᵃ¹⁰


Try it online!

### Explanation

0g               Input = 0, Output = 
|              Or
g{   }ᵃ¹⁰     Accumulate 10 times, starting with [Input]
t+₉         Take the last element, add 9


# Bash, 31 27 bytes

seq $1 9$(($1?99:0))|xargs  Try it online! previous eval echo {$1..$(($1?99:0))..9}

• how does one find the man pages / bash help / ? about "{x..y..z}" ? what is it called? May 30, 2017 at 11:18
• found it: in man page, search [^.]\.\.[^.] : brace expansion: (...) A sequence expression takes the form {x..y[..incr]}, where x and y are either integers or single characters, and incr, an optional increment, is an integer. (...) When the increment is supplied, it is used as the difference between each term. The default increment is 1 or -1 as appropriate. May 30, 2017 at 11:22

# Dyalog APL, 15 bytes

{(×⍵)/+\⍵,10⍴9}


How?

⍵,10⍴9 - concatenate input with 10 9s (⍵ 9 9 9 9 9 9 9 9 9 9).

+\ - cumulative sum.

(×⍵)/ - expand signum times - where signum gives 1 for 1-9 and 0 for 0.

Try it online!

### Dyalog APL, 24 bytes

{⍵/⍨⎕=(⍵≠0)×1+9|⍵-1}⍳100


Requires ⎕IO←0.

How?

                      ⍳100  ⍝ 0 .. 99
1+9|⍵-1      ⍝ digit sum (⍵-1 mod 9 + 1)
(⍵≠0)×             ⍝ edge case for 0
⎕=                    ⍝ equals to the input
⍵/⍨                       ⍝ compress with the range


# Brain-Flak, 48 bytes

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


Try it online!

I may add an explanation later.

• Brilliant! I tried combining the +9 with the length to make a counter, but I never thought of doing it the other way around
– Jo King
Jan 13, 2018 at 3:10
• Jan 14, 2018 at 13:11

# Mathematica, 25 bytes

If[#==0,0,Range[#,99,9]]&


works for 0

• Doesn't work for 0. This also wouldn't include numbers whose digits add up to a number greater than 9. (e.g. 9 wouldn't have 99 in the output). May 29, 2017 at 2:42
• I see what you mean. Do you inspect only "my" codes? cause many codes here don't work for 0... May 29, 2017 at 2:49
• Welp, I tend to focus on Mathematica code because that's the language I know best. Didn't mean to target you or anything. I apologize if it seemed like it. May 29, 2017 at 2:53
• all fixed and working May 29, 2017 at 3:02
• What? No builtin? May 29, 2017 at 16:17

# Jelly, 12 bytes

⁵²Ḷµ,³%9EµÐf


Try it online!

How It Works

⁵²Ḷµ,³%9EµÐf
⁵             - literal 10
²            - square
R           - lowered range: 0 to 99 inclusive.
µ     µÐf  - filter based on:
,³          - element and input
%9        - mod 9
E       - are equal

• When I use 1 as an argument it also gives out 100, which is not two digit May 29, 2017 at 2:54
• This doesn't split the 0 and 9 cases. May 29, 2017 at 7:51
• This still doesn't work for 0 Apr 6, 2018 at 15:44

# Actually, 18 bytes

╗2╤DR⌠╜-9@%Y⌡░╜;)I


Try it online!

Explanation:

╗2╤DR⌠╜-9@%Y⌡░╜;)I
╗                   save input to register 0
2╤DR               range(1, 100)
⌠╜-9@%Y⌡░      elements in range where function returns truthy:
╜-              subtract from input
9@%           mod 9
Y          is equal to 0
╜;)   push a copy of the input on the top and the bottom of the stack
I  if input is truthy, return the filtered range, else return the input (special-cases 0)

• @FryAmTheEggman Fixed.
– user45941
May 29, 2017 at 7:06

# PHP, 41 Bytes

prints underscore separated values

for(;100>$a=&$argn;$a+=$a?9:ERA)echo$a._;  ERA is the shortest constant in PHP with the value 131116. You can replace it with the boring alternative 100 or end the program with die Online Version # Brain-Flak, 54 52 bytes {<>((((()()())){}{})()){({}<(({})<>({}))><>[()])}}<>  Try it online! My first foray with Brain-Flak, and I think I've done pretty well. Anyone with more experience have advice? ### How It Works: { Don't do anything if input is 0 <>((((()()())){}{})()) Switch to other stack and add 9 and 10 10 is the counter, 9 is to add to the current num { While counter ( {} Pop the counter <(({})<>({}))> Get a copy of the 9, switch to the other stack and add it to a copy of the top of it. Use <...> to make it return 0 <>[()] Switch to the other stack and decrement the counter ) } }<> Switch to the stack with the values on it  • Good job! Welcome to Brain-Flak. Jan 12, 2018 at 21:29 # Jelly, 12 bytes ȷ2ḶDS$ÐL⁼¥Ðf


Try it online!

# PHP, 35

print_r(range($argn,!!$argn*99,9));


Creates the range [$argn, 100) with a step of 9 as array and prints it. If the input is 0 it creates the range [0,0] => array(0). # Python, 48 51 bytes 3 bytes saved thanks to @WheatWizard lambda n:[x for x in range(100)if~-n==~-x%9or x==n]  • try ~-x instead of (x-1) May 29, 2017 at 1:51 • still with @WheatWizard's tip, remove the space in if ~-x%9 May 29, 2017 at 14:28 • Now you can do ~-n==~-x%9or x==n to save a byte May 29, 2017 at 14:39 • This gives a 0 for 9 Jan 12, 2018 at 0:49 • I need to ask a silly question... I'd like to run this. How do I get this code to run? There are some constructs here I'm learning about (mainly the ~ operator) Mar 3, 2018 at 3:30 # R, 23 bytes pryr::f(x+0:(10*!!x)*9)  Try it online! The TIO link uses function(x) instead of pryr::f, since TIO doesn't have the pryr package installed. ## Pyke, 6 bytes (old version) Working commit TXU#sq  Explanation: TX - 10**2 U - range(^) # - filter(^) s - digital_root(^) q - ^==input  # Ruby, 25 bytes ->a{[*a.step(99,9)]*a|[]}  Try it online! # C (gcc), 55 bytes f() need not actually be called with any argument; the n is just there instead of outside the function to save a byte. f(n){for(scanf("%d",&n);n&&n<100;n+=9)printf("%d ",n);}  Try it online! • You can save 2 bytes by putting the printf inside the loop header: Try it online! Jan 15, 2018 at 20:39 • @DLosc myeah, but then it starts one number too late. Jan 15, 2018 at 21:31 • The wording could be clearer, but the question does allow starting at (e.g.) 10 instead of 1: "... all of the possible two digit numbers that have that digital root. If you need it to, it can include [the single-digit number] itself, e.g. 05." In other words, including the single-digit number in the output is permitted but not required. Jan 16, 2018 at 3:55 # Charcoal, 14 11 bytes Ｉ∧Ｎ⁺Ｉθ×⁹…¹¹  Try it online! Link is to verbose version of code. Edit: Saved 2 bytes by not printing anything for zero input and 1 byte by using vectorising operations 3 bytes thanks to @ASCII-only. Explanation:  ¹¹ Literal 11 … Range ⁹ Literal 9 × Vector multiply θ (First) input Ｉ Cast to number ⁺ Vector add Ｎ Input digit as a number ∧ Logical AND Ｉ Cast to string Implicitly print on separate lines  • Feb 28, 2018 at 12:07 • i think i just found an alternative that prints 0, here Apr 6, 2018 at 10:45 # Pyt, 11 bytes ?56+ř⁻9*+:;  Try it online! ? implicit input; if input is truthy: 56+ push 11 ř⁻ řangify; decrement 9* multiply by 9 + add input :; otherwise, do nothing; implicit print  # VyxalH, 6 bytes ʁ'∑∑?=  Try it Online! Port of kalsowerus's 05AB1E answer. A port of Kip the Malamute's Pyt answer would be 8 bytes: :[11ʁ9*+  Try it Online! #### Explanation ʁ'∑∑?= # H flag pushes 100 ʁ' # Filter range(100) by: ∑∑ # Digit sum twice ?= # Equals the input  :[11ʁ9*+ # Implicit input : # Duplicate [ # If input is not 0: 11ʁ # Push range(11) 9* # Multiply by 9 + # Add to input # (Otherwise, do nothing)  • "Make sure that 1 does not return 100" Mar 2 at 11:45 • @DominicvanEssen fixed. That was just Vyxal implicitly converting 100 to a 1-based range instead of a 0-based range. Mar 2 at 11:58 # Julia 0.6, 18 bytes I use a ternary to catch the 0 case, and a range n:9:99 to create the numbers. In julia a range is an AbstractVector and can be used in place of an actual Vector of numbers in most cases, but it will just print as 1:9:91 which doesn't satisfy the challenge, so I wrap it in [_;] to collect the contents into a Vector. n->n>0?[n:9:99;]:0  Try it online! # Perl 5, 25 + 1 (-n) = 26 bytes say;!$_||(\$_+=9)>99||redo


Try it online!

Clojure, 33 bytes

(fn[n](if(> n 0)(range n 100 9)))


# Clojure, 38 bytes

(defn f[n](if(pos? n)(range n 100 9)))


or as anonymous function which is 29 bytes

(#(if(pos? %)(range % 100 9))n)


Try it online!

• The output when n=9 is missing the last number, 99. Try it online! Also, you can save a byte by removing the space between f[n] and (if(.... Jan 14, 2018 at 23:13