 # CODE GOLF - April 2016 Answers

All answers will be soft deleted once posted and the thread will be locked on Thursday 12 May 2016 to prevent further answers.

Good Luck!

• Re: CODE GOLF - April 2016 Answers

OK, this is my first go... Seems to work. • Re: CODE GOLF - April 2016 Answers

Code
1. Public Function IsPrime(varNum As Long) As Boolean
2. For i = 2 To varNum - 1
3. If (varNum Mod i = 0) Then
4. IsPrime = False
5. Exit Function
6. End If
7. Next
8. IsPrime = IIf((varNum > 9 And (InStr(Right\$(varNum, 1), "024568"))) Or (varNum < 2), False, True)
9. End Function
• Re: CODE GOLF - April 2016 Answers

Realised on looking at the newsletter agin that I missed an important detail in my VBA function submission (changing one character would fix it and I am sure I was taught that 1 is a prime number!), I thought I would have a go at the formula challenge as well.

This will work for row 2, obviously fill down to pick up the relative cell references. Code
1. =IF(ISERROR(FIND(" ",A2,FIND(" ",A2)+1)),"",MID(A2,FIND(" ",A2)+1,1))
• Re: CODE GOLF - April 2016 Answers

With text in F7:

=IF(LEN(F7)-LEN(SUBSTITUTE(F7," ",""))<2,"",MID(F7,FIND(" ",F7)+1,1))