Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
54
Task/Vampire-number/11l/vampire-number.11l
Normal file
54
Task/Vampire-number/11l/vampire-number.11l
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
-V Pow10 = (0..18).map(n -> Int64(10) ^ n)
|
||||
|
||||
F isOdd(n)
|
||||
R (n [&] 1) != 0
|
||||
|
||||
F fangs(n)
|
||||
[(Int64, Int64)] r
|
||||
|
||||
V nDigits = sorted(String(n))
|
||||
I isOdd(nDigits.len)
|
||||
R r
|
||||
|
||||
V fangLen = nDigits.len I/ 2
|
||||
V inf = Pow10[fangLen - 1]
|
||||
L(d) inf .< inf * 10
|
||||
I n % d != 0
|
||||
L.continue
|
||||
V q = n I/ d
|
||||
I q < d
|
||||
R r
|
||||
V dDigits = String(d)
|
||||
V qDigits = String(q)
|
||||
I qDigits.len > fangLen
|
||||
L.continue
|
||||
I qDigits.len < fangLen
|
||||
R r
|
||||
I nDigits != sorted(dDigits‘’qDigits)
|
||||
L.continue
|
||||
I dDigits.last != ‘0’ | qDigits.last != ‘0’
|
||||
r.append((d, q))
|
||||
|
||||
R r
|
||||
|
||||
print(‘First 25 vampire numbers with their fangs:’)
|
||||
V count = 0
|
||||
V n = 10
|
||||
V limit = 100
|
||||
L count != 25
|
||||
V fangList = fangs(n)
|
||||
I !fangList.empty
|
||||
count++
|
||||
print((‘#2: #6 =’.format(count, n))‘ ’fangList.map(it -> ‘#3 x #3’.format(it[0], it[1])).join(‘ = ’))
|
||||
n++
|
||||
I n == limit
|
||||
n *= 10
|
||||
limit *= 10
|
||||
|
||||
print()
|
||||
L(n) [16'758'243'290'880, 24'959'017'348'650, 14'593'825'548'650]
|
||||
V fangList = fangs(n)
|
||||
I fangList.empty
|
||||
print(n‘ is not vampiric.’)
|
||||
E
|
||||
print(n‘ = ’fangList.map(it -> ‘#. x #.’.format(it[0], it[1])).join(‘ = ’))
|
||||
Loading…
Add table
Add a link
Reference in a new issue