How to resolve the algorithm Largest number divisible by its digits step by step in the EasyLang programming language
How to resolve the algorithm Largest number divisible by its digits step by step in the EasyLang programming language
Table of Contents
Problem Statement
Find the largest base 10 integer whose digits are all different, and is evenly divisible by each of its individual digits.
These numbers are also known as Lynch-Bell numbers, numbers n such that the (base ten) digits are all different (and do not include zero) and n is divisible by each of its individual digits.
135 is evenly divisible by 1, 3, and 5.
Note that the digit zero (0) can not be in the number as integer division by zero is undefined. The digits must all be unique so a base ten number will have at most 9 digits. Feel free to use analytics and clever algorithms to reduce the search space your example needs to visit, but it must do an actual search. (Don't just feed it the answer and verify it is correct.)
Do the same thing for hexadecimal.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Largest number divisible by its digits step by step in the EasyLang programming language
Source code in the easylang programming language
global found dig[] .
proc test . .
for i to len dig[]
n = n * 10 + dig[i]
.
for i to len dig[]
if n mod dig[i] <> 0
return
.
.
found = 1
print n
.
len use[] 9
proc perm pos . .
if found = 1
return
.
for i = 9 downto 1
dig[pos] = i
if use[i] = 0
use[i] = 1
if pos = len dig[]
test
else
perm pos + 1
.
use[i] = 0
.
.
.
for ndig = 9 downto 1
len dig[] ndig
perm 1
.
You may also check:How to resolve the algorithm 21 game step by step in the C++ programming language
You may also check:How to resolve the algorithm Loops/Infinite step by step in the Frink programming language
You may also check:How to resolve the algorithm Angle difference between two bearings step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Square but not cube step by step in the jq programming language
You may also check:How to resolve the algorithm Priority queue step by step in the M2000 Interpreter programming language