Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Did I misunderstand your question?

Because numbers containing 4 & 9 exist between 1 and 125. Those must be excluded. Therefore you must go to the number 186 to reach a collection of 125 numbers that do not contain 4 & 9.

Another way to think of it. Count the first 125 prime numbers. The answer is 691.
Thanks. Yeah I meant the 300. I guess you just put in a random number well above 186.
 
  • Like
Reactions: Gutwrench
Excel Macro

Code:
Sub Macro1()
Dim Verification As String
Counter = 0

Do While Counter < 125
  For Rooms = 1 To 500
    Verification = CStr(Rooms)
    If InStr(Verification, "4") Or InStr(Verification, "9") Then
       'Do Nothing
    Else
        Counter = Counter + 1
        If Counter = 125 Then
            Worksheets("Sheet1").Range("A1") = Rooms
        End If
    End If
 Next
Loop
End Sub

My Result is 186

Excel Verification
  1. Fill Column A with 1 to 500 in Text Format (A1 contains 1, A2 contains 2... etc until A500 which contains 500)
  2. On Cell B1 enter the following formula : =IF(COUNT(FIND({4,9},A1)),"NO","YES") and copy and paste it from B2 to B500. Each cell in the B column should contain "NO" for rooms that have to be excluded as they contain either 4 or 9, and YES for rooms that should be included.
  3. Go to C186 (corresponding to Room number 186) and enter the formula =COUNTIF(B1:B186,"YES") which will count all the YES (rooms that should be included) from B1 to B186. The result is 125, which means 125 included rooms have been counted, hence the correct room # is 186.
Edit: Macro reduced by a couple of lines
 
Last edited:
I read about it years ago. I've replied to some threads in the Mac Programming forum that involve Project Euler questions. I just searched there for "Euler" and found a couple dozen posts, but not many with my replies. I did recognize some of the Euler threads, and can see why I didn't reply. I can also see why I did reply in some threads mentioning "Euler".

If I were a beginning programmer, or needed to hone my skills, then Project Euler problems would likely be useful. The two reasons I say this are:
1. The problems are clearly stated.
2. It's easy to find other's solutions.

The thing is, I'm not a beginner: see my numerous posts in Mac Programming. I apply my programming skills almost every day, to solve actual problems in the project I'm working on. If I want a diversion, solving more programming problems isn't really that appealing, since the result has no use for me, nor is the entertainment factor really present. For me, it's not entertaining if it's exactly like work. If I'm going to do something exactly like work, I'd rather do actual work instead of artificial work.

If I were learning a completely new language, then Project Euler might be useful to me. Then again, I already have a whole lot of other programs I've written, so I'd probably just rewrite one of them in the new language. I already have the source, and can see the expected output, so starting from scratch with just a problem statement might not be as useful as doing a conversion.
That makes sense. I didn't mean to imply that you needed programming practice, and in fairness to ProjectEuler, a lot of the problems past, say, #60 are more mathematics based than programing.
 
Excel Verification
  1. Fill Column A with 1 to 500 in Text Format (A1 contains 1, A2 contains 2... etc until A500 which contains 500)
  2. On Cell B1 enter the following formula : =IF(COUNT(FIND({4,9},A1)),"NO","YES") and copy and paste it from B2 to B500. Each cell in the B column should contain "NO" for rooms that have to be excluded as they contain either 4 or 9, and YES for rooms that should be included.
  3. Go to C186 (corresponding to Room number 186) and enter the formula =COUNTIF(B1:B186,"YES") which will count all the YES (rooms that should be included) from B1 to B186. The result is 125, which means 125 included rooms have been counted, hence the correct room # is 186.
Edit: Macro reduced by a couple of lines

I’m an excel novice but I’d replace step 3 with filtering for yes. I’m lazy. :(
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.