Happy Monday!
Over the weekend there was a discussion of bad programmers in the work force over on Hacker News. One comment suggested that several employed engineers couldn't figure out the number of lowercase A's in a string. So today's challenge is to find the number of lowercase A's in this post.
Note: you don't have to count the A's in the html for the link to the comment.
Comments:
Kevin Benton - 9 years, 9 months ago
I got 15
reply permalink
asheehan - 9 years, 9 months ago
Here is the main logic in Ruby: ``` input = "It is, regrettably, not the case that all people who work as software engineers can e.g. code a for loop which counts the numbers of lower-case As in a string. This is true even if you spot them the syntax for a for loop and finding the Nth character in a string. It is equally true if you allow them to complete the task in isolation, at their own computer, given an arbitrary amount of time to complete it.A"
findChar = 'a' counter = 0 i = 0 while (i = input.index(findChar, i+1)) and (i < input.length) do counter += 1 end
p counter ```
reply permalink
asheehan - 9 years, 9 months ago
shoot, formatted properly
reply permalink
nrobinson - 9 years, 9 months ago
I got 11
reply permalink
Zekaykay - 9 years, 9 months ago
<?php $text = '... Here is the string ...';
$result = substr_count($text,'a');
echo $result;
reply permalink
Jt - 9 years, 9 months ago
JavaScript, I got 15.
reply permalink
Anonymous - 9 years, 9 months ago
I don't feel like scraping the text off the webpage, so I'm just copying and pasting into my crude Python solution.
Perhaps if I'm motivated later, I'll make a nicer version that doesn't have hard coded text. For now, I want to get caught up again.
reply permalink