How to resolve the algorithm Eban numbers step by step in the FreeBASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Eban numbers step by step in the FreeBASIC 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 FreeBASIC programming language
Source code in the freebasic programming language
' Eban_numbers
' Un número eban es un número que no tiene la letra e cuando el número está escrito en inglés.
' O más literalmente, los números escritos que contienen la letra e están prohibidos.
'
' Usaremos la versión americana de los números de ortografía (a diferencia de los británicos).
' 2000000000 son dos billones, no dos millardos (mil millones).
'
Data 2, 1000, 1
Data 1000, 4000, 1
Data 2, 10000, 0
Data 2, 100000, 0
Data 2, 1000000, 0
Data 2, 10000000, 0
Data 2, 100000000, 0
Data 0, 0, 0
Dim As Double tiempo = Timer
Dim As Integer start, ended, printable, count
Dim As Long i, b, r, m, t
Do
Read start, ended, printable
If start = 0 Then Exit Do
If start = 2 Then
Print "eban numbers up to and including"; ended; ":"
Else
Print "eban numbers between "; start; " and "; ended; " (inclusive):"
End If
count = 0
For i = start To ended Step 2
b = Int(i / 1000000000)
r = (i Mod 1000000000)
m = Int(r / 1000000)
r = (i Mod 1000000)
t = Int(r / 1000)
r = (r Mod 1000)
If m >= 30 And m <= 66 Then m = (m Mod 10)
If t >= 30 And t <= 66 Then t = (t Mod 10)
If r >= 30 And r <= 66 Then r = (r Mod 10)
If b = 0 Or b = 2 Or b = 4 Or b = 6 Then
If m = 0 Or m = 2 Or m = 4 Or m = 6 Then
If t = 0 Or t = 2 Or t = 4 Or t = 6 Then
If r = 0 Or r = 2 Or r = 4 Or r = 6 Then
If printable Then Print i;
count += 1
End If
End If
End If
End If
Next i
If printable Then Print
Print "count = "; count & Chr(10)
Loop
tiempo = Timer - tiempo
Print "Run time: " & (tiempo) & " seconds."
End
You may also check:How to resolve the algorithm Loops/Wrong ranges step by step in the 11l programming language
You may also check:How to resolve the algorithm Magic 8-ball step by step in the Arturo programming language
You may also check:How to resolve the algorithm Linear congruential generator step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Idoneal numbers step by step in the C programming language
You may also check:How to resolve the algorithm Bitwise operations step by step in the Pike programming language