How to resolve the algorithm Largest number divisible by its digits step by step in the Ring programming language
How to resolve the algorithm Largest number divisible by its digits step by step in the Ring 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 Ring programming language
Source code in the ring programming language
# Project : Largest number divisible by its digits
for n = 9867000 to 9867400
numbers = list(9)
for t=1 to 9
numbers[t] = 0
next
flag = 1
flag2 = 1
flag3 = 1
str=string(n)
for m=1 to len(str)
if number(str[m]) > 0
numbers[number(str[m])] = numbers[number(str[m])] + 1
else
flag2 = 0
ok
next
if flag2 = 1
for p=1 to 9
if numbers[p] = 0 or numbers[p] = 1
else
flag = 0
ok
next
if flag = 1
for x=1 to len(str)
if n%(number(str[x])) != 0
flag3 = 0
ok
next
if flag3 = 1
see n + nl
ok
ok
ok
next
You may also check:How to resolve the algorithm Classes step by step in the X86-64 Assembly programming language
You may also check:How to resolve the algorithm URL encoding step by step in the Delphi programming language
You may also check:How to resolve the algorithm Topic variable step by step in the Axe programming language
You may also check:How to resolve the algorithm Strip a set of characters from a string step by step in the Nemerle programming language
You may also check:How to resolve the algorithm Power set step by step in the Rust programming language