Interesting... So why are you even bothering with numbers above 125?
Anyway, if anyone is interested, I worked out these two Swift versions. They both return 186.
Code:
var roomNumber = 1, x = 0
repeat {
x += 1
if String(x).contains("4") || String(x).contains("9") {
continue
}
roomNumber += 1
} while roomNumber <= 125
Code:
var currentRoomNo = 1, n = 0
while currentRoomNo <= 125 {
n += 1
if String(n).contains("4") || String(n).contains("9") {
continue
}
currentRoomNo += 1
}
I am still a bit confused though because when i count on paper, i.e. 4, 9, 14, 19, 24, 29.....40,41,42,43,44,45,46,47,48,49...84,89, 90,91,92,93,94,95,96,97,98,99...124, the total number of 4s and 9s is 45 but (125 + 45) obviously isn't the answer.
Also, I should tell you that the answer for this test was actually marked correct as
202. Someone said there were a total of 77 4s and 9s. 77 + 125 = 202.
However, that answer seems to be unverified which is very strange. I like you, get 186. I wonder if there is something we are overlooking.