Multiply and Divide [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
9
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 should be 2 or 3 as anything higher takes too long to calculate.


  • Y is required to be a whole number greater than zero.

  • The shortest code wins.


Test Cases



These are my most common test cases as they are the quickest to test for.



  • x = 2, y = 250000 = 285714

  • x = 2, y = 290000 = 2589714

  • x = 2, y = 3000000 = 20978514

  • x = 3, y = 31000000 = 31046895

  • x = 3, y = 290000000 = 301046895


Clarifications



  • The type of division doesn't matter. If you can get 2.05, 0.25, and 5.20 somehow then feel free.


Good luck to you all!










share|improve this question















closed as unclear what you're asking by Erik the Outgolfer, user202729, iBug, Keeta, Stephen Sep 28 at 13:00


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 4




    "X has to be a value between 2 and 5." - if X>=4, the number multiplied by X will be at least 16 times larger than the number divided by X, so surely it will have more digits
    – ngn
    Sep 27 at 23:25







  • 2




    x can't be anything other than 2 or 3 since the product is x^2 times the quotient and both should have same number of digits. x = 1 will be a trivial case. IMO, there's no solution for x = 3 for any y though I might be wrong.
    – Jatin Sanghvi
    Sep 27 at 23:27






  • 2




    Is division float or integer division?
    – Erik the Outgolfer
    Sep 28 at 9:21






  • 3




    Test cases would be great
    – Stephen
    Sep 28 at 13:00






  • 3




    I suspect I'm not the only person who is refraining from voting to reopen because the clarification actually makes the challenge more ambiguous, because the correct answer could change dependently on whether floating point output is considered or not. I suspect @EriktheOutgolfer 's question was not asking about allowing floating point output, but about whether it's permitted to use truncating integer division. (And I'm sorry if my comments added to the confusion.)
    – Ørjan Johansen
    Sep 29 at 19:43















up vote
9
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 should be 2 or 3 as anything higher takes too long to calculate.


  • Y is required to be a whole number greater than zero.

  • The shortest code wins.


Test Cases



These are my most common test cases as they are the quickest to test for.



  • x = 2, y = 250000 = 285714

  • x = 2, y = 290000 = 2589714

  • x = 2, y = 3000000 = 20978514

  • x = 3, y = 31000000 = 31046895

  • x = 3, y = 290000000 = 301046895


Clarifications



  • The type of division doesn't matter. If you can get 2.05, 0.25, and 5.20 somehow then feel free.


Good luck to you all!










share|improve this question















closed as unclear what you're asking by Erik the Outgolfer, user202729, iBug, Keeta, Stephen Sep 28 at 13:00


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 4




    "X has to be a value between 2 and 5." - if X>=4, the number multiplied by X will be at least 16 times larger than the number divided by X, so surely it will have more digits
    – ngn
    Sep 27 at 23:25







  • 2




    x can't be anything other than 2 or 3 since the product is x^2 times the quotient and both should have same number of digits. x = 1 will be a trivial case. IMO, there's no solution for x = 3 for any y though I might be wrong.
    – Jatin Sanghvi
    Sep 27 at 23:27






  • 2




    Is division float or integer division?
    – Erik the Outgolfer
    Sep 28 at 9:21






  • 3




    Test cases would be great
    – Stephen
    Sep 28 at 13:00






  • 3




    I suspect I'm not the only person who is refraining from voting to reopen because the clarification actually makes the challenge more ambiguous, because the correct answer could change dependently on whether floating point output is considered or not. I suspect @EriktheOutgolfer 's question was not asking about allowing floating point output, but about whether it's permitted to use truncating integer division. (And I'm sorry if my comments added to the confusion.)
    – Ørjan Johansen
    Sep 29 at 19:43













up vote
9
down vote

favorite









up vote
9
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 should be 2 or 3 as anything higher takes too long to calculate.


  • Y is required to be a whole number greater than zero.

  • The shortest code wins.


Test Cases



These are my most common test cases as they are the quickest to test for.



  • x = 2, y = 250000 = 285714

  • x = 2, y = 290000 = 2589714

  • x = 2, y = 3000000 = 20978514

  • x = 3, y = 31000000 = 31046895

  • x = 3, y = 290000000 = 301046895


Clarifications



  • The type of division doesn't matter. If you can get 2.05, 0.25, and 5.20 somehow then feel free.


Good luck to you all!










share|improve this question















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 should be 2 or 3 as anything higher takes too long to calculate.


  • Y is required to be a whole number greater than zero.

  • The shortest code wins.


Test Cases



These are my most common test cases as they are the quickest to test for.



  • x = 2, y = 250000 = 285714

  • x = 2, y = 290000 = 2589714

  • x = 2, y = 3000000 = 20978514

  • x = 3, y = 31000000 = 31046895

  • x = 3, y = 290000000 = 301046895


Clarifications



  • The type of division doesn't matter. If you can get 2.05, 0.25, and 5.20 somehow then feel free.


Good luck to you all!







code-golf number






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 28 at 15:09

























asked Sep 27 at 20:44









PerpetualJ

1617




1617




closed as unclear what you're asking by Erik the Outgolfer, user202729, iBug, Keeta, Stephen Sep 28 at 13:00


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by Erik the Outgolfer, user202729, iBug, Keeta, Stephen Sep 28 at 13:00


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 4




    "X has to be a value between 2 and 5." - if X>=4, the number multiplied by X will be at least 16 times larger than the number divided by X, so surely it will have more digits
    – ngn
    Sep 27 at 23:25







  • 2




    x can't be anything other than 2 or 3 since the product is x^2 times the quotient and both should have same number of digits. x = 1 will be a trivial case. IMO, there's no solution for x = 3 for any y though I might be wrong.
    – Jatin Sanghvi
    Sep 27 at 23:27






  • 2




    Is division float or integer division?
    – Erik the Outgolfer
    Sep 28 at 9:21






  • 3




    Test cases would be great
    – Stephen
    Sep 28 at 13:00






  • 3




    I suspect I'm not the only person who is refraining from voting to reopen because the clarification actually makes the challenge more ambiguous, because the correct answer could change dependently on whether floating point output is considered or not. I suspect @EriktheOutgolfer 's question was not asking about allowing floating point output, but about whether it's permitted to use truncating integer division. (And I'm sorry if my comments added to the confusion.)
    – Ørjan Johansen
    Sep 29 at 19:43













  • 4




    "X has to be a value between 2 and 5." - if X>=4, the number multiplied by X will be at least 16 times larger than the number divided by X, so surely it will have more digits
    – ngn
    Sep 27 at 23:25







  • 2




    x can't be anything other than 2 or 3 since the product is x^2 times the quotient and both should have same number of digits. x = 1 will be a trivial case. IMO, there's no solution for x = 3 for any y though I might be wrong.
    – Jatin Sanghvi
    Sep 27 at 23:27






  • 2




    Is division float or integer division?
    – Erik the Outgolfer
    Sep 28 at 9:21






  • 3




    Test cases would be great
    – Stephen
    Sep 28 at 13:00






  • 3




    I suspect I'm not the only person who is refraining from voting to reopen because the clarification actually makes the challenge more ambiguous, because the correct answer could change dependently on whether floating point output is considered or not. I suspect @EriktheOutgolfer 's question was not asking about allowing floating point output, but about whether it's permitted to use truncating integer division. (And I'm sorry if my comments added to the confusion.)
    – Ørjan Johansen
    Sep 29 at 19:43








4




4




"X has to be a value between 2 and 5." - if X>=4, the number multiplied by X will be at least 16 times larger than the number divided by X, so surely it will have more digits
– ngn
Sep 27 at 23:25





"X has to be a value between 2 and 5." - if X>=4, the number multiplied by X will be at least 16 times larger than the number divided by X, so surely it will have more digits
– ngn
Sep 27 at 23:25





2




2




x can't be anything other than 2 or 3 since the product is x^2 times the quotient and both should have same number of digits. x = 1 will be a trivial case. IMO, there's no solution for x = 3 for any y though I might be wrong.
– Jatin Sanghvi
Sep 27 at 23:27




x can't be anything other than 2 or 3 since the product is x^2 times the quotient and both should have same number of digits. x = 1 will be a trivial case. IMO, there's no solution for x = 3 for any y though I might be wrong.
– Jatin Sanghvi
Sep 27 at 23:27




2




2




Is division float or integer division?
– Erik the Outgolfer
Sep 28 at 9:21




Is division float or integer division?
– Erik the Outgolfer
Sep 28 at 9:21




3




3




Test cases would be great
– Stephen
Sep 28 at 13:00




Test cases would be great
– Stephen
Sep 28 at 13:00




3




3




I suspect I'm not the only person who is refraining from voting to reopen because the clarification actually makes the challenge more ambiguous, because the correct answer could change dependently on whether floating point output is considered or not. I suspect @EriktheOutgolfer 's question was not asking about allowing floating point output, but about whether it's permitted to use truncating integer division. (And I'm sorry if my comments added to the confusion.)
– Ørjan Johansen
Sep 29 at 19:43





I suspect I'm not the only person who is refraining from voting to reopen because the clarification actually makes the challenge more ambiguous, because the correct answer could change dependently on whether floating point output is considered or not. I suspect @EriktheOutgolfer 's question was not asking about allowing floating point output, but about whether it's permitted to use truncating integer division. (And I'm sorry if my comments added to the confusion.)
– Ørjan Johansen
Sep 29 at 19:43











10 Answers
10






active

oldest

votes

















up vote
4
down vote



accepted











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





share|improve this answer






















  • I adjusted the value for y to get a closer starting point and the result was incorrect for x = 3, y = 25000000.
    – PerpetualJ
    Sep 27 at 21:28











  • @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
    Sep 27 at 21:30










  • I've adjusted it after some thought and edited my first comment.
    – PerpetualJ
    Sep 27 at 21:32










  • @PerpetualJ: I've fixed it: made an assumption about - which was wrong.
    – BMO
    Sep 27 at 21:45






  • 1




    @PerpetualJ: I wrote the program ;) I added an explanation, now everybody should understand what's going on.
    – BMO
    Sep 27 at 21:59

















up vote
4
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^..*





share|improve this answer





























    up vote
    4
    down vote














    Brachylog v2, 15 bytes



    t<.g,?kA/p.∧A×p


    Try it online!



    Takes input in the form [x,y].



    Explanation



    t<.g,?kA/p.∧A×p
    t Tail (extract y from the input)
    < Brute-force search for a number > y, such that:
    . it's the output to the user (called ".");
    g forming it into a list,
    ,? appending both inputs (to form [.,x,y]),
    k and removing the last (to form [.,x])
    A gives a value called A, such that:
    / first ÷ second element of A
    p is a permutation of
    . .
    ∧ and
    A× first × second element of A
    p is a permutation of .


    Commentary



    Brachylog's weakness at reusing multiple values multiple times shows up here; this program is almost all plumbing and very little algorithm.



    As such, it might seem more convenient to simply hardcode the value of y (there's a comment on this question hypothesising that 2 is the only possible value). However, there are in fact solutions for y=3, meaning that unfortunately, the plumbing has to handle the value of y as well. The smallest that I'm aware of is the following:



     315789473684210526
    315789473684210526 × 3 = 947368421052631578
    315789473684210526 ÷ 3 = 105263157894736842


    (The technique I used to find this number isn't fully general, so it's possible that there's a smaller solution using some other approach.)



    You're unlikely to verify that with this program, though. Brachylog's p is written in a very general way that doesn't have optimisations for special cases (such as the case where both the input and output are already known, meaning that you can do the verification in O(n log n) via sorting, rather than the O(n!) for the brute-force approach that I suspect it's using). As a consequence, it takes a very long time to verify that 105263157894736842 is a permutation of 315789473684210526 (I've been leaving it running for several minutes now with no obvious progress).



    (EDIT: I checked the Brachylog source for the reason. It turns out that if you use p on two known integers, the algorithm used generates all possible permutations of the integer in question until it finds one that's equal to the output integer, as the algorithm is "input → indigits, permute indigits → outdigits, outdigits → output". A more efficient algorithm would be to set up the outdigits/output relationship first, so that the backtracking within the permutation could take into account which digits were available.)






    share|improve this answer






















    • Using a fork can decrease your code by 1 byte. Try it online!
      – Kroppeb
      Sep 28 at 9:20










    • Also according to the docs, it seems checking if two known lists are a permutation is O(n²) swi-prolog.org/pldoc/man?predicate=permutation/2
      – Kroppeb
      Sep 28 at 9:24

















    up vote
    3
    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.






    share|improve this answer



























      up vote
      3
      down vote













      q, 65 bytes



      f:asc 10 vs x;while[not((f y)~f y*x)&(f y*x)~f"i"$y%x;y+:1];y


      Split number on base 10, sort each ascending, and check if equal. If not, increment y and go again






      share|improve this answer



























        up vote
        2
        down vote













        Japt, 24 bytes



        Pretty naïve solution over a few beers; I'm sure there's a better way.



        @[X*UX/U]®ì nÃeeXì n}a°V


        Try it






        share|improve this answer






















        • Unfortunately this produces an incorrect result when x = 3 and y = 25000.
          – PerpetualJ
          Sep 27 at 21:30










        • @PerpetualJ Assuming 315789473684210526 is the first solution for x=3, Javascript or Japt can't compute it correctly since it doesn't fit in double precision.
          – Bubbler
          Sep 28 at 4:38










        • @PerpetualJ, fixed that earlier. That test case will never complete, though, for the reason Bubbler mentioned above.
          – Shaggy
          Sep 28 at 10:13










        • @Shaggy This now produces a correct result and the solution that Bubbler pointed at is not the first correct result above 25000. See my test cases if you're curious on that. +1
          – PerpetualJ
          Sep 28 at 15:17

















        up vote
        2
        down vote













        JavaScript (ES6), 76 73 69 bytes



        Saved 3 bytes by using eval(), as suggested by @ShieruAsakoto



        Takes input as (x)(y).





        x=>y=>eval("for(;(g=x=>r=[...x+''].sort())(y*x)+g(y/x)!=g(y)+r;)++y")


        Try it online!



        A recursive version would be 62 bytes, but it's not well suited here because of the high number of required iterations.



        How?



        The helper function $g$ takes an integer as input, converts it to an array of digit characters and sorts this array.



        Example:



        g(285714) = [ '1', '2', '4', '5', '7', '8' ]


        To compare the digits of $ytimes x$ and those of $y/x$ against those of $y$, we test whether the concatenation of $g(ytimes x)$ with $g(y/x)$ is equal to the concatenation of $g(y)$ with itself.



        When adding two arrays together, each of them is implicitly coerced to a comma-separated string. The last digit of the first array is going to be directly concatenated with the first digit of the second array with no comma between them, which makes this format unambiguous.



        Example:



        g(123) + g(456) = [ '1', '2', '3' ] + [ '4', '5', '6' ] = '1,2,34,5,6'


        But:



        g(1234) + g(56) = [ '1', '2', '3', '4' ] + [ '5', '6' ] = '1,2,3,45,6'


        Commented



        x => y => // given x and y
        eval( // evaluate as JS code:
        "for(;" + // loop:
        "(g = x =>" + // g = helper function taking x
        "r =" + // the result will be eventually saved in r
        "[...x + '']" + // coerce x to a string and split it
        ".sort() + ''" + // sort the digits and coerce them back to a string
        ")(y * x) +" + // compute g(y * x)
        "g(y / x) !=" + // concatenate it with g(y / x)
        "g(y) + r;" + // loop while it's not equal to g(y) concatenated with
        ")" + // itself
        "++y" // increment y after each iteration
        ) // end of eval(); return y





        share|improve this answer






















        • 66: x=>F=y=>(g=x=>r=[...x+''].sort()+'')(y*x)!=g(y)|r!=g(y/x)?F(y+1):y May cause stack overflow if y is far from the solution tho.
          – Shieru Asakoto
          Sep 28 at 2:21











        • or 75 using eval: x=>y=>eval("for(;(g=x=>r=[...x+''].sort()+'')(y*x)!=g(y)|r!=g(y/x);y++);y")
          – Shieru Asakoto
          Sep 28 at 2:24











        • @ShieruAsakoto Thanks for the eval() idea. My first attempt was indeed recursive, but I gave up because of the high number of required iterations.
          – Arnauld
          Sep 28 at 6:14

















        up vote
        1
        down vote














        Python 2, 69 bytes





        S=sorted
        x,y=input()
        while(S(`y`)==S(`y*x`)==S(`y/x`))<1:y+=1
        print y


        Try it online!






        share|improve this answer





























          up vote
          1
          down vote














          Jelly,  14  13 bytes



          -1 thanks to Erik the Outgolfer (`` uses make_digits, so D was not required)

          +2 fixing a bug (thanks again to Erik the Outgolfer for pointing out the off-by one issue)



          ×;÷;⁸Ṣ€E
          ‘ç1#


          A full program printing the result (as a dyadic link a list of length 1 is yielded).



          Try it online!



          How?



          ×;÷;⁸Ṣ€E - Link 1, checkValidity: n, x e.g. n=285714, x=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]
          Ṣ€ - sort €ach (implicitly make decimals) [[1,2,4,5,7,8],[1,2,4,5,7,8],[1,2,4,5,7,8]]
          E - all equal? 1

          ‘ç1# - Main link: y, x
          ‘ - increment -> y+1
          # - count up from n=y+1 finding the first...
          1 - ...1 match of:
          ç - the last link (1) as a dyad i.e. f(n, x)


          Note that when the division is not exact the implicit decimal instruction (equivalent to a D) applied prior to the sort yields a fractional part

          e.g.: 1800÷3D -> [6,0,0]

          while 1801÷3D -> [6.0,0.0,0.33333333333337123]






          share|improve this answer






















          • I'm not really sure this answer is valid; the challenge requires the result to be "greater than y", which I interpret as "strictly greater than Y". Also, you don't need D.
            – Erik the Outgolfer
            Sep 28 at 10:36










          • Ah good spot on >= I totally missed that! Had no idea á¹¢ had make_digits set on it - thanks. Will have to fix & update later though...
            – Jonathan Allan
            Sep 28 at 12:29

















          up vote
          1
          down vote













          Mathematica, 82 74 bytes



          x=Sort@*IntegerDigits;Do[If[x[i#]==x@Floor[i/#]==x@i,Break@i],i,#2,∞]&


          -8 bytes thanks to tsh



          Function that takes arguments as [x,y]. Effectively a brute force search that checks if the sorted list of digits for y,y/x and xy are the same.



          Try it online!






          share|improve this answer






















          • I'm not familiar with Mathematica. But it could be proved that the answer would still be right if you drop the fractional part of division: All ans, ans/x, ans*x should be divisible by 9. And this may make your solution shorter.
            – tsh
            Sep 28 at 9:05










          • @tsh That works for x=3, but I'm not sure it's true for x=2.
            – Ørjan Johansen
            Sep 28 at 9:32










          • @ØrjanJohansen Let v = a[1]*10^p[1] + a[2]*10^p[2] + ... + a[n]*10^p[n], u = a[1] * 10^q[1] + ... + a[n] * 10^q[n]. And u-v = a[1]*(10^p[1]-10^q[1]) + ... + a[n]*(10^p[n]-10^q[n]) Since 10^x-10^y=0 (mod 9) always holds. u-v=0 (mod 9) always holds. If there is an wrong answer w, since w*x-w=0 (mod 9), and, w-floor(w/x)=0 (mod 9): we have floor(w/x)=0 (mod 9). if floor(w/x)*x <> w, w-floor(w/x)*x>=9, but this conflict with the fact that w-floor(w/x)*x<x while x could be 2 or 3.
            – tsh
            Sep 28 at 9:51










          • @tsh Thanks! For the benefit of others taking way too long to get this point, w=0 (mod 9) there follows from w*x-w=0 (mod 9) because x-1 is not divisible by 3.
            – Ørjan Johansen
            Sep 28 at 10:17










          • If I exclude the IntegerQ test, it produces a couple of errors when it tries to do IntegerDigits on fractions, but Mathematica still goes past them and produces the correct answer. I'm not sure if errors being included during the calculation would be allowed, even if the final answer is correct.
            – numbermaniac
            Sep 28 at 11:43

















          10 Answers
          10






          active

          oldest

          votes








          10 Answers
          10






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote



          accepted











          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





          share|improve this answer






















          • I adjusted the value for y to get a closer starting point and the result was incorrect for x = 3, y = 25000000.
            – PerpetualJ
            Sep 27 at 21:28











          • @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
            Sep 27 at 21:30










          • I've adjusted it after some thought and edited my first comment.
            – PerpetualJ
            Sep 27 at 21:32










          • @PerpetualJ: I've fixed it: made an assumption about - which was wrong.
            – BMO
            Sep 27 at 21:45






          • 1




            @PerpetualJ: I wrote the program ;) I added an explanation, now everybody should understand what's going on.
            – BMO
            Sep 27 at 21:59














          up vote
          4
          down vote



          accepted











          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





          share|improve this answer






















          • I adjusted the value for y to get a closer starting point and the result was incorrect for x = 3, y = 25000000.
            – PerpetualJ
            Sep 27 at 21:28











          • @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
            Sep 27 at 21:30










          • I've adjusted it after some thought and edited my first comment.
            – PerpetualJ
            Sep 27 at 21:32










          • @PerpetualJ: I've fixed it: made an assumption about - which was wrong.
            – BMO
            Sep 27 at 21:45






          • 1




            @PerpetualJ: I wrote the program ;) I added an explanation, now everybody should understand what's going on.
            – BMO
            Sep 27 at 21:59












          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted







          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





          share|improve this answer















          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






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Sep 27 at 21:56

























          answered Sep 27 at 21:22









          BMO

          9,97921774




          9,97921774











          • I adjusted the value for y to get a closer starting point and the result was incorrect for x = 3, y = 25000000.
            – PerpetualJ
            Sep 27 at 21:28











          • @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
            Sep 27 at 21:30










          • I've adjusted it after some thought and edited my first comment.
            – PerpetualJ
            Sep 27 at 21:32










          • @PerpetualJ: I've fixed it: made an assumption about - which was wrong.
            – BMO
            Sep 27 at 21:45






          • 1




            @PerpetualJ: I wrote the program ;) I added an explanation, now everybody should understand what's going on.
            – BMO
            Sep 27 at 21:59
















          • I adjusted the value for y to get a closer starting point and the result was incorrect for x = 3, y = 25000000.
            – PerpetualJ
            Sep 27 at 21:28











          • @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
            Sep 27 at 21:30










          • I've adjusted it after some thought and edited my first comment.
            – PerpetualJ
            Sep 27 at 21:32










          • @PerpetualJ: I've fixed it: made an assumption about - which was wrong.
            – BMO
            Sep 27 at 21:45






          • 1




            @PerpetualJ: I wrote the program ;) I added an explanation, now everybody should understand what's going on.
            – BMO
            Sep 27 at 21:59















          I adjusted the value for y to get a closer starting point and the result was incorrect for x = 3, y = 25000000.
          – PerpetualJ
          Sep 27 at 21:28





          I adjusted the value for y to get a closer starting point and the result was incorrect for x = 3, y = 25000000.
          – PerpetualJ
          Sep 27 at 21:28













          @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
          Sep 27 at 21:30




          @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
          Sep 27 at 21:30












          I've adjusted it after some thought and edited my first comment.
          – PerpetualJ
          Sep 27 at 21:32




          I've adjusted it after some thought and edited my first comment.
          – PerpetualJ
          Sep 27 at 21:32












          @PerpetualJ: I've fixed it: made an assumption about - which was wrong.
          – BMO
          Sep 27 at 21:45




          @PerpetualJ: I've fixed it: made an assumption about - which was wrong.
          – BMO
          Sep 27 at 21:45




          1




          1




          @PerpetualJ: I wrote the program ;) I added an explanation, now everybody should understand what's going on.
          – BMO
          Sep 27 at 21:59




          @PerpetualJ: I wrote the program ;) I added an explanation, now everybody should understand what's going on.
          – BMO
          Sep 27 at 21:59










          up vote
          4
          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^..*





          share|improve this answer


























            up vote
            4
            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^..*





            share|improve this answer
























              up vote
              4
              down vote










              up vote
              4
              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^..*





              share|improve this answer















              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^..*






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Sep 27 at 22:29

























              answered Sep 27 at 22:11









              nwellnhof

              3,973715




              3,973715




















                  up vote
                  4
                  down vote














                  Brachylog v2, 15 bytes



                  t<.g,?kA/p.∧A×p


                  Try it online!



                  Takes input in the form [x,y].



                  Explanation



                  t<.g,?kA/p.∧A×p
                  t Tail (extract y from the input)
                  < Brute-force search for a number > y, such that:
                  . it's the output to the user (called ".");
                  g forming it into a list,
                  ,? appending both inputs (to form [.,x,y]),
                  k and removing the last (to form [.,x])
                  A gives a value called A, such that:
                  / first ÷ second element of A
                  p is a permutation of
                  . .
                  ∧ and
                  A× first × second element of A
                  p is a permutation of .


                  Commentary



                  Brachylog's weakness at reusing multiple values multiple times shows up here; this program is almost all plumbing and very little algorithm.



                  As such, it might seem more convenient to simply hardcode the value of y (there's a comment on this question hypothesising that 2 is the only possible value). However, there are in fact solutions for y=3, meaning that unfortunately, the plumbing has to handle the value of y as well. The smallest that I'm aware of is the following:



                   315789473684210526
                  315789473684210526 × 3 = 947368421052631578
                  315789473684210526 ÷ 3 = 105263157894736842


                  (The technique I used to find this number isn't fully general, so it's possible that there's a smaller solution using some other approach.)



                  You're unlikely to verify that with this program, though. Brachylog's p is written in a very general way that doesn't have optimisations for special cases (such as the case where both the input and output are already known, meaning that you can do the verification in O(n log n) via sorting, rather than the O(n!) for the brute-force approach that I suspect it's using). As a consequence, it takes a very long time to verify that 105263157894736842 is a permutation of 315789473684210526 (I've been leaving it running for several minutes now with no obvious progress).



                  (EDIT: I checked the Brachylog source for the reason. It turns out that if you use p on two known integers, the algorithm used generates all possible permutations of the integer in question until it finds one that's equal to the output integer, as the algorithm is "input → indigits, permute indigits → outdigits, outdigits → output". A more efficient algorithm would be to set up the outdigits/output relationship first, so that the backtracking within the permutation could take into account which digits were available.)






                  share|improve this answer






















                  • Using a fork can decrease your code by 1 byte. Try it online!
                    – Kroppeb
                    Sep 28 at 9:20










                  • Also according to the docs, it seems checking if two known lists are a permutation is O(n²) swi-prolog.org/pldoc/man?predicate=permutation/2
                    – Kroppeb
                    Sep 28 at 9:24














                  up vote
                  4
                  down vote














                  Brachylog v2, 15 bytes



                  t<.g,?kA/p.∧A×p


                  Try it online!



                  Takes input in the form [x,y].



                  Explanation



                  t<.g,?kA/p.∧A×p
                  t Tail (extract y from the input)
                  < Brute-force search for a number > y, such that:
                  . it's the output to the user (called ".");
                  g forming it into a list,
                  ,? appending both inputs (to form [.,x,y]),
                  k and removing the last (to form [.,x])
                  A gives a value called A, such that:
                  / first ÷ second element of A
                  p is a permutation of
                  . .
                  ∧ and
                  A× first × second element of A
                  p is a permutation of .


                  Commentary



                  Brachylog's weakness at reusing multiple values multiple times shows up here; this program is almost all plumbing and very little algorithm.



                  As such, it might seem more convenient to simply hardcode the value of y (there's a comment on this question hypothesising that 2 is the only possible value). However, there are in fact solutions for y=3, meaning that unfortunately, the plumbing has to handle the value of y as well. The smallest that I'm aware of is the following:



                   315789473684210526
                  315789473684210526 × 3 = 947368421052631578
                  315789473684210526 ÷ 3 = 105263157894736842


                  (The technique I used to find this number isn't fully general, so it's possible that there's a smaller solution using some other approach.)



                  You're unlikely to verify that with this program, though. Brachylog's p is written in a very general way that doesn't have optimisations for special cases (such as the case where both the input and output are already known, meaning that you can do the verification in O(n log n) via sorting, rather than the O(n!) for the brute-force approach that I suspect it's using). As a consequence, it takes a very long time to verify that 105263157894736842 is a permutation of 315789473684210526 (I've been leaving it running for several minutes now with no obvious progress).



                  (EDIT: I checked the Brachylog source for the reason. It turns out that if you use p on two known integers, the algorithm used generates all possible permutations of the integer in question until it finds one that's equal to the output integer, as the algorithm is "input → indigits, permute indigits → outdigits, outdigits → output". A more efficient algorithm would be to set up the outdigits/output relationship first, so that the backtracking within the permutation could take into account which digits were available.)






                  share|improve this answer






















                  • Using a fork can decrease your code by 1 byte. Try it online!
                    – Kroppeb
                    Sep 28 at 9:20










                  • Also according to the docs, it seems checking if two known lists are a permutation is O(n²) swi-prolog.org/pldoc/man?predicate=permutation/2
                    – Kroppeb
                    Sep 28 at 9:24












                  up vote
                  4
                  down vote










                  up vote
                  4
                  down vote










                  Brachylog v2, 15 bytes



                  t<.g,?kA/p.∧A×p


                  Try it online!



                  Takes input in the form [x,y].



                  Explanation



                  t<.g,?kA/p.∧A×p
                  t Tail (extract y from the input)
                  < Brute-force search for a number > y, such that:
                  . it's the output to the user (called ".");
                  g forming it into a list,
                  ,? appending both inputs (to form [.,x,y]),
                  k and removing the last (to form [.,x])
                  A gives a value called A, such that:
                  / first ÷ second element of A
                  p is a permutation of
                  . .
                  ∧ and
                  A× first × second element of A
                  p is a permutation of .


                  Commentary



                  Brachylog's weakness at reusing multiple values multiple times shows up here; this program is almost all plumbing and very little algorithm.



                  As such, it might seem more convenient to simply hardcode the value of y (there's a comment on this question hypothesising that 2 is the only possible value). However, there are in fact solutions for y=3, meaning that unfortunately, the plumbing has to handle the value of y as well. The smallest that I'm aware of is the following:



                   315789473684210526
                  315789473684210526 × 3 = 947368421052631578
                  315789473684210526 ÷ 3 = 105263157894736842


                  (The technique I used to find this number isn't fully general, so it's possible that there's a smaller solution using some other approach.)



                  You're unlikely to verify that with this program, though. Brachylog's p is written in a very general way that doesn't have optimisations for special cases (such as the case where both the input and output are already known, meaning that you can do the verification in O(n log n) via sorting, rather than the O(n!) for the brute-force approach that I suspect it's using). As a consequence, it takes a very long time to verify that 105263157894736842 is a permutation of 315789473684210526 (I've been leaving it running for several minutes now with no obvious progress).



                  (EDIT: I checked the Brachylog source for the reason. It turns out that if you use p on two known integers, the algorithm used generates all possible permutations of the integer in question until it finds one that's equal to the output integer, as the algorithm is "input → indigits, permute indigits → outdigits, outdigits → output". A more efficient algorithm would be to set up the outdigits/output relationship first, so that the backtracking within the permutation could take into account which digits were available.)






                  share|improve this answer















                  Brachylog v2, 15 bytes



                  t<.g,?kA/p.∧A×p


                  Try it online!



                  Takes input in the form [x,y].



                  Explanation



                  t<.g,?kA/p.∧A×p
                  t Tail (extract y from the input)
                  < Brute-force search for a number > y, such that:
                  . it's the output to the user (called ".");
                  g forming it into a list,
                  ,? appending both inputs (to form [.,x,y]),
                  k and removing the last (to form [.,x])
                  A gives a value called A, such that:
                  / first ÷ second element of A
                  p is a permutation of
                  . .
                  ∧ and
                  A× first × second element of A
                  p is a permutation of .


                  Commentary



                  Brachylog's weakness at reusing multiple values multiple times shows up here; this program is almost all plumbing and very little algorithm.



                  As such, it might seem more convenient to simply hardcode the value of y (there's a comment on this question hypothesising that 2 is the only possible value). However, there are in fact solutions for y=3, meaning that unfortunately, the plumbing has to handle the value of y as well. The smallest that I'm aware of is the following:



                   315789473684210526
                  315789473684210526 × 3 = 947368421052631578
                  315789473684210526 ÷ 3 = 105263157894736842


                  (The technique I used to find this number isn't fully general, so it's possible that there's a smaller solution using some other approach.)



                  You're unlikely to verify that with this program, though. Brachylog's p is written in a very general way that doesn't have optimisations for special cases (such as the case where both the input and output are already known, meaning that you can do the verification in O(n log n) via sorting, rather than the O(n!) for the brute-force approach that I suspect it's using). As a consequence, it takes a very long time to verify that 105263157894736842 is a permutation of 315789473684210526 (I've been leaving it running for several minutes now with no obvious progress).



                  (EDIT: I checked the Brachylog source for the reason. It turns out that if you use p on two known integers, the algorithm used generates all possible permutations of the integer in question until it finds one that's equal to the output integer, as the algorithm is "input → indigits, permute indigits → outdigits, outdigits → output". A more efficient algorithm would be to set up the outdigits/output relationship first, so that the backtracking within the permutation could take into account which digits were available.)







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Sep 28 at 4:38


























                  community wiki





                  2 revs
                  ais523












                  • Using a fork can decrease your code by 1 byte. Try it online!
                    – Kroppeb
                    Sep 28 at 9:20










                  • Also according to the docs, it seems checking if two known lists are a permutation is O(n²) swi-prolog.org/pldoc/man?predicate=permutation/2
                    – Kroppeb
                    Sep 28 at 9:24
















                  • Using a fork can decrease your code by 1 byte. Try it online!
                    – Kroppeb
                    Sep 28 at 9:20










                  • Also according to the docs, it seems checking if two known lists are a permutation is O(n²) swi-prolog.org/pldoc/man?predicate=permutation/2
                    – Kroppeb
                    Sep 28 at 9:24















                  Using a fork can decrease your code by 1 byte. Try it online!
                  – Kroppeb
                  Sep 28 at 9:20




                  Using a fork can decrease your code by 1 byte. Try it online!
                  – Kroppeb
                  Sep 28 at 9:20












                  Also according to the docs, it seems checking if two known lists are a permutation is O(n²) swi-prolog.org/pldoc/man?predicate=permutation/2
                  – Kroppeb
                  Sep 28 at 9:24




                  Also according to the docs, it seems checking if two known lists are a permutation is O(n²) swi-prolog.org/pldoc/man?predicate=permutation/2
                  – Kroppeb
                  Sep 28 at 9:24










                  up vote
                  3
                  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.






                  share|improve this answer
























                    up vote
                    3
                    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.






                    share|improve this answer






















                      up vote
                      3
                      down vote










                      up vote
                      3
                      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.






                      share|improve this answer













                      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.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Sep 27 at 22:10









                      Οurous

                      5,36311031




                      5,36311031




















                          up vote
                          3
                          down vote













                          q, 65 bytes



                          f:asc 10 vs x;while[not((f y)~f y*x)&(f y*x)~f"i"$y%x;y+:1];y


                          Split number on base 10, sort each ascending, and check if equal. If not, increment y and go again






                          share|improve this answer
























                            up vote
                            3
                            down vote













                            q, 65 bytes



                            f:asc 10 vs x;while[not((f y)~f y*x)&(f y*x)~f"i"$y%x;y+:1];y


                            Split number on base 10, sort each ascending, and check if equal. If not, increment y and go again






                            share|improve this answer






















                              up vote
                              3
                              down vote










                              up vote
                              3
                              down vote









                              q, 65 bytes



                              f:asc 10 vs x;while[not((f y)~f y*x)&(f y*x)~f"i"$y%x;y+:1];y


                              Split number on base 10, sort each ascending, and check if equal. If not, increment y and go again






                              share|improve this answer












                              q, 65 bytes



                              f:asc 10 vs x;while[not((f y)~f y*x)&(f y*x)~f"i"$y%x;y+:1];y


                              Split number on base 10, sort each ascending, and check if equal. If not, increment y and go again







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Sep 27 at 23:36









                              Thaufeki

                              1115




                              1115




















                                  up vote
                                  2
                                  down vote













                                  Japt, 24 bytes



                                  Pretty naïve solution over a few beers; I'm sure there's a better way.



                                  @[X*UX/U]®ì nÃeeXì n}a°V


                                  Try it






                                  share|improve this answer






















                                  • Unfortunately this produces an incorrect result when x = 3 and y = 25000.
                                    – PerpetualJ
                                    Sep 27 at 21:30










                                  • @PerpetualJ Assuming 315789473684210526 is the first solution for x=3, Javascript or Japt can't compute it correctly since it doesn't fit in double precision.
                                    – Bubbler
                                    Sep 28 at 4:38










                                  • @PerpetualJ, fixed that earlier. That test case will never complete, though, for the reason Bubbler mentioned above.
                                    – Shaggy
                                    Sep 28 at 10:13










                                  • @Shaggy This now produces a correct result and the solution that Bubbler pointed at is not the first correct result above 25000. See my test cases if you're curious on that. +1
                                    – PerpetualJ
                                    Sep 28 at 15:17














                                  up vote
                                  2
                                  down vote













                                  Japt, 24 bytes



                                  Pretty naïve solution over a few beers; I'm sure there's a better way.



                                  @[X*UX/U]®ì nÃeeXì n}a°V


                                  Try it






                                  share|improve this answer






















                                  • Unfortunately this produces an incorrect result when x = 3 and y = 25000.
                                    – PerpetualJ
                                    Sep 27 at 21:30










                                  • @PerpetualJ Assuming 315789473684210526 is the first solution for x=3, Javascript or Japt can't compute it correctly since it doesn't fit in double precision.
                                    – Bubbler
                                    Sep 28 at 4:38










                                  • @PerpetualJ, fixed that earlier. That test case will never complete, though, for the reason Bubbler mentioned above.
                                    – Shaggy
                                    Sep 28 at 10:13










                                  • @Shaggy This now produces a correct result and the solution that Bubbler pointed at is not the first correct result above 25000. See my test cases if you're curious on that. +1
                                    – PerpetualJ
                                    Sep 28 at 15:17












                                  up vote
                                  2
                                  down vote










                                  up vote
                                  2
                                  down vote









                                  Japt, 24 bytes



                                  Pretty naïve solution over a few beers; I'm sure there's a better way.



                                  @[X*UX/U]®ì nÃeeXì n}a°V


                                  Try it






                                  share|improve this answer














                                  Japt, 24 bytes



                                  Pretty naïve solution over a few beers; I'm sure there's a better way.



                                  @[X*UX/U]®ì nÃeeXì n}a°V


                                  Try it







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Sep 28 at 7:03

























                                  answered Sep 27 at 21:19









                                  Shaggy

                                  17k21662




                                  17k21662











                                  • Unfortunately this produces an incorrect result when x = 3 and y = 25000.
                                    – PerpetualJ
                                    Sep 27 at 21:30










                                  • @PerpetualJ Assuming 315789473684210526 is the first solution for x=3, Javascript or Japt can't compute it correctly since it doesn't fit in double precision.
                                    – Bubbler
                                    Sep 28 at 4:38










                                  • @PerpetualJ, fixed that earlier. That test case will never complete, though, for the reason Bubbler mentioned above.
                                    – Shaggy
                                    Sep 28 at 10:13










                                  • @Shaggy This now produces a correct result and the solution that Bubbler pointed at is not the first correct result above 25000. See my test cases if you're curious on that. +1
                                    – PerpetualJ
                                    Sep 28 at 15:17
















                                  • Unfortunately this produces an incorrect result when x = 3 and y = 25000.
                                    – PerpetualJ
                                    Sep 27 at 21:30










                                  • @PerpetualJ Assuming 315789473684210526 is the first solution for x=3, Javascript or Japt can't compute it correctly since it doesn't fit in double precision.
                                    – Bubbler
                                    Sep 28 at 4:38










                                  • @PerpetualJ, fixed that earlier. That test case will never complete, though, for the reason Bubbler mentioned above.
                                    – Shaggy
                                    Sep 28 at 10:13










                                  • @Shaggy This now produces a correct result and the solution that Bubbler pointed at is not the first correct result above 25000. See my test cases if you're curious on that. +1
                                    – PerpetualJ
                                    Sep 28 at 15:17















                                  Unfortunately this produces an incorrect result when x = 3 and y = 25000.
                                  – PerpetualJ
                                  Sep 27 at 21:30




                                  Unfortunately this produces an incorrect result when x = 3 and y = 25000.
                                  – PerpetualJ
                                  Sep 27 at 21:30












                                  @PerpetualJ Assuming 315789473684210526 is the first solution for x=3, Javascript or Japt can't compute it correctly since it doesn't fit in double precision.
                                  – Bubbler
                                  Sep 28 at 4:38




                                  @PerpetualJ Assuming 315789473684210526 is the first solution for x=3, Javascript or Japt can't compute it correctly since it doesn't fit in double precision.
                                  – Bubbler
                                  Sep 28 at 4:38












                                  @PerpetualJ, fixed that earlier. That test case will never complete, though, for the reason Bubbler mentioned above.
                                  – Shaggy
                                  Sep 28 at 10:13




                                  @PerpetualJ, fixed that earlier. That test case will never complete, though, for the reason Bubbler mentioned above.
                                  – Shaggy
                                  Sep 28 at 10:13












                                  @Shaggy This now produces a correct result and the solution that Bubbler pointed at is not the first correct result above 25000. See my test cases if you're curious on that. +1
                                  – PerpetualJ
                                  Sep 28 at 15:17




                                  @Shaggy This now produces a correct result and the solution that Bubbler pointed at is not the first correct result above 25000. See my test cases if you're curious on that. +1
                                  – PerpetualJ
                                  Sep 28 at 15:17










                                  up vote
                                  2
                                  down vote













                                  JavaScript (ES6), 76 73 69 bytes



                                  Saved 3 bytes by using eval(), as suggested by @ShieruAsakoto



                                  Takes input as (x)(y).





                                  x=>y=>eval("for(;(g=x=>r=[...x+''].sort())(y*x)+g(y/x)!=g(y)+r;)++y")


                                  Try it online!



                                  A recursive version would be 62 bytes, but it's not well suited here because of the high number of required iterations.



                                  How?



                                  The helper function $g$ takes an integer as input, converts it to an array of digit characters and sorts this array.



                                  Example:



                                  g(285714) = [ '1', '2', '4', '5', '7', '8' ]


                                  To compare the digits of $ytimes x$ and those of $y/x$ against those of $y$, we test whether the concatenation of $g(ytimes x)$ with $g(y/x)$ is equal to the concatenation of $g(y)$ with itself.



                                  When adding two arrays together, each of them is implicitly coerced to a comma-separated string. The last digit of the first array is going to be directly concatenated with the first digit of the second array with no comma between them, which makes this format unambiguous.



                                  Example:



                                  g(123) + g(456) = [ '1', '2', '3' ] + [ '4', '5', '6' ] = '1,2,34,5,6'


                                  But:



                                  g(1234) + g(56) = [ '1', '2', '3', '4' ] + [ '5', '6' ] = '1,2,3,45,6'


                                  Commented



                                  x => y => // given x and y
                                  eval( // evaluate as JS code:
                                  "for(;" + // loop:
                                  "(g = x =>" + // g = helper function taking x
                                  "r =" + // the result will be eventually saved in r
                                  "[...x + '']" + // coerce x to a string and split it
                                  ".sort() + ''" + // sort the digits and coerce them back to a string
                                  ")(y * x) +" + // compute g(y * x)
                                  "g(y / x) !=" + // concatenate it with g(y / x)
                                  "g(y) + r;" + // loop while it's not equal to g(y) concatenated with
                                  ")" + // itself
                                  "++y" // increment y after each iteration
                                  ) // end of eval(); return y





                                  share|improve this answer






















                                  • 66: x=>F=y=>(g=x=>r=[...x+''].sort()+'')(y*x)!=g(y)|r!=g(y/x)?F(y+1):y May cause stack overflow if y is far from the solution tho.
                                    – Shieru Asakoto
                                    Sep 28 at 2:21











                                  • or 75 using eval: x=>y=>eval("for(;(g=x=>r=[...x+''].sort()+'')(y*x)!=g(y)|r!=g(y/x);y++);y")
                                    – Shieru Asakoto
                                    Sep 28 at 2:24











                                  • @ShieruAsakoto Thanks for the eval() idea. My first attempt was indeed recursive, but I gave up because of the high number of required iterations.
                                    – Arnauld
                                    Sep 28 at 6:14














                                  up vote
                                  2
                                  down vote













                                  JavaScript (ES6), 76 73 69 bytes



                                  Saved 3 bytes by using eval(), as suggested by @ShieruAsakoto



                                  Takes input as (x)(y).





                                  x=>y=>eval("for(;(g=x=>r=[...x+''].sort())(y*x)+g(y/x)!=g(y)+r;)++y")


                                  Try it online!



                                  A recursive version would be 62 bytes, but it's not well suited here because of the high number of required iterations.



                                  How?



                                  The helper function $g$ takes an integer as input, converts it to an array of digit characters and sorts this array.



                                  Example:



                                  g(285714) = [ '1', '2', '4', '5', '7', '8' ]


                                  To compare the digits of $ytimes x$ and those of $y/x$ against those of $y$, we test whether the concatenation of $g(ytimes x)$ with $g(y/x)$ is equal to the concatenation of $g(y)$ with itself.



                                  When adding two arrays together, each of them is implicitly coerced to a comma-separated string. The last digit of the first array is going to be directly concatenated with the first digit of the second array with no comma between them, which makes this format unambiguous.



                                  Example:



                                  g(123) + g(456) = [ '1', '2', '3' ] + [ '4', '5', '6' ] = '1,2,34,5,6'


                                  But:



                                  g(1234) + g(56) = [ '1', '2', '3', '4' ] + [ '5', '6' ] = '1,2,3,45,6'


                                  Commented



                                  x => y => // given x and y
                                  eval( // evaluate as JS code:
                                  "for(;" + // loop:
                                  "(g = x =>" + // g = helper function taking x
                                  "r =" + // the result will be eventually saved in r
                                  "[...x + '']" + // coerce x to a string and split it
                                  ".sort() + ''" + // sort the digits and coerce them back to a string
                                  ")(y * x) +" + // compute g(y * x)
                                  "g(y / x) !=" + // concatenate it with g(y / x)
                                  "g(y) + r;" + // loop while it's not equal to g(y) concatenated with
                                  ")" + // itself
                                  "++y" // increment y after each iteration
                                  ) // end of eval(); return y





                                  share|improve this answer






















                                  • 66: x=>F=y=>(g=x=>r=[...x+''].sort()+'')(y*x)!=g(y)|r!=g(y/x)?F(y+1):y May cause stack overflow if y is far from the solution tho.
                                    – Shieru Asakoto
                                    Sep 28 at 2:21











                                  • or 75 using eval: x=>y=>eval("for(;(g=x=>r=[...x+''].sort()+'')(y*x)!=g(y)|r!=g(y/x);y++);y")
                                    – Shieru Asakoto
                                    Sep 28 at 2:24











                                  • @ShieruAsakoto Thanks for the eval() idea. My first attempt was indeed recursive, but I gave up because of the high number of required iterations.
                                    – Arnauld
                                    Sep 28 at 6:14












                                  up vote
                                  2
                                  down vote










                                  up vote
                                  2
                                  down vote









                                  JavaScript (ES6), 76 73 69 bytes



                                  Saved 3 bytes by using eval(), as suggested by @ShieruAsakoto



                                  Takes input as (x)(y).





                                  x=>y=>eval("for(;(g=x=>r=[...x+''].sort())(y*x)+g(y/x)!=g(y)+r;)++y")


                                  Try it online!



                                  A recursive version would be 62 bytes, but it's not well suited here because of the high number of required iterations.



                                  How?



                                  The helper function $g$ takes an integer as input, converts it to an array of digit characters and sorts this array.



                                  Example:



                                  g(285714) = [ '1', '2', '4', '5', '7', '8' ]


                                  To compare the digits of $ytimes x$ and those of $y/x$ against those of $y$, we test whether the concatenation of $g(ytimes x)$ with $g(y/x)$ is equal to the concatenation of $g(y)$ with itself.



                                  When adding two arrays together, each of them is implicitly coerced to a comma-separated string. The last digit of the first array is going to be directly concatenated with the first digit of the second array with no comma between them, which makes this format unambiguous.



                                  Example:



                                  g(123) + g(456) = [ '1', '2', '3' ] + [ '4', '5', '6' ] = '1,2,34,5,6'


                                  But:



                                  g(1234) + g(56) = [ '1', '2', '3', '4' ] + [ '5', '6' ] = '1,2,3,45,6'


                                  Commented



                                  x => y => // given x and y
                                  eval( // evaluate as JS code:
                                  "for(;" + // loop:
                                  "(g = x =>" + // g = helper function taking x
                                  "r =" + // the result will be eventually saved in r
                                  "[...x + '']" + // coerce x to a string and split it
                                  ".sort() + ''" + // sort the digits and coerce them back to a string
                                  ")(y * x) +" + // compute g(y * x)
                                  "g(y / x) !=" + // concatenate it with g(y / x)
                                  "g(y) + r;" + // loop while it's not equal to g(y) concatenated with
                                  ")" + // itself
                                  "++y" // increment y after each iteration
                                  ) // end of eval(); return y





                                  share|improve this answer














                                  JavaScript (ES6), 76 73 69 bytes



                                  Saved 3 bytes by using eval(), as suggested by @ShieruAsakoto



                                  Takes input as (x)(y).





                                  x=>y=>eval("for(;(g=x=>r=[...x+''].sort())(y*x)+g(y/x)!=g(y)+r;)++y")


                                  Try it online!



                                  A recursive version would be 62 bytes, but it's not well suited here because of the high number of required iterations.



                                  How?



                                  The helper function $g$ takes an integer as input, converts it to an array of digit characters and sorts this array.



                                  Example:



                                  g(285714) = [ '1', '2', '4', '5', '7', '8' ]


                                  To compare the digits of $ytimes x$ and those of $y/x$ against those of $y$, we test whether the concatenation of $g(ytimes x)$ with $g(y/x)$ is equal to the concatenation of $g(y)$ with itself.



                                  When adding two arrays together, each of them is implicitly coerced to a comma-separated string. The last digit of the first array is going to be directly concatenated with the first digit of the second array with no comma between them, which makes this format unambiguous.



                                  Example:



                                  g(123) + g(456) = [ '1', '2', '3' ] + [ '4', '5', '6' ] = '1,2,34,5,6'


                                  But:



                                  g(1234) + g(56) = [ '1', '2', '3', '4' ] + [ '5', '6' ] = '1,2,3,45,6'


                                  Commented



                                  x => y => // given x and y
                                  eval( // evaluate as JS code:
                                  "for(;" + // loop:
                                  "(g = x =>" + // g = helper function taking x
                                  "r =" + // the result will be eventually saved in r
                                  "[...x + '']" + // coerce x to a string and split it
                                  ".sort() + ''" + // sort the digits and coerce them back to a string
                                  ")(y * x) +" + // compute g(y * x)
                                  "g(y / x) !=" + // concatenate it with g(y / x)
                                  "g(y) + r;" + // loop while it's not equal to g(y) concatenated with
                                  ")" + // itself
                                  "++y" // increment y after each iteration
                                  ) // end of eval(); return y






                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Sep 29 at 11:42

























                                  answered Sep 27 at 22:43









                                  Arnauld

                                  65.9k583278




                                  65.9k583278











                                  • 66: x=>F=y=>(g=x=>r=[...x+''].sort()+'')(y*x)!=g(y)|r!=g(y/x)?F(y+1):y May cause stack overflow if y is far from the solution tho.
                                    – Shieru Asakoto
                                    Sep 28 at 2:21











                                  • or 75 using eval: x=>y=>eval("for(;(g=x=>r=[...x+''].sort()+'')(y*x)!=g(y)|r!=g(y/x);y++);y")
                                    – Shieru Asakoto
                                    Sep 28 at 2:24











                                  • @ShieruAsakoto Thanks for the eval() idea. My first attempt was indeed recursive, but I gave up because of the high number of required iterations.
                                    – Arnauld
                                    Sep 28 at 6:14
















                                  • 66: x=>F=y=>(g=x=>r=[...x+''].sort()+'')(y*x)!=g(y)|r!=g(y/x)?F(y+1):y May cause stack overflow if y is far from the solution tho.
                                    – Shieru Asakoto
                                    Sep 28 at 2:21











                                  • or 75 using eval: x=>y=>eval("for(;(g=x=>r=[...x+''].sort()+'')(y*x)!=g(y)|r!=g(y/x);y++);y")
                                    – Shieru Asakoto
                                    Sep 28 at 2:24











                                  • @ShieruAsakoto Thanks for the eval() idea. My first attempt was indeed recursive, but I gave up because of the high number of required iterations.
                                    – Arnauld
                                    Sep 28 at 6:14















                                  66: x=>F=y=>(g=x=>r=[...x+''].sort()+'')(y*x)!=g(y)|r!=g(y/x)?F(y+1):y May cause stack overflow if y is far from the solution tho.
                                  – Shieru Asakoto
                                  Sep 28 at 2:21





                                  66: x=>F=y=>(g=x=>r=[...x+''].sort()+'')(y*x)!=g(y)|r!=g(y/x)?F(y+1):y May cause stack overflow if y is far from the solution tho.
                                  – Shieru Asakoto
                                  Sep 28 at 2:21













                                  or 75 using eval: x=>y=>eval("for(;(g=x=>r=[...x+''].sort()+'')(y*x)!=g(y)|r!=g(y/x);y++);y")
                                  – Shieru Asakoto
                                  Sep 28 at 2:24





                                  or 75 using eval: x=>y=>eval("for(;(g=x=>r=[...x+''].sort()+'')(y*x)!=g(y)|r!=g(y/x);y++);y")
                                  – Shieru Asakoto
                                  Sep 28 at 2:24













                                  @ShieruAsakoto Thanks for the eval() idea. My first attempt was indeed recursive, but I gave up because of the high number of required iterations.
                                  – Arnauld
                                  Sep 28 at 6:14




                                  @ShieruAsakoto Thanks for the eval() idea. My first attempt was indeed recursive, but I gave up because of the high number of required iterations.
                                  – Arnauld
                                  Sep 28 at 6:14










                                  up vote
                                  1
                                  down vote














                                  Python 2, 69 bytes





                                  S=sorted
                                  x,y=input()
                                  while(S(`y`)==S(`y*x`)==S(`y/x`))<1:y+=1
                                  print y


                                  Try it online!






                                  share|improve this answer


























                                    up vote
                                    1
                                    down vote














                                    Python 2, 69 bytes





                                    S=sorted
                                    x,y=input()
                                    while(S(`y`)==S(`y*x`)==S(`y/x`))<1:y+=1
                                    print y


                                    Try it online!






                                    share|improve this answer
























                                      up vote
                                      1
                                      down vote










                                      up vote
                                      1
                                      down vote










                                      Python 2, 69 bytes





                                      S=sorted
                                      x,y=input()
                                      while(S(`y`)==S(`y*x`)==S(`y/x`))<1:y+=1
                                      print y


                                      Try it online!






                                      share|improve this answer















                                      Python 2, 69 bytes





                                      S=sorted
                                      x,y=input()
                                      while(S(`y`)==S(`y*x`)==S(`y/x`))<1:y+=1
                                      print y


                                      Try it online!







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Sep 28 at 6:50

























                                      answered Sep 28 at 6:28









                                      Chas Brown

                                      4,3211319




                                      4,3211319




















                                          up vote
                                          1
                                          down vote














                                          Jelly,  14  13 bytes



                                          -1 thanks to Erik the Outgolfer (`` uses make_digits, so D was not required)

                                          +2 fixing a bug (thanks again to Erik the Outgolfer for pointing out the off-by one issue)



                                          ×;÷;⁸Ṣ€E
                                          ‘ç1#


                                          A full program printing the result (as a dyadic link a list of length 1 is yielded).



                                          Try it online!



                                          How?



                                          ×;÷;⁸Ṣ€E - Link 1, checkValidity: n, x e.g. n=285714, x=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]
                                          Ṣ€ - sort €ach (implicitly make decimals) [[1,2,4,5,7,8],[1,2,4,5,7,8],[1,2,4,5,7,8]]
                                          E - all equal? 1

                                          ‘ç1# - Main link: y, x
                                          ‘ - increment -> y+1
                                          # - count up from n=y+1 finding the first...
                                          1 - ...1 match of:
                                          ç - the last link (1) as a dyad i.e. f(n, x)


                                          Note that when the division is not exact the implicit decimal instruction (equivalent to a D) applied prior to the sort yields a fractional part

                                          e.g.: 1800÷3D -> [6,0,0]

                                          while 1801÷3D -> [6.0,0.0,0.33333333333337123]






                                          share|improve this answer






















                                          • I'm not really sure this answer is valid; the challenge requires the result to be "greater than y", which I interpret as "strictly greater than Y". Also, you don't need D.
                                            – Erik the Outgolfer
                                            Sep 28 at 10:36










                                          • Ah good spot on >= I totally missed that! Had no idea á¹¢ had make_digits set on it - thanks. Will have to fix & update later though...
                                            – Jonathan Allan
                                            Sep 28 at 12:29














                                          up vote
                                          1
                                          down vote














                                          Jelly,  14  13 bytes



                                          -1 thanks to Erik the Outgolfer (`` uses make_digits, so D was not required)

                                          +2 fixing a bug (thanks again to Erik the Outgolfer for pointing out the off-by one issue)



                                          ×;÷;⁸Ṣ€E
                                          ‘ç1#


                                          A full program printing the result (as a dyadic link a list of length 1 is yielded).



                                          Try it online!



                                          How?



                                          ×;÷;⁸Ṣ€E - Link 1, checkValidity: n, x e.g. n=285714, x=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]
                                          Ṣ€ - sort €ach (implicitly make decimals) [[1,2,4,5,7,8],[1,2,4,5,7,8],[1,2,4,5,7,8]]
                                          E - all equal? 1

                                          ‘ç1# - Main link: y, x
                                          ‘ - increment -> y+1
                                          # - count up from n=y+1 finding the first...
                                          1 - ...1 match of:
                                          ç - the last link (1) as a dyad i.e. f(n, x)


                                          Note that when the division is not exact the implicit decimal instruction (equivalent to a D) applied prior to the sort yields a fractional part

                                          e.g.: 1800÷3D -> [6,0,0]

                                          while 1801÷3D -> [6.0,0.0,0.33333333333337123]






                                          share|improve this answer






















                                          • I'm not really sure this answer is valid; the challenge requires the result to be "greater than y", which I interpret as "strictly greater than Y". Also, you don't need D.
                                            – Erik the Outgolfer
                                            Sep 28 at 10:36










                                          • Ah good spot on >= I totally missed that! Had no idea á¹¢ had make_digits set on it - thanks. Will have to fix & update later though...
                                            – Jonathan Allan
                                            Sep 28 at 12:29












                                          up vote
                                          1
                                          down vote










                                          up vote
                                          1
                                          down vote










                                          Jelly,  14  13 bytes



                                          -1 thanks to Erik the Outgolfer (`` uses make_digits, so D was not required)

                                          +2 fixing a bug (thanks again to Erik the Outgolfer for pointing out the off-by one issue)



                                          ×;÷;⁸Ṣ€E
                                          ‘ç1#


                                          A full program printing the result (as a dyadic link a list of length 1 is yielded).



                                          Try it online!



                                          How?



                                          ×;÷;⁸Ṣ€E - Link 1, checkValidity: n, x e.g. n=285714, x=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]
                                          Ṣ€ - sort €ach (implicitly make decimals) [[1,2,4,5,7,8],[1,2,4,5,7,8],[1,2,4,5,7,8]]
                                          E - all equal? 1

                                          ‘ç1# - Main link: y, x
                                          ‘ - increment -> y+1
                                          # - count up from n=y+1 finding the first...
                                          1 - ...1 match of:
                                          ç - the last link (1) as a dyad i.e. f(n, x)


                                          Note that when the division is not exact the implicit decimal instruction (equivalent to a D) applied prior to the sort yields a fractional part

                                          e.g.: 1800÷3D -> [6,0,0]

                                          while 1801÷3D -> [6.0,0.0,0.33333333333337123]






                                          share|improve this answer















                                          Jelly,  14  13 bytes



                                          -1 thanks to Erik the Outgolfer (`` uses make_digits, so D was not required)

                                          +2 fixing a bug (thanks again to Erik the Outgolfer for pointing out the off-by one issue)



                                          ×;÷;⁸Ṣ€E
                                          ‘ç1#


                                          A full program printing the result (as a dyadic link a list of length 1 is yielded).



                                          Try it online!



                                          How?



                                          ×;÷;⁸Ṣ€E - Link 1, checkValidity: n, x e.g. n=285714, x=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]
                                          Ṣ€ - sort €ach (implicitly make decimals) [[1,2,4,5,7,8],[1,2,4,5,7,8],[1,2,4,5,7,8]]
                                          E - all equal? 1

                                          ‘ç1# - Main link: y, x
                                          ‘ - increment -> y+1
                                          # - count up from n=y+1 finding the first...
                                          1 - ...1 match of:
                                          ç - the last link (1) as a dyad i.e. f(n, x)


                                          Note that when the division is not exact the implicit decimal instruction (equivalent to a D) applied prior to the sort yields a fractional part

                                          e.g.: 1800÷3D -> [6,0,0]

                                          while 1801÷3D -> [6.0,0.0,0.33333333333337123]







                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Sep 28 at 15:54

























                                          answered Sep 27 at 22:02









                                          Jonathan Allan

                                          48.7k534161




                                          48.7k534161











                                          • I'm not really sure this answer is valid; the challenge requires the result to be "greater than y", which I interpret as "strictly greater than Y". Also, you don't need D.
                                            – Erik the Outgolfer
                                            Sep 28 at 10:36










                                          • Ah good spot on >= I totally missed that! Had no idea á¹¢ had make_digits set on it - thanks. Will have to fix & update later though...
                                            – Jonathan Allan
                                            Sep 28 at 12:29
















                                          • I'm not really sure this answer is valid; the challenge requires the result to be "greater than y", which I interpret as "strictly greater than Y". Also, you don't need D.
                                            – Erik the Outgolfer
                                            Sep 28 at 10:36










                                          • Ah good spot on >= I totally missed that! Had no idea á¹¢ had make_digits set on it - thanks. Will have to fix & update later though...
                                            – Jonathan Allan
                                            Sep 28 at 12:29















                                          I'm not really sure this answer is valid; the challenge requires the result to be "greater than y", which I interpret as "strictly greater than Y". Also, you don't need D.
                                          – Erik the Outgolfer
                                          Sep 28 at 10:36




                                          I'm not really sure this answer is valid; the challenge requires the result to be "greater than y", which I interpret as "strictly greater than Y". Also, you don't need D.
                                          – Erik the Outgolfer
                                          Sep 28 at 10:36












                                          Ah good spot on >= I totally missed that! Had no idea á¹¢ had make_digits set on it - thanks. Will have to fix & update later though...
                                          – Jonathan Allan
                                          Sep 28 at 12:29




                                          Ah good spot on >= I totally missed that! Had no idea á¹¢ had make_digits set on it - thanks. Will have to fix & update later though...
                                          – Jonathan Allan
                                          Sep 28 at 12:29










                                          up vote
                                          1
                                          down vote













                                          Mathematica, 82 74 bytes



                                          x=Sort@*IntegerDigits;Do[If[x[i#]==x@Floor[i/#]==x@i,Break@i],i,#2,∞]&


                                          -8 bytes thanks to tsh



                                          Function that takes arguments as [x,y]. Effectively a brute force search that checks if the sorted list of digits for y,y/x and xy are the same.



                                          Try it online!






                                          share|improve this answer






















                                          • I'm not familiar with Mathematica. But it could be proved that the answer would still be right if you drop the fractional part of division: All ans, ans/x, ans*x should be divisible by 9. And this may make your solution shorter.
                                            – tsh
                                            Sep 28 at 9:05










                                          • @tsh That works for x=3, but I'm not sure it's true for x=2.
                                            – Ørjan Johansen
                                            Sep 28 at 9:32










                                          • @ØrjanJohansen Let v = a[1]*10^p[1] + a[2]*10^p[2] + ... + a[n]*10^p[n], u = a[1] * 10^q[1] + ... + a[n] * 10^q[n]. And u-v = a[1]*(10^p[1]-10^q[1]) + ... + a[n]*(10^p[n]-10^q[n]) Since 10^x-10^y=0 (mod 9) always holds. u-v=0 (mod 9) always holds. If there is an wrong answer w, since w*x-w=0 (mod 9), and, w-floor(w/x)=0 (mod 9): we have floor(w/x)=0 (mod 9). if floor(w/x)*x <> w, w-floor(w/x)*x>=9, but this conflict with the fact that w-floor(w/x)*x<x while x could be 2 or 3.
                                            – tsh
                                            Sep 28 at 9:51










                                          • @tsh Thanks! For the benefit of others taking way too long to get this point, w=0 (mod 9) there follows from w*x-w=0 (mod 9) because x-1 is not divisible by 3.
                                            – Ørjan Johansen
                                            Sep 28 at 10:17










                                          • If I exclude the IntegerQ test, it produces a couple of errors when it tries to do IntegerDigits on fractions, but Mathematica still goes past them and produces the correct answer. I'm not sure if errors being included during the calculation would be allowed, even if the final answer is correct.
                                            – numbermaniac
                                            Sep 28 at 11:43














                                          up vote
                                          1
                                          down vote













                                          Mathematica, 82 74 bytes



                                          x=Sort@*IntegerDigits;Do[If[x[i#]==x@Floor[i/#]==x@i,Break@i],i,#2,∞]&


                                          -8 bytes thanks to tsh



                                          Function that takes arguments as [x,y]. Effectively a brute force search that checks if the sorted list of digits for y,y/x and xy are the same.



                                          Try it online!






                                          share|improve this answer






















                                          • I'm not familiar with Mathematica. But it could be proved that the answer would still be right if you drop the fractional part of division: All ans, ans/x, ans*x should be divisible by 9. And this may make your solution shorter.
                                            – tsh
                                            Sep 28 at 9:05










                                          • @tsh That works for x=3, but I'm not sure it's true for x=2.
                                            – Ørjan Johansen
                                            Sep 28 at 9:32










                                          • @ØrjanJohansen Let v = a[1]*10^p[1] + a[2]*10^p[2] + ... + a[n]*10^p[n], u = a[1] * 10^q[1] + ... + a[n] * 10^q[n]. And u-v = a[1]*(10^p[1]-10^q[1]) + ... + a[n]*(10^p[n]-10^q[n]) Since 10^x-10^y=0 (mod 9) always holds. u-v=0 (mod 9) always holds. If there is an wrong answer w, since w*x-w=0 (mod 9), and, w-floor(w/x)=0 (mod 9): we have floor(w/x)=0 (mod 9). if floor(w/x)*x <> w, w-floor(w/x)*x>=9, but this conflict with the fact that w-floor(w/x)*x<x while x could be 2 or 3.
                                            – tsh
                                            Sep 28 at 9:51










                                          • @tsh Thanks! For the benefit of others taking way too long to get this point, w=0 (mod 9) there follows from w*x-w=0 (mod 9) because x-1 is not divisible by 3.
                                            – Ørjan Johansen
                                            Sep 28 at 10:17










                                          • If I exclude the IntegerQ test, it produces a couple of errors when it tries to do IntegerDigits on fractions, but Mathematica still goes past them and produces the correct answer. I'm not sure if errors being included during the calculation would be allowed, even if the final answer is correct.
                                            – numbermaniac
                                            Sep 28 at 11:43












                                          up vote
                                          1
                                          down vote










                                          up vote
                                          1
                                          down vote









                                          Mathematica, 82 74 bytes



                                          x=Sort@*IntegerDigits;Do[If[x[i#]==x@Floor[i/#]==x@i,Break@i],i,#2,∞]&


                                          -8 bytes thanks to tsh



                                          Function that takes arguments as [x,y]. Effectively a brute force search that checks if the sorted list of digits for y,y/x and xy are the same.



                                          Try it online!






                                          share|improve this answer














                                          Mathematica, 82 74 bytes



                                          x=Sort@*IntegerDigits;Do[If[x[i#]==x@Floor[i/#]==x@i,Break@i],i,#2,∞]&


                                          -8 bytes thanks to tsh



                                          Function that takes arguments as [x,y]. Effectively a brute force search that checks if the sorted list of digits for y,y/x and xy are the same.



                                          Try it online!







                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Sep 29 at 1:02

























                                          answered Sep 28 at 7:21









                                          numbermaniac

                                          627312




                                          627312











                                          • I'm not familiar with Mathematica. But it could be proved that the answer would still be right if you drop the fractional part of division: All ans, ans/x, ans*x should be divisible by 9. And this may make your solution shorter.
                                            – tsh
                                            Sep 28 at 9:05










                                          • @tsh That works for x=3, but I'm not sure it's true for x=2.
                                            – Ørjan Johansen
                                            Sep 28 at 9:32










                                          • @ØrjanJohansen Let v = a[1]*10^p[1] + a[2]*10^p[2] + ... + a[n]*10^p[n], u = a[1] * 10^q[1] + ... + a[n] * 10^q[n]. And u-v = a[1]*(10^p[1]-10^q[1]) + ... + a[n]*(10^p[n]-10^q[n]) Since 10^x-10^y=0 (mod 9) always holds. u-v=0 (mod 9) always holds. If there is an wrong answer w, since w*x-w=0 (mod 9), and, w-floor(w/x)=0 (mod 9): we have floor(w/x)=0 (mod 9). if floor(w/x)*x <> w, w-floor(w/x)*x>=9, but this conflict with the fact that w-floor(w/x)*x<x while x could be 2 or 3.
                                            – tsh
                                            Sep 28 at 9:51










                                          • @tsh Thanks! For the benefit of others taking way too long to get this point, w=0 (mod 9) there follows from w*x-w=0 (mod 9) because x-1 is not divisible by 3.
                                            – Ørjan Johansen
                                            Sep 28 at 10:17










                                          • If I exclude the IntegerQ test, it produces a couple of errors when it tries to do IntegerDigits on fractions, but Mathematica still goes past them and produces the correct answer. I'm not sure if errors being included during the calculation would be allowed, even if the final answer is correct.
                                            – numbermaniac
                                            Sep 28 at 11:43
















                                          • I'm not familiar with Mathematica. But it could be proved that the answer would still be right if you drop the fractional part of division: All ans, ans/x, ans*x should be divisible by 9. And this may make your solution shorter.
                                            – tsh
                                            Sep 28 at 9:05










                                          • @tsh That works for x=3, but I'm not sure it's true for x=2.
                                            – Ørjan Johansen
                                            Sep 28 at 9:32










                                          • @ØrjanJohansen Let v = a[1]*10^p[1] + a[2]*10^p[2] + ... + a[n]*10^p[n], u = a[1] * 10^q[1] + ... + a[n] * 10^q[n]. And u-v = a[1]*(10^p[1]-10^q[1]) + ... + a[n]*(10^p[n]-10^q[n]) Since 10^x-10^y=0 (mod 9) always holds. u-v=0 (mod 9) always holds. If there is an wrong answer w, since w*x-w=0 (mod 9), and, w-floor(w/x)=0 (mod 9): we have floor(w/x)=0 (mod 9). if floor(w/x)*x <> w, w-floor(w/x)*x>=9, but this conflict with the fact that w-floor(w/x)*x<x while x could be 2 or 3.
                                            – tsh
                                            Sep 28 at 9:51










                                          • @tsh Thanks! For the benefit of others taking way too long to get this point, w=0 (mod 9) there follows from w*x-w=0 (mod 9) because x-1 is not divisible by 3.
                                            – Ørjan Johansen
                                            Sep 28 at 10:17










                                          • If I exclude the IntegerQ test, it produces a couple of errors when it tries to do IntegerDigits on fractions, but Mathematica still goes past them and produces the correct answer. I'm not sure if errors being included during the calculation would be allowed, even if the final answer is correct.
                                            – numbermaniac
                                            Sep 28 at 11:43















                                          I'm not familiar with Mathematica. But it could be proved that the answer would still be right if you drop the fractional part of division: All ans, ans/x, ans*x should be divisible by 9. And this may make your solution shorter.
                                          – tsh
                                          Sep 28 at 9:05




                                          I'm not familiar with Mathematica. But it could be proved that the answer would still be right if you drop the fractional part of division: All ans, ans/x, ans*x should be divisible by 9. And this may make your solution shorter.
                                          – tsh
                                          Sep 28 at 9:05












                                          @tsh That works for x=3, but I'm not sure it's true for x=2.
                                          – Ørjan Johansen
                                          Sep 28 at 9:32




                                          @tsh That works for x=3, but I'm not sure it's true for x=2.
                                          – Ørjan Johansen
                                          Sep 28 at 9:32












                                          @ØrjanJohansen Let v = a[1]*10^p[1] + a[2]*10^p[2] + ... + a[n]*10^p[n], u = a[1] * 10^q[1] + ... + a[n] * 10^q[n]. And u-v = a[1]*(10^p[1]-10^q[1]) + ... + a[n]*(10^p[n]-10^q[n]) Since 10^x-10^y=0 (mod 9) always holds. u-v=0 (mod 9) always holds. If there is an wrong answer w, since w*x-w=0 (mod 9), and, w-floor(w/x)=0 (mod 9): we have floor(w/x)=0 (mod 9). if floor(w/x)*x <> w, w-floor(w/x)*x>=9, but this conflict with the fact that w-floor(w/x)*x<x while x could be 2 or 3.
                                          – tsh
                                          Sep 28 at 9:51




                                          @ØrjanJohansen Let v = a[1]*10^p[1] + a[2]*10^p[2] + ... + a[n]*10^p[n], u = a[1] * 10^q[1] + ... + a[n] * 10^q[n]. And u-v = a[1]*(10^p[1]-10^q[1]) + ... + a[n]*(10^p[n]-10^q[n]) Since 10^x-10^y=0 (mod 9) always holds. u-v=0 (mod 9) always holds. If there is an wrong answer w, since w*x-w=0 (mod 9), and, w-floor(w/x)=0 (mod 9): we have floor(w/x)=0 (mod 9). if floor(w/x)*x <> w, w-floor(w/x)*x>=9, but this conflict with the fact that w-floor(w/x)*x<x while x could be 2 or 3.
                                          – tsh
                                          Sep 28 at 9:51












                                          @tsh Thanks! For the benefit of others taking way too long to get this point, w=0 (mod 9) there follows from w*x-w=0 (mod 9) because x-1 is not divisible by 3.
                                          – Ørjan Johansen
                                          Sep 28 at 10:17




                                          @tsh Thanks! For the benefit of others taking way too long to get this point, w=0 (mod 9) there follows from w*x-w=0 (mod 9) because x-1 is not divisible by 3.
                                          – Ørjan Johansen
                                          Sep 28 at 10:17












                                          If I exclude the IntegerQ test, it produces a couple of errors when it tries to do IntegerDigits on fractions, but Mathematica still goes past them and produces the correct answer. I'm not sure if errors being included during the calculation would be allowed, even if the final answer is correct.
                                          – numbermaniac
                                          Sep 28 at 11:43




                                          If I exclude the IntegerQ test, it produces a couple of errors when it tries to do IntegerDigits on fractions, but Mathematica still goes past them and produces the correct answer. I'm not sure if errors being included during the calculation would be allowed, even if the final answer is correct.
                                          – numbermaniac
                                          Sep 28 at 11:43


                                          Popular posts from this blog

                                          How to check contact read email or not when send email to Individual?

                                          Bahrain

                                          Postfix configuration issue with fips on centos 7; mailgun relay