/112.lua
Lua | 39 lines | 34 code | 4 blank | 1 comment | 7 complexity | 4159cc550c2a49e3ebcbecacccbc3212 MD5 | raw file
1-- solved 2 3function is_bouncy(n) 4 local s = tostring(n) 5 local sl = string.len(s) 6 local i 7 local dir = 0 8 local p = string.byte(s, 1) 9 for i = 2, sl do 10 local p2 = string.byte(s, i) 11 if p2>p then 12 if dir<0 then return true end 13 dir = 1 14 elseif p2<p then 15 if dir>0 then return true end 16 dir = -1 17 end 18 p = p2 19 end 20 return false 21end 22 23assert(is_bouncy(1232)) 24assert(not is_bouncy(1233)) 25 26a=100 27b=0 28 29for i=101,10000000 do 30 if not is_bouncy(i) then 31 a = a + 1 32 else 33 b = b + 1 34 end 35 if (a/(a+b))<=0.01 then 36 print(i, a, b, a/(a+b)) 37 break 38 end 39end