Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
62
Task/Esthetic-numbers/FreeBASIC/esthetic-numbers.basic
Normal file
62
Task/Esthetic-numbers/FreeBASIC/esthetic-numbers.basic
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
dim shared as string*16 digits = "0123456789ABCDEF"
|
||||
|
||||
function get_digit( n as uinteger ) as string
|
||||
return mid(digits, n+1, 1)
|
||||
end function
|
||||
|
||||
function find_digit( s as string ) as integer
|
||||
for i as uinteger = 1 to len(digits)
|
||||
if s = mid(digits, i, 1) then return i
|
||||
next i
|
||||
return -999
|
||||
end function
|
||||
|
||||
sub make_base( byval n as uinteger, bse as uinteger, byref ret as string )
|
||||
if n = 0 then ret = "0" else ret = ""
|
||||
dim as uinteger m
|
||||
while n > 0
|
||||
m = n mod bse
|
||||
ret = mid(digits, m+1, 1) + ret
|
||||
n = (n - m)/bse
|
||||
wend
|
||||
end sub
|
||||
|
||||
function is_esthetic( number as string ) as boolean
|
||||
if number = "0" then return false
|
||||
if len(number) = 1 then return true
|
||||
dim as integer curr = find_digit( left(number,1) ), last, i
|
||||
for i = 2 to len(number)
|
||||
last = curr
|
||||
curr = find_digit( mid(number, i, 1) )
|
||||
if abs( last - curr ) <> 1 then return false
|
||||
next i
|
||||
return true
|
||||
end function
|
||||
|
||||
dim as uinteger b, c
|
||||
dim as ulongint i
|
||||
dim as string number
|
||||
for b = 2 to 16
|
||||
print "BASE ";b
|
||||
i = 0 : c = 0
|
||||
while c <= 6*b
|
||||
i += 1
|
||||
make_base i, b, number
|
||||
if is_esthetic( number ) then
|
||||
c += 1
|
||||
if c >= 4*b then print number;" ";
|
||||
end if
|
||||
wend
|
||||
print
|
||||
next b
|
||||
print "BASE TEN"
|
||||
for i = 1000 to 9999
|
||||
make_base i, 10, number
|
||||
if is_esthetic(number) then print number;" ";
|
||||
next i
|
||||
print
|
||||
print "STRETCH GOAL"
|
||||
for i = 100000000 to 130000000
|
||||
make_base i, 10, number
|
||||
if is_esthetic(number) then print number;" ";
|
||||
next i
|
||||
Loading…
Add table
Add a link
Reference in a new issue