Lower Count

Discussion of challenges you have already solved
Knochnkopf
Posts: 2
Joined: Fri Oct 22, 2010 4:54 pm

Post by Knochnkopf »

Code: Select all

echo 'mQmPtphqGrboHh.....' | awk '{print $0, gsub("[a-z]", ".")}'
Peredur
Posts: 1
Joined: Thu May 19, 2011 8:40 am

Solved with Ruby

Post by Peredur »

I did it also with Ruby:

text = "mQmPtphqGrboHhmgaqVhCdwTwignlQvjIopDqVpgaNrwkAzVcnkHyNiPdSmgJmgrPiMjpnjdbuPucHnouwfKuPcybromnmbvfxJqRnnOvWsceZeYzRyqnkaaFsffjenxoIhqHnIzorlOdwZoxYmAuNwNnRppguwidvbtOqdbUngpZdbGqwYjfpLzPjRtwVwEqBbYmCqbKwuziCoEwPsIkJgruTbhdyWpvPztAodufjZxLaZcUeFaklSmeRfolohVbXoDfIqMqgIrQhzedqZlFwaBndQkQexBdLsCfXebrEfiOnSgYquyaqohxoDmLdDhwoOpgtkuRzeYziuvnuvnUuOtqasZueYpKfAkmKcJcWeocQvJguVsZfVovgrztAiryZivHqyMjoLyJdklKifmoWeOjVnogiiaBzDfrsWlOeAzPxltamqQiujZrpZrUcIlyktdJbhmNpDbltOlLnAqVhcxgObghpdcScgIiayqygUgwatiEzgzTsZgApUbbPynLfbzehzWsxcPbdcdfMucsCzjkWvjhMkiWuHfquqrcKwedqghiyHyMkSayRegeJcGw"

count = 0

for i in 0...text.size
if (text.eql?(text.downcase()))
count+=1
end
end

puts "I counted #{count} lower case letters"
gunn4r
Posts: 6
Joined: Thu Aug 11, 2011 11:44 pm

Post by gunn4r »

I did it in vim :%s/[A-Z]//g

and looked at the character count in the bottom right corner.
the_austria
Posts: 5
Joined: Sun Mar 11, 2012 2:57 pm
Contact:

Post by the_austria »

I did it in JS with RegExp

Code: Select all

var str="mQmPtphqGrboHhmgaqVhCdwTwignlQvjIopDqVpgaNrwkAzVcnkHyNiPdSmgJ
mgrPiMjpnjdbuPucHnouwfKuPcybromnmbvfxJqRnnOvWsceZeYzRyqnkaaFsffjenxoIhqH
nIzorlOdwZoxYmAuNwNnRppguwidvbtOqdbUngpZdbGqwYjfpLzPjRtwVwEqBbYmCqbKw
uziCoEwPsIkJgruTbhdyWpvPztAodufjZxLaZcUeFaklSmeRfolohVbXoDfIqMqgIrQhzedqZl
FwaBndQkQexBdLsCfXebrEfiOnSgYquyaqohxoDmLdDhwoOpgtkuRzeYziuvnuvnUuOtqas
ZueYpKfAkmKcJcWeocQvJguVsZfVovgrztAiryZivHqyMjoLyJdklKifmoWeOjVnogiiaBzDfrs
WlOeAzPxltamqQiujZrpZrUcIlyktdJbhmNpDbltOlLnAqVhcxgObghpdcScgIiayqygUgwatiE
zgzTsZgApUbbPynLfbzehzWsxcPbdcdfMucsCzjkWvjhMkiWuHfquqrcKwedqghiyHyMkSay
RegeJcGw"; 

document.write (str.match(/[a-z]/g).length);
pedromalta
Posts: 22
Joined: Wed Apr 13, 2011 12:00 am
Location: Vila Velha
Contact:

Post by pedromalta »

Simpla java code

Code: Select all

	public int lowerCaseCount(String string){
		int pivot = 0, sum = 0;
		
		while (true){
			try{
				if(Character.isLowerCase(string.charAt(pivot))){
					sum ++;					
				}
				pivot++;
				
			}catch (StringIndexOutOfBoundsException e) {
				return sum;
			}
			
		}		
		
	}
sudo apt-get a life
AgRaven
Posts: 13
Joined: Sun Feb 24, 2013 8:27 am

Post by AgRaven »

Hmm... I don't see a c++ code, so I'll throw mine up... but man it takes a lot more structure than the python or ruby examples I see here:

Code: Select all

#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;

int main ()
{
    string s=" ** string deleted for forum sanity **";
    int j=s.length();
    long l=0;
    for (int i=0; i<=j; i++)
    {
        char c=s[i];
        if (islower(c))
            l++;
    }
    cout << l;
    return 0;
}
Post Reply