Skip to main content
deleted 255 characters in body
Source Link
dylnan
  • 5.4k
  • 2
  • 16
  • 33

Jelly, 2222 21 bytes

DS=³a³ḍaDṫ³DLC¤Ḍ=³
Ç1#DS=³a³ḍaDṫ³DLC¤Ḍ=³ø1#

Try it online!Try it online!

Edit: compressed to a single line

Explanation

Ç1#                    Main Link
DS=³a³ḍaDṫ³DLC¤Ḍ=³ø1#
Ç                      Calls first link as a monad
 1#               ø1#  Evaluate the condition Countbefore upthis and stop when you get first match 

First Link:

DS=³a³ḍaDṫ³DLC¤Ḍ=³ increment a counter until Thisit is whatmet Çthen calls
output the counter                     
D                      Digits of incremented variable as a list
 S                     Sum
  =³                   Equals argument of program?
    a                  Logical and
     ³ḍ                Does arg divide incremented variable?
       a               Logical and
        Dṫ     Ḍ       Last n digits of inc. var. where n is number of digits in program input
          ³DLC         1 - (number of digits of program input)
              ¤        Book ends above nilad
                =³     Equals program input?

When all three conditionals in the first link are met the loop ends and outputs which iteration number it is.

This took me many hours to write because I'm learning Jelly but now that I'm done I'm so satisfied. For a long time I didn't realize I needed the ¤ and I just couldn't get it to work. Looking at this[this][1] well explained code helped me seal the deal. Lots of other Jelly answers in PPCG guided me too.

Jelly, 22 bytes

DS=³a³ḍaDṫ³DLC¤Ḍ=³
Ç1#

Try it online!

Explanation

Ç1#                    Main Link

Ç                      Calls first link as a monad
 1#                    Count up and stop when you get first match 

First Link:

DS=³a³ḍaDṫ³DLC¤Ḍ=³     This is what Ç calls
                       
D                      Digits of incremented variable as a list
 S                     Sum
  =³                   Equals argument of program?
    a                  Logical and
     ³ḍ                Does arg divide incremented variable?
       a               Logical and
        Dṫ     Ḍ       Last n digits of inc. var. where n is number of digits in program input
          ³DLC         1 - (number of digits of program input)
              ¤        Book ends above nilad
                =³     Equals program input?

When all three conditionals in the first link are met the loop ends and outputs which iteration number it is.

This took me many hours to write because I'm learning Jelly but now that I'm done I'm so satisfied. For a long time I didn't realize I needed the ¤ and I just couldn't get it to work. Looking at this well explained code helped me seal the deal. Lots of other Jelly answers in PPCG guided me too.

Jelly, 22 21 bytes

DS=³a³ḍaDṫ³DLC¤Ḍ=³ø1#

Try it online!

Edit: compressed to a single line

Explanation

DS=³a³ḍaDṫ³DLC¤Ḍ=³ø1#
                  ø1#  Evaluate the condition before this and increment a counter until it is met then output the counter                     
D                      Digits of incremented variable as a list
 S                     Sum
  =³                   Equals argument of program?
    a                  Logical and
     ³ḍ                Does arg divide incremented variable?
       a               Logical and
        Dṫ     Ḍ       Last n digits of inc. var. where n is number of digits in program input
          ³DLC         1 - (number of digits of program input)
              ¤        Book ends above nilad
                =³     Equals program input?

This took me many hours to write because I'm learning Jelly but now that I'm done I'm so satisfied. For a long time I didn't realize I needed the ¤ and I just couldn't get it to work. Looking at [this][1] well explained code helped me seal the deal. Lots of other Jelly answers in PPCG guided me too.

deleted 29 characters in body
Source Link
dylnan
  • 5.4k
  • 2
  • 16
  • 33

Jelly, 22 bytes

DS=³a³ḍaDṫ³DLC¤Ḍ=³
Ç1#

Try it online!

Explanation

Ç1#                    Main Link

Ç                      Calls first link as a monad
 1#                    Count up and stop when you get first match 

First Link:

DS=³a³ḍaDṫ³DLC¤Ḍ=³     This is what Ç calls
                       
D                      Digits of incremented variable as a list
 S                     Sum
  =³                   Equals argument of program?
    a                  Logical and
     ³ḍ                Does arg divide incremented variable?
       a               Logical and
        Dṫ     Ḍ       Last n digits of inc. var. where n is number of digits in program input
          ³DLC         1 - (number of digits of program input)
              ¤        Book ends above nilad
                =³     Equals program input?

When all three conditionals in the first link are met the loop ends and outputs which iteration number it is.

This took me many hours to write because I'm learning Jelly but now that I'm done I'm so satisfied. For a long time I didn't realize I needed the ¤ and I just couldn't get it to work. Looking at this with it's thorough explanation gavewell explained code helped me seal the last piece of knowledge I neededdeal. Lots of other Jelly answers in PPCG helpedguided me too.

Jelly, 22 bytes

DS=³a³ḍaDṫ³DLC¤Ḍ=³
Ç1#

Try it online!

Explanation

Ç1#                    Main Link

Ç                      Calls first link as a monad
 1#                    Count up and stop when you get first match 

First Link:

DS=³a³ḍaDṫ³DLC¤Ḍ=³     This is what Ç calls
                       
D                      Digits of incremented variable as a list
 S                     Sum
  =³                   Equals argument of program?
    a                  Logical and
     ³ḍ                Does arg divide incremented variable?
       a               Logical and
        Dṫ     Ḍ       Last n digits of inc. var. where n is number of digits in program input
          ³DLC         1 - (number of digits of program input)
              ¤        Book ends above nilad
                =³     Equals program input?

When all three conditionals in the first link are met the loop ends and outputs which iteration number it is.

This took me many hours to write because I'm learning Jelly but now that I'm done I'm so satisfied. For a long time I didn't realize I needed the ¤ and I just couldn't get it to work. Looking at this with it's thorough explanation gave me the last piece of knowledge I needed. Lots of other Jelly answers in PPCG helped too.

Jelly, 22 bytes

DS=³a³ḍaDṫ³DLC¤Ḍ=³
Ç1#

Try it online!

Explanation

Ç1#                    Main Link

Ç                      Calls first link as a monad
 1#                    Count up and stop when you get first match 

First Link:

DS=³a³ḍaDṫ³DLC¤Ḍ=³     This is what Ç calls
                       
D                      Digits of incremented variable as a list
 S                     Sum
  =³                   Equals argument of program?
    a                  Logical and
     ³ḍ                Does arg divide incremented variable?
       a               Logical and
        Dṫ     Ḍ       Last n digits of inc. var. where n is number of digits in program input
          ³DLC         1 - (number of digits of program input)
              ¤        Book ends above nilad
                =³     Equals program input?

When all three conditionals in the first link are met the loop ends and outputs which iteration number it is.

This took me many hours to write because I'm learning Jelly but now that I'm done I'm so satisfied. For a long time I didn't realize I needed the ¤ and I just couldn't get it to work. Looking at this well explained code helped me seal the deal. Lots of other Jelly answers in PPCG guided me too.

Source Link
dylnan
  • 5.4k
  • 2
  • 16
  • 33

Jelly, 22 bytes

DS=³a³ḍaDṫ³DLC¤Ḍ=³
Ç1#

Try it online!

Explanation

Ç1#                    Main Link

Ç                      Calls first link as a monad
 1#                    Count up and stop when you get first match 

First Link:

DS=³a³ḍaDṫ³DLC¤Ḍ=³     This is what Ç calls
                       
D                      Digits of incremented variable as a list
 S                     Sum
  =³                   Equals argument of program?
    a                  Logical and
     ³ḍ                Does arg divide incremented variable?
       a               Logical and
        Dṫ     Ḍ       Last n digits of inc. var. where n is number of digits in program input
          ³DLC         1 - (number of digits of program input)
              ¤        Book ends above nilad
                =³     Equals program input?

When all three conditionals in the first link are met the loop ends and outputs which iteration number it is.

This took me many hours to write because I'm learning Jelly but now that I'm done I'm so satisfied. For a long time I didn't realize I needed the ¤ and I just couldn't get it to work. Looking at this with it's thorough explanation gave me the last piece of knowledge I needed. Lots of other Jelly answers in PPCG helped too.