« So here I am... | Main| A little rain... »

I am bumming...

Category
Because of Admin2006 , I missed the last day of the Da Vinci Quest that was running on Google. I realize that I had no chance of winning, but I was enjoying the little puzzles each day. I especially liked the Sudoku like puzzles that used graphics instead of numbers. So I was thinking, as a lot of the blog readers here are programmers, maybe I should start posting little programming puzzles every now, nothing fancy, but it would be fun to see what people come up with. As with any programming challenge, it's really the final result that counts, but sometimes with things like this people come up with amazing solutions. So here is the first of the Friday programming challenges...

Yesterday when driving my car, my mileage hit "49094", a number that reads the same forwards as backwards aka palindrome. Write the smallest (not necessarily the most efficient) amount of lotusscript code you can to return the number of palindromes my cars odometer will display before it gets to 51000 miles"

Post your solutions and anything else you want as a comment

Comments

Gravatar Image1 - I will start the ball rolling with this effort that returns 20.

Function c() As Integer
Dim i, j As Integer
i = 49094
While (i<51000)
If((Left(Cstr(i), 1) = Right(Cstr(i), 1)) & (Mid(Cstr(i), 2, 1) = Mid(Cstr(i), 4,1))) Then
j = j + 1
End If
i = i +1
Wend
c = j
End Function

Gravatar Image2 - Apologies, this is the correct code.

Function c() As Integer
Dim i,j As Integer
i = 49094
j= 0
While (i<51000)
If((Left(Cstr(i), 1) = Right(Cstr(i), 1)) And (Mid(Cstr(i), 2, 1) = Mid(Cstr(i), 4,1))) Then
j= j + 1
End If
i = i +1
Wend
c = j
End Function

Gravatar Image3 - More improvements:

Function c() As Integer
Dim i,j As Integer
i = 49094
While (i<51000)
n = Cstr(i)
If Left(n, 1) = Right(n, 1) And Mid(n, 2, 1) = Mid(n, 4,1) Then
c= c + 1
End If
i = i +1
Wend
End Function

Gravatar Image4 - Or if you are being really pedantic

Function c() as Integer
c=20
End Function

Gravatar Image5 - @4 I guess you're right, but your other efforts are more in linme with what I was thinking

Gravatar Image6 - This is a fun little idea. Here's my 5 second stab at it, I reverse the string and check equivalency.

For x=49094 To 51000
s=Cstr(x)

res=Evaluate(|@For(n := @Length("| + s + |"); n >= 0; n := n - 1; temp2 := temp2 + @Middle("| + s + |";n;1)); temp2;|)

If (res(0)=s) Then
c=c+1
End If
Next

Messagebox("There are " + Cstr(c) + " palindromes")

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::rolleyes:;-)