9
\$\begingroup\$

Given a positive number \$n\$ we call another (not same as n) positive number \$m\$ good if we insert same digits in both n and m and the resulting fractional value is same.

$$m/n = m_{\text{transformed}}/n_{\text{transformed}}$$ $$or$$ $$m*n_{\text{transformed}} = m_{\text{transformed}}*n$$

Clarifications:

  • No leading zeros or trailing zero insertion is allowed (you can insert 0 at beginning or end, but this must not be the last digit added in that end),other than this you can insert any digit(same digit and same number of time in both) at any place,i.e you need not insert at same place in n and m.

  • At least one insertion is required.

Examples :

Example 1: $$n= 12$$

here m=66 is a good number ,we can obtain it by inserting 1 in m and n such that they become 616 and 112.

Example 2:

$$n=30$$

here m=60 is a good number, we can get 300 and 600 by inserting 0 in middle, as mentioned we cannot insert 0 at end or beginning, but here we inserted it in middle.

Example 3:

$$n=4$$ here 7 is a good number, as we can insert 2 and 1 , making them 124 and 217 respectively, now the fractional value is same.

Example 4:

$$n=11$$ here 2 is a good number, as we can insert 2 and 2 , making them 1221 and 222 respectively, now the fractional value is same.

Example 5:

$$n=4269$$ here 1423 is a good number, as we can insert 0, making them 42069 and 14023 respectively, now the fractional value is same.

Example 6:

$$n=1331$$ here 242 is a good number, as we can insert 2 and 2, making them 123321 and 22422 respectively, now the fractional value is same.

Task:

You have to find out smallest good number for a given n (there always exists a good number as pointed out by a user in comments).

This is , so the shortest answer in bytes per language wins.

\$\endgroup\$
16
  • 9
    \$\begingroup\$ A solution must always exist. Given \$n\$ choose \$m=n\times 10\$, now insert a \$1\$ at the beginning of both numbers (or really do any insertion at the same place relative to the beginning of the number). \$\endgroup\$
    – Wheat Wizard
    Jun 7, 2021 at 11:30
  • 1
    \$\begingroup\$ Also, 3 is a valid solution for n=12: (12, 3) -> (132, 33), just helping you there \$\endgroup\$
    – user100690
    Jun 7, 2021 at 12:03
  • 5
    \$\begingroup\$ I'd suggest that you update your testcases such that they show the smallest possible number rather than the current ones which are not necessarily the shortest. \$\endgroup\$
    – user100690
    Jun 7, 2021 at 15:12
  • 1
    \$\begingroup\$ Also, when we insert 0s, sometimes the result is equivalent to adding 0s at the end, should this one not be allowed too ? For example, if we add two 0s in the middle of 10, we get 1000 which is equivalent to adding the 0s to the end \$\endgroup\$ Jun 7, 2021 at 20:59
  • 2
    \$\begingroup\$ @OldMan Maybe make it such that only 1 digit insertion is allowed? \$\endgroup\$
    – user100690
    Jun 13, 2021 at 8:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.