Numeros Autodescriptivos
Publicado por lrcvs (17 intervenciones) el 24/08/2010 19:13:40
'Numeros autodescriptivos
'lrcvs 24.08.10
'Hecho en FreeBasic
dim a, d1, d2, g as string
dim b, r, e1, e2, j, s, l, f, t as integer
dim k, n as double
cls
a$ = "123" '<<< numero a probar
b = len (a$)
dim c (0 to 9)
dim z (0 to 9)
for r = 1 to len (a$)
d1$ = mid$(a$,r,1)
e1 = val (d1$)
c(r-1) = e1
f = f + e1
next r
k = val (string$ (f, "9"))
for n = 1 to k
for r = 1 to len (str$(n))
d2$ = mid$(str$(n),r,1)
e2 = val (d2$)
z(e2) = z(e2) + 1
next r
for s = 0 to 9
if c(s) = z(s) then j = j + 1
next s
if j = 10 then t = t + 1 : print n; " >"; t
j = 0
for l = 0 to 9
z(l) = 0
next l
next n
print "Fin"
sleep
end
'lrcvs 24.08.10
'Hecho en FreeBasic
dim a, d1, d2, g as string
dim b, r, e1, e2, j, s, l, f, t as integer
dim k, n as double
cls
a$ = "123" '<<< numero a probar
b = len (a$)
dim c (0 to 9)
dim z (0 to 9)
for r = 1 to len (a$)
d1$ = mid$(a$,r,1)
e1 = val (d1$)
c(r-1) = e1
f = f + e1
next r
k = val (string$ (f, "9"))
for n = 1 to k
for r = 1 to len (str$(n))
d2$ = mid$(str$(n),r,1)
e2 = val (d2$)
z(e2) = z(e2) + 1
next r
for s = 0 to 9
if c(s) = z(s) then j = j + 1
next s
if j = 10 then t = t + 1 : print n; " >"; t
j = 0
for l = 0 to 9
z(l) = 0
next l
next n
print "Fin"
sleep
end
Valora esta pregunta
0