Skip to main content
Commonmark migration
Source Link

#Befunge, 81 bytes

Befunge, 81 bytes

&>00p0v<!%g0<
v%"d":_>1+:0^
>00g->#^_:0v
0g10g-#^_.@1>
>0p:55+/\:v>
^1+g01%+55_$^

Try it online!

Can handle up to n = 70 at least, after which some values will start overflowing the stack cell size on most implementations, and on those that don't, it'll take so long that it's not worth waiting to find out.

Given those constraints, we don't even bother trying to handle values of n greater than 99, which means we can more easily test if the value ends in n with by simply comparing the value modulo 100 with n.

Below is more detailed breakdown of the code.

Source code with execution paths highlighted

* Read n from stdin and save in memory.
* Initialize the test value v to 0 and start the main loop, incrementing v up front.
* Test if v%n == 0, and if not return to the start of the main loop.
* Test if v%100 == n, and if not return to the start of the main loop.
* Sum the digits in v by repeatedly adding v modulo 10 and dividing v by 10.
* Test if the sum is equal to n, and if not return to the start of the main loop.
* Otherwise output v and exit.

#Befunge, 81 bytes

&>00p0v<!%g0<
v%"d":_>1+:0^
>00g->#^_:0v
0g10g-#^_.@1>
>0p:55+/\:v>
^1+g01%+55_$^

Try it online!

Can handle up to n = 70 at least, after which some values will start overflowing the stack cell size on most implementations, and on those that don't, it'll take so long that it's not worth waiting to find out.

Given those constraints, we don't even bother trying to handle values of n greater than 99, which means we can more easily test if the value ends in n with by simply comparing the value modulo 100 with n.

Below is more detailed breakdown of the code.

Source code with execution paths highlighted

* Read n from stdin and save in memory.
* Initialize the test value v to 0 and start the main loop, incrementing v up front.
* Test if v%n == 0, and if not return to the start of the main loop.
* Test if v%100 == n, and if not return to the start of the main loop.
* Sum the digits in v by repeatedly adding v modulo 10 and dividing v by 10.
* Test if the sum is equal to n, and if not return to the start of the main loop.
* Otherwise output v and exit.

Befunge, 81 bytes

&>00p0v<!%g0<
v%"d":_>1+:0^
>00g->#^_:0v
0g10g-#^_.@1>
>0p:55+/\:v>
^1+g01%+55_$^

Try it online!

Can handle up to n = 70 at least, after which some values will start overflowing the stack cell size on most implementations, and on those that don't, it'll take so long that it's not worth waiting to find out.

Given those constraints, we don't even bother trying to handle values of n greater than 99, which means we can more easily test if the value ends in n with by simply comparing the value modulo 100 with n.

Below is more detailed breakdown of the code.

Source code with execution paths highlighted

* Read n from stdin and save in memory.
* Initialize the test value v to 0 and start the main loop, incrementing v up front.
* Test if v%n == 0, and if not return to the start of the main loop.
* Test if v%100 == n, and if not return to the start of the main loop.
* Sum the digits in v by repeatedly adding v modulo 10 and dividing v by 10.
* Test if the sum is equal to n, and if not return to the start of the main loop.
* Otherwise output v and exit.

Added an explanation.
Source Link
James Holderness
  • 8.9k
  • 2
  • 23
  • 44

#Befunge, 81 bytes

&>00p0v<!%g0<
v%"d":_>1+:0^
>00g->#^_:0v
0g10g-#^_.@1>
>0p:55+/\:v>
^1+g01%+55_$^

Try it online!

Can handle up to n = 70 at least, after which some values will start overflowing the stack cell size on most implementations, and on those that don't, it'll take so long that it's not worth waiting to find out.

Given those constraints, we don't even bother trying to handle values of n greater than 99, which means we can more easily test if the value ends in n with by simply comparing the value modulo 100 with n.

Below is more detailed breakdown of the code.

Source code with execution paths highlighted

* Read n from stdin and save in memory.
* Initialize the test value v to 0 and start the main loop, incrementing v up front.
* Test if v%n == 0, and if not return to the start of the main loop.
* Test if v%100 == n, and if not return to the start of the main loop.
* Sum the digits in v by repeatedly adding v modulo 10 and dividing v by 10.
* Test if the sum is equal to n, and if not return to the start of the main loop.
* Otherwise output v and exit.

#Befunge, 81 bytes

&>00p0v<!%g0<
v%"d":_>1+:0^
>00g->#^_:0v
0g10g-#^_.@1>
>0p:55+/\:v>
^1+g01%+55_$^

Try it online!

#Befunge, 81 bytes

&>00p0v<!%g0<
v%"d":_>1+:0^
>00g->#^_:0v
0g10g-#^_.@1>
>0p:55+/\:v>
^1+g01%+55_$^

Try it online!

Can handle up to n = 70 at least, after which some values will start overflowing the stack cell size on most implementations, and on those that don't, it'll take so long that it's not worth waiting to find out.

Given those constraints, we don't even bother trying to handle values of n greater than 99, which means we can more easily test if the value ends in n with by simply comparing the value modulo 100 with n.

Below is more detailed breakdown of the code.

Source code with execution paths highlighted

* Read n from stdin and save in memory.
* Initialize the test value v to 0 and start the main loop, incrementing v up front.
* Test if v%n == 0, and if not return to the start of the main loop.
* Test if v%100 == n, and if not return to the start of the main loop.
* Sum the digits in v by repeatedly adding v modulo 10 and dividing v by 10.
* Test if the sum is equal to n, and if not return to the start of the main loop.
* Otherwise output v and exit.

Source Link
James Holderness
  • 8.9k
  • 2
  • 23
  • 44

#Befunge, 81 bytes

&>00p0v<!%g0<
v%"d":_>1+:0^
>00g->#^_:0v
0g10g-#^_.@1>
>0p:55+/\:v>
^1+g01%+55_$^

Try it online!