How to resolve the algorithm Eban numbers step by step in the Scala programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Eban numbers step by step in the Scala programming language
Table of Contents
Problem Statement
An eban number is a number that has no letter e in it when the number is spelled in English. Or more literally, spelled numbers that contain the letter e are banned.
The American version of spelling numbers will be used here (as opposed to the British). 2,000,000,000 is two billion, not two milliard.
Only numbers less than one sextillion (1021) will be considered in/for this task. This will allow optimizations to be used.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Eban numbers step by step in the Scala programming language
Source code in the scala programming language
object EbanNumbers {
class ERange(s: Int, e: Int, p: Boolean) {
val start: Int = s
val end: Int = e
val print: Boolean = p
}
def main(args: Array[String]): Unit = {
val rgs = List(
new ERange(2, 1000, true),
new ERange(1000, 4000, true),
new ERange(2, 10000, false),
new ERange(2, 100000, false),
new ERange(2, 1000000, false),
new ERange(2, 10000000, false),
new ERange(2, 100000000, false),
new ERange(2, 1000000000, false)
)
for (rg <- rgs) {
if (rg.start == 2) {
println(s"eban numbers up to an including ${rg.end}")
} else {
println(s"eban numbers between ${rg.start} and ${rg.end}")
}
var count = 0
for (i <- rg.start to rg.end) {
val b = i / 1000000000
var r = i % 1000000000
var m = r / 1000000
r = i % 1000000
var t = r / 1000
r %= 1000
if (m >= 30 && m <= 66) {
m %= 10
}
if (t >= 30 && t <= 66) {
t %= 10
}
if (r >= 30 && r <= 66) {
r %= 10
}
if (b == 0 || b == 2 || b == 4 || b == 6) {
if (m == 0 || m == 2 || m == 4 || m == 6) {
if (t == 0 || t == 2 || t == 4 || t == 6) {
if (r == 0 || r == 2 || r == 4 || r == 6) {
if (rg.print) {
print(s"$i ")
}
count += 1
}
}
}
}
}
if (rg.print) {
println()
}
println(s"count = $count")
println()
}
}
}
You may also check:How to resolve the algorithm Guess the number step by step in the Dart programming language
You may also check:How to resolve the algorithm Weird numbers step by step in the Crystal programming language
You may also check:How to resolve the algorithm Four bit adder step by step in the Elixir programming language
You may also check:How to resolve the algorithm Color quantization step by step in the Python programming language
You may also check:How to resolve the algorithm Arrays step by step in the langur programming language