Multiply and Divide
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
Given a value x find the smallest numerical value greater than y that is capable of being multiplied and divided by x while retaining all original digits.
- The new numbers do not lose digits.
- The new numbers do not gain digits.
For example:
Input: x = 2, y = 250000
- Original: 285714
- Division: 142857
- Multiplication: 571428
This is true because 285714 is greater than y; then when divided by x results in 142857 and when multiplied by x results in 571428. In both tests all of the original digits from 285714 are present and no extra digits have been added.
The Rules
X has to be a value between 2 and 5.
X and Y are required to be whole numbers greater than zero.- The shortest code wins.
Good luck to you all!
code-golf number
add a comment |Â
up vote
4
down vote
favorite
Given a value x find the smallest numerical value greater than y that is capable of being multiplied and divided by x while retaining all original digits.
- The new numbers do not lose digits.
- The new numbers do not gain digits.
For example:
Input: x = 2, y = 250000
- Original: 285714
- Division: 142857
- Multiplication: 571428
This is true because 285714 is greater than y; then when divided by x results in 142857 and when multiplied by x results in 571428. In both tests all of the original digits from 285714 are present and no extra digits have been added.
The Rules
X has to be a value between 2 and 5.
X and Y are required to be whole numbers greater than zero.- The shortest code wins.
Good luck to you all!
code-golf number
Are digits counted with multiplicity? I.e., if x=11 and y=10, is 11 the answer? (11/11=1 which has the same digits as 11, but not with multiplicity). Also, is it ok if new digits appear when multiplying by x, as long as all the original digits are present?
â Delfad0r
1 hour ago
No digits are gained nor lost; and this has to be true for multiplication and division. In the case of x = 11 and y = 10 then 11 is not the answer; 11/11 = 1 and 11 * 11 = 121. Thus digits are lost and gained.
â PerpetualJ
1 hour ago
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
Given a value x find the smallest numerical value greater than y that is capable of being multiplied and divided by x while retaining all original digits.
- The new numbers do not lose digits.
- The new numbers do not gain digits.
For example:
Input: x = 2, y = 250000
- Original: 285714
- Division: 142857
- Multiplication: 571428
This is true because 285714 is greater than y; then when divided by x results in 142857 and when multiplied by x results in 571428. In both tests all of the original digits from 285714 are present and no extra digits have been added.
The Rules
X has to be a value between 2 and 5.
X and Y are required to be whole numbers greater than zero.- The shortest code wins.
Good luck to you all!
code-golf number
Given a value x find the smallest numerical value greater than y that is capable of being multiplied and divided by x while retaining all original digits.
- The new numbers do not lose digits.
- The new numbers do not gain digits.
For example:
Input: x = 2, y = 250000
- Original: 285714
- Division: 142857
- Multiplication: 571428
This is true because 285714 is greater than y; then when divided by x results in 142857 and when multiplied by x results in 571428. In both tests all of the original digits from 285714 are present and no extra digits have been added.
The Rules
X has to be a value between 2 and 5.
X and Y are required to be whole numbers greater than zero.- The shortest code wins.
Good luck to you all!
code-golf number
code-golf number
edited 1 hour ago
asked 1 hour ago
PerpetualJ
1315
1315
Are digits counted with multiplicity? I.e., if x=11 and y=10, is 11 the answer? (11/11=1 which has the same digits as 11, but not with multiplicity). Also, is it ok if new digits appear when multiplying by x, as long as all the original digits are present?
â Delfad0r
1 hour ago
No digits are gained nor lost; and this has to be true for multiplication and division. In the case of x = 11 and y = 10 then 11 is not the answer; 11/11 = 1 and 11 * 11 = 121. Thus digits are lost and gained.
â PerpetualJ
1 hour ago
add a comment |Â
Are digits counted with multiplicity? I.e., if x=11 and y=10, is 11 the answer? (11/11=1 which has the same digits as 11, but not with multiplicity). Also, is it ok if new digits appear when multiplying by x, as long as all the original digits are present?
â Delfad0r
1 hour ago
No digits are gained nor lost; and this has to be true for multiplication and division. In the case of x = 11 and y = 10 then 11 is not the answer; 11/11 = 1 and 11 * 11 = 121. Thus digits are lost and gained.
â PerpetualJ
1 hour ago
Are digits counted with multiplicity? I.e., if x=11 and y=10, is 11 the answer? (11/11=1 which has the same digits as 11, but not with multiplicity). Also, is it ok if new digits appear when multiplying by x, as long as all the original digits are present?
â Delfad0r
1 hour ago
Are digits counted with multiplicity? I.e., if x=11 and y=10, is 11 the answer? (11/11=1 which has the same digits as 11, but not with multiplicity). Also, is it ok if new digits appear when multiplying by x, as long as all the original digits are present?
â Delfad0r
1 hour ago
No digits are gained nor lost; and this has to be true for multiplication and division. In the case of x = 11 and y = 10 then 11 is not the answer; 11/11 = 1 and 11 * 11 = 121. Thus digits are lost and gained.
â PerpetualJ
1 hour ago
No digits are gained nor lost; and this has to be true for multiplication and division. In the case of x = 11 and y = 10 then 11 is not the answer; 11/11 = 1 and 11 * 11 = 121. Thus digits are lost and gained.
â PerpetualJ
1 hour ago
add a comment |Â
5 Answers
5
active
oldest
votes
up vote
2
down vote
Husk, 14 bytes
á¸Âçä=OoDdçä+d*/
Try it online!
Explanation
á¸Âçä=O(Dd)çä+d*/ -- example inputs: x=2 y=1
Ḡ-- find first value greater than y where the following is true (example on 285714)
ç -- | fork
ç -- | | fork
/ -- | | | divide by x: 142857
-- | | and
* -- | | | multiply by y: 571428
-- | | then do the following with 142857 and 571428
-- | | | concatenate but first take
+ -- | | | | digits: [1,4,2,8,5,7] [5,7,1,4,2,8]
ä d -- | | | : [1,4,2,8,5,7,5,7,1,4,2,8]
-- | and
d -- | | digits: [2,8,5,7,1,4]
D -- | | double: [2,8,5,7,1,4,2,8,5,7,1,4]
-- | then do the following with [2,8,5,7,1,4,2,8,5,7,1,4] and [1,4,2,8,5,7,5,7,1,4,2,8]
= -- | | are they equal
ä O -- | | | when sorted: [1,1,2,2,4,4,5,5,7,7,8,8] [1,1,2,2,4,4,5,5,7,7,8,8]
-- | : truthy
-- : 285714
I adjusted the value for y to get a closer starting point and the result was incorrect for x = 3, y = 25000000.
â PerpetualJ
1 hour ago
@PerpetualJ: If you know the result then you can simply adjust y, and this version should be slightly faster (only the type-checking though).
â BMO
1 hour ago
I've adjusted it after some thought and edited my first comment.
â PerpetualJ
1 hour ago
@PerpetualJ: I've fixed it: made an assumption about-
which was wrong.
â BMO
53 mins ago
That produced a correct result! :) I'm curious; how do you understand what's going on there by the way?
â PerpetualJ
47 mins ago
 |Â
show 1 more comment
up vote
1
down vote
Perl 6, 56 bytes
->x,yfirst [eqv] map *.comb.Bag,$_,$_*x,$_/x,y^..*
Try it online!
Interesting alternative, computing n*xk for k=-1,0,1:
->x,yfirst [eqv] map ($_*x***).comb.Bag,^3-1,y^..*
add a comment |Â
up vote
0
down vote
Japt, 22 bytes
Pretty naïve solution over a few beers; I'm sure there's a better way.
@[X*UX/U]îìnÃÂeöXìn}aðV
Try it
Unfortunately this produces an incorrect result when x = 3 and y = 25000.
â PerpetualJ
1 hour ago
add a comment |Â
up vote
0
down vote
Clean, 92 bytes
import StdEnv
$n m=hd[i\i<-[m..],[_]<-[removeDup[sort[c\c<-:toString j]\j<-[i,i/n,i*n]]]]
Try it online!
Pretty simple. Explanation coming in a while.
add a comment |Â
up vote
0
down vote
Jelly, 12 bytes
ÃÂ;÷;â¸Dá¹¢â¬Eð1#
A full program printing the result (as a dyadic link a list of length 1 is yielded).
Try it online!
How?
ÃÂ;÷;â¸Dá¹¢â¬Eð1# - Main link: y, x
# - count up from n=y, finding the first...
1 - ...1 match:
ð - using the dyad -- i.e. f(n, x): e.g. 285714, 2
ÃÂ - multiply -> nÃÂx 571428
÷ - divide -> n÷x 142857
; - concatenate -> [nÃÂx,n÷x] [571428,142857]
⸠- chain's left argument = n 285714
; - concatenate -> [nÃÂx,n÷x,n] [571428,142857,285714]
D - to decimal (vectorises) [[5,7,1,4,2,8],[1,4,2,8,5,7],[2,8,5,7,1,4]]
Ṣ⬠- sort â¬ach [[1,2,4,5,7,8],[1,2,4,5,7,8],[1,2,4,5,7,8]]
E - all equal? 1
Note that when the division is not exact the decimal instruction yields a fractional part
e.g.: 1800÷3D
-> [6,0,0]
while 1801÷3D
-> [6.0,0.0,0.33333333333337123]
add a comment |Â
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Husk, 14 bytes
á¸Âçä=OoDdçä+d*/
Try it online!
Explanation
á¸Âçä=O(Dd)çä+d*/ -- example inputs: x=2 y=1
Ḡ-- find first value greater than y where the following is true (example on 285714)
ç -- | fork
ç -- | | fork
/ -- | | | divide by x: 142857
-- | | and
* -- | | | multiply by y: 571428
-- | | then do the following with 142857 and 571428
-- | | | concatenate but first take
+ -- | | | | digits: [1,4,2,8,5,7] [5,7,1,4,2,8]
ä d -- | | | : [1,4,2,8,5,7,5,7,1,4,2,8]
-- | and
d -- | | digits: [2,8,5,7,1,4]
D -- | | double: [2,8,5,7,1,4,2,8,5,7,1,4]
-- | then do the following with [2,8,5,7,1,4,2,8,5,7,1,4] and [1,4,2,8,5,7,5,7,1,4,2,8]
= -- | | are they equal
ä O -- | | | when sorted: [1,1,2,2,4,4,5,5,7,7,8,8] [1,1,2,2,4,4,5,5,7,7,8,8]
-- | : truthy
-- : 285714
I adjusted the value for y to get a closer starting point and the result was incorrect for x = 3, y = 25000000.
â PerpetualJ
1 hour ago
@PerpetualJ: If you know the result then you can simply adjust y, and this version should be slightly faster (only the type-checking though).
â BMO
1 hour ago
I've adjusted it after some thought and edited my first comment.
â PerpetualJ
1 hour ago
@PerpetualJ: I've fixed it: made an assumption about-
which was wrong.
â BMO
53 mins ago
That produced a correct result! :) I'm curious; how do you understand what's going on there by the way?
â PerpetualJ
47 mins ago
 |Â
show 1 more comment
up vote
2
down vote
Husk, 14 bytes
á¸Âçä=OoDdçä+d*/
Try it online!
Explanation
á¸Âçä=O(Dd)çä+d*/ -- example inputs: x=2 y=1
Ḡ-- find first value greater than y where the following is true (example on 285714)
ç -- | fork
ç -- | | fork
/ -- | | | divide by x: 142857
-- | | and
* -- | | | multiply by y: 571428
-- | | then do the following with 142857 and 571428
-- | | | concatenate but first take
+ -- | | | | digits: [1,4,2,8,5,7] [5,7,1,4,2,8]
ä d -- | | | : [1,4,2,8,5,7,5,7,1,4,2,8]
-- | and
d -- | | digits: [2,8,5,7,1,4]
D -- | | double: [2,8,5,7,1,4,2,8,5,7,1,4]
-- | then do the following with [2,8,5,7,1,4,2,8,5,7,1,4] and [1,4,2,8,5,7,5,7,1,4,2,8]
= -- | | are they equal
ä O -- | | | when sorted: [1,1,2,2,4,4,5,5,7,7,8,8] [1,1,2,2,4,4,5,5,7,7,8,8]
-- | : truthy
-- : 285714
I adjusted the value for y to get a closer starting point and the result was incorrect for x = 3, y = 25000000.
â PerpetualJ
1 hour ago
@PerpetualJ: If you know the result then you can simply adjust y, and this version should be slightly faster (only the type-checking though).
â BMO
1 hour ago
I've adjusted it after some thought and edited my first comment.
â PerpetualJ
1 hour ago
@PerpetualJ: I've fixed it: made an assumption about-
which was wrong.
â BMO
53 mins ago
That produced a correct result! :) I'm curious; how do you understand what's going on there by the way?
â PerpetualJ
47 mins ago
 |Â
show 1 more comment
up vote
2
down vote
up vote
2
down vote
Husk, 14 bytes
á¸Âçä=OoDdçä+d*/
Try it online!
Explanation
á¸Âçä=O(Dd)çä+d*/ -- example inputs: x=2 y=1
Ḡ-- find first value greater than y where the following is true (example on 285714)
ç -- | fork
ç -- | | fork
/ -- | | | divide by x: 142857
-- | | and
* -- | | | multiply by y: 571428
-- | | then do the following with 142857 and 571428
-- | | | concatenate but first take
+ -- | | | | digits: [1,4,2,8,5,7] [5,7,1,4,2,8]
ä d -- | | | : [1,4,2,8,5,7,5,7,1,4,2,8]
-- | and
d -- | | digits: [2,8,5,7,1,4]
D -- | | double: [2,8,5,7,1,4,2,8,5,7,1,4]
-- | then do the following with [2,8,5,7,1,4,2,8,5,7,1,4] and [1,4,2,8,5,7,5,7,1,4,2,8]
= -- | | are they equal
ä O -- | | | when sorted: [1,1,2,2,4,4,5,5,7,7,8,8] [1,1,2,2,4,4,5,5,7,7,8,8]
-- | : truthy
-- : 285714
Husk, 14 bytes
á¸Âçä=OoDdçä+d*/
Try it online!
Explanation
á¸Âçä=O(Dd)çä+d*/ -- example inputs: x=2 y=1
Ḡ-- find first value greater than y where the following is true (example on 285714)
ç -- | fork
ç -- | | fork
/ -- | | | divide by x: 142857
-- | | and
* -- | | | multiply by y: 571428
-- | | then do the following with 142857 and 571428
-- | | | concatenate but first take
+ -- | | | | digits: [1,4,2,8,5,7] [5,7,1,4,2,8]
ä d -- | | | : [1,4,2,8,5,7,5,7,1,4,2,8]
-- | and
d -- | | digits: [2,8,5,7,1,4]
D -- | | double: [2,8,5,7,1,4,2,8,5,7,1,4]
-- | then do the following with [2,8,5,7,1,4,2,8,5,7,1,4] and [1,4,2,8,5,7,5,7,1,4,2,8]
= -- | | are they equal
ä O -- | | | when sorted: [1,1,2,2,4,4,5,5,7,7,8,8] [1,1,2,2,4,4,5,5,7,7,8,8]
-- | : truthy
-- : 285714
edited 42 mins ago
answered 1 hour ago
BMO
9,74411773
9,74411773
I adjusted the value for y to get a closer starting point and the result was incorrect for x = 3, y = 25000000.
â PerpetualJ
1 hour ago
@PerpetualJ: If you know the result then you can simply adjust y, and this version should be slightly faster (only the type-checking though).
â BMO
1 hour ago
I've adjusted it after some thought and edited my first comment.
â PerpetualJ
1 hour ago
@PerpetualJ: I've fixed it: made an assumption about-
which was wrong.
â BMO
53 mins ago
That produced a correct result! :) I'm curious; how do you understand what's going on there by the way?
â PerpetualJ
47 mins ago
 |Â
show 1 more comment
I adjusted the value for y to get a closer starting point and the result was incorrect for x = 3, y = 25000000.
â PerpetualJ
1 hour ago
@PerpetualJ: If you know the result then you can simply adjust y, and this version should be slightly faster (only the type-checking though).
â BMO
1 hour ago
I've adjusted it after some thought and edited my first comment.
â PerpetualJ
1 hour ago
@PerpetualJ: I've fixed it: made an assumption about-
which was wrong.
â BMO
53 mins ago
That produced a correct result! :) I'm curious; how do you understand what's going on there by the way?
â PerpetualJ
47 mins ago
I adjusted the value for y to get a closer starting point and the result was incorrect for x = 3, y = 25000000.
â PerpetualJ
1 hour ago
I adjusted the value for y to get a closer starting point and the result was incorrect for x = 3, y = 25000000.
â PerpetualJ
1 hour ago
@PerpetualJ: If you know the result then you can simply adjust y, and this version should be slightly faster (only the type-checking though).
â BMO
1 hour ago
@PerpetualJ: If you know the result then you can simply adjust y, and this version should be slightly faster (only the type-checking though).
â BMO
1 hour ago
I've adjusted it after some thought and edited my first comment.
â PerpetualJ
1 hour ago
I've adjusted it after some thought and edited my first comment.
â PerpetualJ
1 hour ago
@PerpetualJ: I've fixed it: made an assumption about
-
which was wrong.â BMO
53 mins ago
@PerpetualJ: I've fixed it: made an assumption about
-
which was wrong.â BMO
53 mins ago
That produced a correct result! :) I'm curious; how do you understand what's going on there by the way?
â PerpetualJ
47 mins ago
That produced a correct result! :) I'm curious; how do you understand what's going on there by the way?
â PerpetualJ
47 mins ago
 |Â
show 1 more comment
up vote
1
down vote
Perl 6, 56 bytes
->x,yfirst [eqv] map *.comb.Bag,$_,$_*x,$_/x,y^..*
Try it online!
Interesting alternative, computing n*xk for k=-1,0,1:
->x,yfirst [eqv] map ($_*x***).comb.Bag,^3-1,y^..*
add a comment |Â
up vote
1
down vote
Perl 6, 56 bytes
->x,yfirst [eqv] map *.comb.Bag,$_,$_*x,$_/x,y^..*
Try it online!
Interesting alternative, computing n*xk for k=-1,0,1:
->x,yfirst [eqv] map ($_*x***).comb.Bag,^3-1,y^..*
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Perl 6, 56 bytes
->x,yfirst [eqv] map *.comb.Bag,$_,$_*x,$_/x,y^..*
Try it online!
Interesting alternative, computing n*xk for k=-1,0,1:
->x,yfirst [eqv] map ($_*x***).comb.Bag,^3-1,y^..*
Perl 6, 56 bytes
->x,yfirst [eqv] map *.comb.Bag,$_,$_*x,$_/x,y^..*
Try it online!
Interesting alternative, computing n*xk for k=-1,0,1:
->x,yfirst [eqv] map ($_*x***).comb.Bag,^3-1,y^..*
edited 10 mins ago
answered 28 mins ago
nwellnhof
3,833715
3,833715
add a comment |Â
add a comment |Â
up vote
0
down vote
Japt, 22 bytes
Pretty naïve solution over a few beers; I'm sure there's a better way.
@[X*UX/U]îìnÃÂeöXìn}aðV
Try it
Unfortunately this produces an incorrect result when x = 3 and y = 25000.
â PerpetualJ
1 hour ago
add a comment |Â
up vote
0
down vote
Japt, 22 bytes
Pretty naïve solution over a few beers; I'm sure there's a better way.
@[X*UX/U]îìnÃÂeöXìn}aðV
Try it
Unfortunately this produces an incorrect result when x = 3 and y = 25000.
â PerpetualJ
1 hour ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Japt, 22 bytes
Pretty naïve solution over a few beers; I'm sure there's a better way.
@[X*UX/U]îìnÃÂeöXìn}aðV
Try it
Japt, 22 bytes
Pretty naïve solution over a few beers; I'm sure there's a better way.
@[X*UX/U]îìnÃÂeöXìn}aðV
Try it
answered 1 hour ago
Shaggy
16.9k21661
16.9k21661
Unfortunately this produces an incorrect result when x = 3 and y = 25000.
â PerpetualJ
1 hour ago
add a comment |Â
Unfortunately this produces an incorrect result when x = 3 and y = 25000.
â PerpetualJ
1 hour ago
Unfortunately this produces an incorrect result when x = 3 and y = 25000.
â PerpetualJ
1 hour ago
Unfortunately this produces an incorrect result when x = 3 and y = 25000.
â PerpetualJ
1 hour ago
add a comment |Â
up vote
0
down vote
Clean, 92 bytes
import StdEnv
$n m=hd[i\i<-[m..],[_]<-[removeDup[sort[c\c<-:toString j]\j<-[i,i/n,i*n]]]]
Try it online!
Pretty simple. Explanation coming in a while.
add a comment |Â
up vote
0
down vote
Clean, 92 bytes
import StdEnv
$n m=hd[i\i<-[m..],[_]<-[removeDup[sort[c\c<-:toString j]\j<-[i,i/n,i*n]]]]
Try it online!
Pretty simple. Explanation coming in a while.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Clean, 92 bytes
import StdEnv
$n m=hd[i\i<-[m..],[_]<-[removeDup[sort[c\c<-:toString j]\j<-[i,i/n,i*n]]]]
Try it online!
Pretty simple. Explanation coming in a while.
Clean, 92 bytes
import StdEnv
$n m=hd[i\i<-[m..],[_]<-[removeDup[sort[c\c<-:toString j]\j<-[i,i/n,i*n]]]]
Try it online!
Pretty simple. Explanation coming in a while.
answered 29 mins ago
ÃÂurous
5,33311031
5,33311031
add a comment |Â
add a comment |Â
up vote
0
down vote
Jelly, 12 bytes
ÃÂ;÷;â¸Dá¹¢â¬Eð1#
A full program printing the result (as a dyadic link a list of length 1 is yielded).
Try it online!
How?
ÃÂ;÷;â¸Dá¹¢â¬Eð1# - Main link: y, x
# - count up from n=y, finding the first...
1 - ...1 match:
ð - using the dyad -- i.e. f(n, x): e.g. 285714, 2
ÃÂ - multiply -> nÃÂx 571428
÷ - divide -> n÷x 142857
; - concatenate -> [nÃÂx,n÷x] [571428,142857]
⸠- chain's left argument = n 285714
; - concatenate -> [nÃÂx,n÷x,n] [571428,142857,285714]
D - to decimal (vectorises) [[5,7,1,4,2,8],[1,4,2,8,5,7],[2,8,5,7,1,4]]
Ṣ⬠- sort â¬ach [[1,2,4,5,7,8],[1,2,4,5,7,8],[1,2,4,5,7,8]]
E - all equal? 1
Note that when the division is not exact the decimal instruction yields a fractional part
e.g.: 1800÷3D
-> [6,0,0]
while 1801÷3D
-> [6.0,0.0,0.33333333333337123]
add a comment |Â
up vote
0
down vote
Jelly, 12 bytes
ÃÂ;÷;â¸Dá¹¢â¬Eð1#
A full program printing the result (as a dyadic link a list of length 1 is yielded).
Try it online!
How?
ÃÂ;÷;â¸Dá¹¢â¬Eð1# - Main link: y, x
# - count up from n=y, finding the first...
1 - ...1 match:
ð - using the dyad -- i.e. f(n, x): e.g. 285714, 2
ÃÂ - multiply -> nÃÂx 571428
÷ - divide -> n÷x 142857
; - concatenate -> [nÃÂx,n÷x] [571428,142857]
⸠- chain's left argument = n 285714
; - concatenate -> [nÃÂx,n÷x,n] [571428,142857,285714]
D - to decimal (vectorises) [[5,7,1,4,2,8],[1,4,2,8,5,7],[2,8,5,7,1,4]]
Ṣ⬠- sort â¬ach [[1,2,4,5,7,8],[1,2,4,5,7,8],[1,2,4,5,7,8]]
E - all equal? 1
Note that when the division is not exact the decimal instruction yields a fractional part
e.g.: 1800÷3D
-> [6,0,0]
while 1801÷3D
-> [6.0,0.0,0.33333333333337123]
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Jelly, 12 bytes
ÃÂ;÷;â¸Dá¹¢â¬Eð1#
A full program printing the result (as a dyadic link a list of length 1 is yielded).
Try it online!
How?
ÃÂ;÷;â¸Dá¹¢â¬Eð1# - Main link: y, x
# - count up from n=y, finding the first...
1 - ...1 match:
ð - using the dyad -- i.e. f(n, x): e.g. 285714, 2
ÃÂ - multiply -> nÃÂx 571428
÷ - divide -> n÷x 142857
; - concatenate -> [nÃÂx,n÷x] [571428,142857]
⸠- chain's left argument = n 285714
; - concatenate -> [nÃÂx,n÷x,n] [571428,142857,285714]
D - to decimal (vectorises) [[5,7,1,4,2,8],[1,4,2,8,5,7],[2,8,5,7,1,4]]
Ṣ⬠- sort â¬ach [[1,2,4,5,7,8],[1,2,4,5,7,8],[1,2,4,5,7,8]]
E - all equal? 1
Note that when the division is not exact the decimal instruction yields a fractional part
e.g.: 1800÷3D
-> [6,0,0]
while 1801÷3D
-> [6.0,0.0,0.33333333333337123]
Jelly, 12 bytes
ÃÂ;÷;â¸Dá¹¢â¬Eð1#
A full program printing the result (as a dyadic link a list of length 1 is yielded).
Try it online!
How?
ÃÂ;÷;â¸Dá¹¢â¬Eð1# - Main link: y, x
# - count up from n=y, finding the first...
1 - ...1 match:
ð - using the dyad -- i.e. f(n, x): e.g. 285714, 2
ÃÂ - multiply -> nÃÂx 571428
÷ - divide -> n÷x 142857
; - concatenate -> [nÃÂx,n÷x] [571428,142857]
⸠- chain's left argument = n 285714
; - concatenate -> [nÃÂx,n÷x,n] [571428,142857,285714]
D - to decimal (vectorises) [[5,7,1,4,2,8],[1,4,2,8,5,7],[2,8,5,7,1,4]]
Ṣ⬠- sort â¬ach [[1,2,4,5,7,8],[1,2,4,5,7,8],[1,2,4,5,7,8]]
E - all equal? 1
Note that when the division is not exact the decimal instruction yields a fractional part
e.g.: 1800÷3D
-> [6,0,0]
while 1801÷3D
-> [6.0,0.0,0.33333333333337123]
edited 17 mins ago
answered 36 mins ago
Jonathan Allan
48.6k534159
48.6k534159
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f172958%2fmultiply-and-divide%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Are digits counted with multiplicity? I.e., if x=11 and y=10, is 11 the answer? (11/11=1 which has the same digits as 11, but not with multiplicity). Also, is it ok if new digits appear when multiplying by x, as long as all the original digits are present?
â Delfad0r
1 hour ago
No digits are gained nor lost; and this has to be true for multiplication and division. In the case of x = 11 and y = 10 then 11 is not the answer; 11/11 = 1 and 11 * 11 = 121. Thus digits are lost and gained.
â PerpetualJ
1 hour ago