Here's the problem:
If the numbers 1 to 5 are written out in words: one, two, three, four, five; there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters.
And my solution:
+ Code Snippetsync on
total = 11
for i = 1 to 999
cls
if len(str$(i)) = 1
place1$ = mid$(str$(i),1)
endif
if len(str$(i)) = 2
place1$ = mid$(str$(i),2)
place2$ = mid$(str$(i),1)
endif
if len(str$(i)) = 3
place1$ = mid$(str$(i),3)
place2$ = mid$(str$(i),2)
place3$ = mid$(str$(i),1)
endif
if len(str$(i)) = 4
place1$ = mid$(str$(i),4)
place2$ = mid$(str$(i),3)
place3$ = mid$(str$(i),2)
place4$ = mid$(str$(i),1)
endif
text 70,10,place1$
text 50,10,place2$
text 30,10,place3$
text 10,10,place4$
if place1$ = "1" then inc total,3
if place1$ = "2" then inc total,3
if place1$ = "3" then inc total,5
if place1$ = "4" then inc total,4
if place1$ = "5" then inc total,4
if place1$ = "6" then inc total,3
if place1$ = "7" then inc total,5
if place1$ = "8" then inc total,5
if place1$ = "9" then inc total,4
if place2$ = "1"
IF place1$ = "0" then inc total,3
IF place1$ = "8" then inc total,3
IF place1$ = "1" then inc total,3
if place1$ = "2" then inc total,3
if place1$ = "3" then inc total,3
if place1$ = "5" then inc total,3
IF place1$ <> "0" AND place1$ <> "8" AND place1$ <> "1" AND place1$ <> "2" AND place1$ <> "3" AND place1$ <> "5" then inc total,4
endif
if place2$ = "2" then inc total,6
if place2$ = "3" then inc total,6
if place2$ = "4" then inc total,5
if place2$ = "5" then inc total,5
if place2$ = "6" then inc total,5
if place2$ = "7" then inc total,7
if place2$ = "8" then inc total,6
if place2$ = "9" then inc total,6
if place3$ <> "" AND place3$ <> "0"
if place2$ <> "0" OR place1$ <> "0" then inc total,3
endif
if place3$ = "1" then inc total,10
if place3$ = "2" then inc total,10
if place3$ = "3" then inc total,12
if place3$ = "4" then inc total,11
if place3$ = "5" then inc total,11
if place3$ = "6" then inc total,10
if place3$ = "7" then inc total,12
if place3$ = "8" then inc total,12
if place3$ = "9" then inc total,11
`should be good
text 50,50,"TOTAL: " + str$(total)
sync : sync
next i
text 50,50,"TOTAL: " + str$(total)
sync : sync
wait key
That seems like a really hard way to have solved it but it seems to be the only way to code the solution. Anyone else know any otherways to do it that are more direct and dont use as many long lists?