36
\$\begingroup\$

It's all in the title...

Take as input a positive integer n>=12 and... do what the title says.

Yes, this is on OEIS A187924.

Some test cases

12 -> 912  
13 -> 11713  
14 -> 6314  
15 -> 915  
16 -> 3616  
17 -> 15317  
18 -> 918  
19 -> 17119 
20 -> 9920  
40 -> 1999840   
100-> 99999999999100

This is . Shortest code in bytes wins!

\$\endgroup\$
2
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$ Dec 9, 2017 at 14:12
  • 1
    \$\begingroup\$ To close up a part of what was moved to chat: my edit to the OEIS proving that 11 is the only number without a solution was just approved. \$\endgroup\$ Jan 21, 2018 at 4:55

33 Answers 33

1
2
0
\$\begingroup\$

Javascript, 224 bytes function getNumber(x){if(x<12){return!1};const sumDigits=(x)=>x.toString().split('').map(Number).reduce((a,b)=>a+b,0);for(let i=2;i<9999;i++){if((x*i-x)%(Math.pow(10,x.toString().length))==0&&sumDigits(x*i)==x){return x*i}}} Un-golf:

function getNumber(x){
	if (x<12) {return false};
	const sumDigits = (x) => x.toString().split('').map(Number).reduce((a,b)=>a+b, 0);
	for (let i=2; i<9999; i++){
		if((x*i-x)%(Math.pow(10, x.toString().length))==0 && sumDigits(x*i)==x){
			return x*i;
}
}
}

Usage: 1. getNumber(12) 2. getNumber(13) 3. ....

\$\endgroup\$
2
  • \$\begingroup\$ I don't know much about Javascript golfing, but I'm pretty sure you should shorten the names getNumber or sumDigits. \$\endgroup\$ Dec 4, 2017 at 9:45
  • \$\begingroup\$ Thank you so much, I am not go to win here, just want to get into this challenge :smile: \$\endgroup\$
    – NTCG
    Dec 7, 2017 at 4:35
0
\$\begingroup\$

J, 37 33 bytes

+^:(((=1#."."0)*:(e.".\.))":)^:_~

Try it online!

                                ~    A = N
+^:                          ^:_     while(...)A+=N; return A
   (                      ":)        A to string
   (((    "."0)          )  )        digits of A
   ((( 1#.    )          )  )        sum
   (((=       )          )  )        equals N
   ((            (e.".\.))  )        N is one of the suffixes of A-string
   ((          *:        )  )        not AND

Prepending the iteration counter is ~5 times faster but 5 bytes longer:

(]+[((=1#.,.&.":)<:|),~&.":)^:_&1,&":]

Try it online!

Incrementing by 100, 27 bytes:

(]+100*(=1#.,.&.":)<:|)^:_~

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Vyxal, 89 bitsv2, 11.125 bytes

Þ∞vp:Ṡ?=*ꜝ‡?Ḋc

Try it Online!

Explained

Þ∞vp:Ṡ?=*ꜝ‡?Ḋc­⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏⁠‎⁡⁠⁣‏⁠‎⁡⁠⁤‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏⁠⁠‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢⁣‏⁠‎⁡⁠⁢⁤‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁣⁡‏⁠‎⁡⁠⁣⁢‏‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁣⁣‏⁠‎⁡⁠⁣⁤‏⁠‎⁡⁠⁤⁡‏⁠‎⁡⁠⁤⁢‏‏​⁡⁠⁡‌­
Þ∞vp            # ‎⁡Append the input to each and every positive integer.
    :Ṡ          # ‎⁢and push a copy of that with each number summed
      ?=        # ‎⁣does each copy equal the input
        *ꜝ      # ‎⁤Multiply the two lists and keep only truthy items
          ‡?Ḋc  # ‎⁢⁡Find the first of that where the number is divisible by the input.
💎

Created with the help of Luminespire.

\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.