How to resolve the algorithm Esthetic numbers step by step in the Arturo programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Esthetic numbers step by step in the Arturo programming language
Table of Contents
Problem Statement
An esthetic number is a positive integer where every adjacent digit differs from its neighbour by 1.
These examples are nominally in base 10 but the concept extends easily to numbers in other bases. Traditionally, single digit numbers are included in esthetic numbers; zero may or may not be. For our purposes, for this task, do not include zero (0) as an esthetic number. Do not include numbers with leading zeros. Esthetic numbers are also sometimes referred to as stepping numbers.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Esthetic numbers step by step in the Arturo programming language
Source code in the arturo programming language
esthetic?: function [n, b][
if n=0 -> return false
k: n % b
l: n / b
while [l>0][
j: l % b
if 1 <> abs k-j -> return false
l: l / b
k: j
]
return true
]
HEX: "0000000000ABCDEF"
getHex: function [ds][
map ds 'd [
(d < 10)? -> to :string d
-> to :string HEX\[d]
]
]
findEsthetics: function [base][
limDown: base * 4
limUp: base * 6
cnt: 0
i: 1
result: new []
while [cnt < limUp][
if esthetic? i base [
cnt: cnt + 1
if cnt >= limDown ->
'result ++ join getHex digits.base: base i
]
i: i + 1
]
print ["Base" base "->" (to :string limDown)++"th" "to" (to :string limUp)++"th" "esthetic numbers:"]
print result
print ""
]
loop 2..16 'bs ->
findEsthetics bs
print "Esthetic numbers between 1000 and 9999:"
loop split.every: 16 select 1000..9999 'num -> esthetic? num 10 'row [
print map to [:string] row 'item -> pad item 4
]
You may also check:How to resolve the algorithm Abundant odd numbers step by step in the jq programming language
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the Limbo programming language
You may also check:How to resolve the algorithm Find the missing permutation step by step in the Arturo programming language
You may also check:How to resolve the algorithm Formal power series step by step in the D programming language
You may also check:How to resolve the algorithm Sum multiples of 3 and 5 step by step in the AppleScript programming language