Discussion of challenges you have already solved
Marv
Posts: 17 Joined: Tue Nov 25, 2008 12:58 pm
Post
by Marv » Wed Nov 26, 2008 1:18 am
My Ruby Code:
Code: Select all
result = 0
string = 'mQmPtphqGrboHhmgaqVhCdwTwignlQvjIopDqVpgaNrwkAzVcnkHyNiPdSmgJmgrPiMjpnjdbuPucHnouwfKuPcybromnmbvfxJqRnnOvWsceZeYzRyqnkaaFsffjenxoIhqHnIzorlOdwZoxYmAuNwNnRppguwidvbtOqdbUngpZdbGqwYjfpLzPjRtwVwEqBbYmCqbKwuziCoEwPsIkJgruTbhdyWpvPztAodufjZxLaZcUeFaklSmeRfolohVbXoDfIqMqgIrQhzedqZlFwaBndQkQexBdLsCfXebrEfiOnSgYquyaqohxoDmLdDhwoOpgtkuRzeYziuvnuvnUuOtqasZueYpKfAkmKcJcWeocQvJguVsZfVovgrztAiryZivHqyMjoLyJdklKifmoWeOjVnogiiaBzDfrsWlOeAzPxltamqQiujZrpZrUcIlyktdJbhmNpDbltOlLnAqVhcxgObghpdcScgIiayqygUgwatiEzgzTsZgApUbbPynLfbzehzWsxcPbdcdfMucsCzjkWvjhMkiWuHfquqrcKwedqghiyHyMkSayRegeJcGw'
string.each_byte {|b| result += 1 if b.between?(97,122)}
p result
megabreit
Posts: 141 Joined: Sat Jan 03, 2009 3:33 pm
Post
by megabreit » Sat Jan 03, 2009 8:23 pm
As generic shell code:
Code: Select all
string="mQmPtphqGrboHhmgaqVhCdwTwignlQvjIopDqVpgaNrwkAzVcnkHyNiPdSmgJmgrPiMjpnjdbuPucHnouwfKuPcybromnmbvfxJqRnnOvWsceZeYzRyqnkaaFsffjenxoIhqHnIzorlOdwZoxYmAuNwNnRppguwidvbtOqdbUngpZdbGqwYjfpLzPjRtwVwEqBbYmCqbKwuziCoEwPsIkJgruTbhdyWpvPztAodufjZxLaZcUeFaklSmeRfolohVbXoDfIqMqgIrQhzedqZlFwaBndQkQexBdLsCfXebrEfiOnSgYquyaqohxoDmLdDhwoOpgtkuRzeYziuvnuvnUuOtqasZueYpKfAkmKcJcWeocQvJguVsZfVovgrztAiryZivHqyMjoLyJdklKifmoWeOjVnogiiaBzDfrsWlOeAzPxltamqQiujZrpZrUcIlyktdJbhmNpDbltOlLnAqVhcxgObghpdcScgIiayqygUgwatiEzgzTsZgApUbbPynLfbzehzWsxcPbdcdfMucsCzjkWvjhMkiWuHfquqrcKwedqghiyHyMkSayRegeJcGw"
echo -n $string | sed -e "s/[A-Z]//g"|wc -c
LStrike
Posts: 3 Joined: Tue Nov 18, 2008 7:42 pm
Post
by LStrike » Fri Jan 23, 2009 9:13 pm
Not very beautiful, but it works.
java code:
Code: Select all
public void lowerCase(){
String s = "mQmPtphqGrboHhmgaqVhCdwTwignlQvjIopDqVpgaNrwkAzVcnkHyNiPdSmgJmgrPiMjpnjdbuPucHnouwfKuPcybromnmbvfxJqRnnOvWsceZeYzRyqnkaaFsffjenxoIhqHnIzorlOdwZoxYmAuNwNnRppguwidvbtOqdbUngpZdbGqwYjfpLzPjRtwVwEqBbYmCqbKwuziCoEwPsIkJgruTbhdyWpvPztAodufjZxLaZcUeFaklSmeRfolohVbXoDfIqMqgIrQhzedqZlFwaBndQkQexBdLsCfXebrEfiOnSgYquyaqohxoDmLdDhwoOpgtkuRzeYziuvnuvnUuOtqasZueYpKfAkmKcJcWeocQvJguVsZfVovgrztAiryZivHqyMjoLyJdklKifmoWeOjVnogiiaBzDfrsWlOeAzPxltamqQiujZrpZrUcIlyktdJbhmNpDbltOlLnAqVhcxgObghpdcScgIiayqygUgwatiEzgzTsZgApUbbPynLfbzehzWsxcPbdcdfMucsCzjkWvjhMkiWuHfquqrcKwedqghiyHyMkSayRegeJcGw";
String r = "";
r = s.replaceAll("[A-Z]", "");
System.out.println(r);
System.out.println(r.length());
}
aurora
Posts: 54 Joined: Thu Feb 05, 2009 12:31 pm
Location: Bavaria, Germany
Post
by aurora » Sun Feb 08, 2009 9:26 pm
i too solved it via the regexp
trunx
Posts: 2 Joined: Wed Dec 24, 2008 4:57 pm
Post
by trunx » Thu Jun 18, 2009 6:46 pm
solved in java
Code: Select all
String s = "mQmPtphqGrboHhmgaqVhCdwTwignlQvjIopDqVpgaNrwkAzVcnkHyNiPdSmgJmgrPiMjpnjdbuPucHnouwfKuPcybromnmbvfxJqRnnOvWsceZeYzRyqnkaaFsffjenxoIhqHnIzorlOdwZoxYmAuNwNnRppguwidvbtOqdbUngpZdbGqwYjfpLzPjRtwVwEqBbYmCqbKwuziCoEwPsIkJgruTbhdyWpvPztAodufjZxLaZcUeFaklSmeRfolohVbXoDfIqMqgIrQhzedqZlFwaBndQkQexBdLsCfXebrEfiOnSgYquyaqohxoDmLdDhwoOpgtkuRzeYziuvnuvnUuOtqasZueYpKfAkmKcJcWeocQvJguVsZfVovgrztAiryZivHqyMjoLyJdklKifmoWeOjVnogiiaBzDfrsWlOeAzPxltamqQiujZrpZrUcIlyktdJbhmNpDbltOlLnAqVhcxgObghpdcScgIiayqygUgwatiEzgzTsZgApUbbPynLfbzehzWsxcPbdcdfMucsCzjkWvjhMkiWuHfquqrcKwedqghiyHyMkSayRegeJcGw";
int lowerCount = 0;
int c = 0;
for(int i=0;i < s.length();i++){
c = (int) s.charAt(i);
if(c > 96 && c < 123){
lowerCount ++;
}
}
System.out.println(lowerCount);
}
gfoot
Posts: 269 Joined: Wed Sep 05, 2007 11:34 pm
Location: Brighton, UK
Post
by gfoot » Thu Jun 18, 2009 9:15 pm
Python's pretty concise again:
Code: Select all
print len(filter(str.islower, "..."))
or more modern:
Code: Select all
print sum([c.islower() for c in "..."])
(I didn't realise you could sum collections of bools. 'len' with a conditional list comprehension (replacing the 'filter' earlier) is more obvious to write, but I think this is easier to read.)
teebee
Posts: 89 Joined: Mon Nov 10, 2008 3:21 pm
Location: Germany
Post
by teebee » Thu Jun 18, 2009 9:43 pm
I used a Perl one liner to solve it:
Code: Select all
perl -le '$_="...";print tr/a-z//'
Juampi
Posts: 3 Joined: Wed Jun 10, 2009 12:50 am
Location: Rosario, Argentina
Post
by Juampi » Thu Jun 18, 2009 11:13 pm
text editor + regex
sabretooth
Posts: 61 Joined: Sun Jul 12, 2009 3:13 pm
Post
by sabretooth » Wed Aug 12, 2009 11:05 pm
Ok so it's a while since I solved it but heres my php code anyway:
Code: Select all
<?php
$unsorted = "mQmPtphqGrboHhmgaqVhCdwTwignlQvjIopDqVpgaNrwkAzVcnkHyNiPdSmgJmgrPiMjpnjdbuPucHnouwfKuPcybromnmbvfxJqRnnOvWsceZeYzRyqnkaaFsffjenxoIhqHnIzorlOdwZoxYmAuNwNnRppguwidvbtOqdbUngpZdbGqwYjfpLzPjRtwVwEqBbYmCqbKwuziCoEwPsIkJgruTbhdyWpvPztAodufjZxLaZcUeFaklSmeRfolohVbXoDfIqMqgIrQhzedqZlFwaBndQkQexBdLsCfXebrEfiOnSgYquyaqohxoDmLdDhwoOpgtkuRzeYziuvnuvnUuOtqasZueYpKfAkmKcJcWeocQvJguVsZfVovgrztAiryZivHqyMjoLyJdklKifmoWeOjVnogiiaBzDfrsWlOeAzPxltamqQiujZrpZrUcIlyktdJbhmNpDbltOlLnAqVhcxgObghpdcScgIiayqygUgwatiEzgzTsZgApUbbPynLfbzehzWsxcPbdcdfMucsCzjkWvjhMkiWuHfquqrcKwedqghiyHyMkSayRegeJcGw";
$unsortedlen = strlen($unsorted);
$counter = 0;
for($x = 0; $x < $unsortedlen; $x++)
{
if (ord($unsorted{$x}) > 96)
{
$counter++;
}
}
echo $counter;
?>
sabre
nighthalk
Posts: 41 Joined: Fri Jul 31, 2009 8:22 pm
Post
by nighthalk » Thu Aug 13, 2009 5:25 pm
notepad replace all match case, paste into office for letter count ^_^ i know not efficient but i didnt have to code anything.
s7mahess
Posts: 2 Joined: Fri Jan 09, 2009 9:03 pm
Post
by s7mahess » Wed Jun 30, 2010 7:56 am
Code: Select all
for (int i=0;i<mystr.length();i++){
if (mystr.at(i) <= 122 && mystr.at(i) >=97){
result++;
}
}
Curiosu
Posts: 3 Joined: Fri Aug 27, 2010 12:52 pm
Post
by Curiosu » Sat Aug 28, 2010 9:14 pm
php
Code: Select all
$i=0;
$str=str_split("mQmPtphqGrboHhmgaqVhCdwTwignlQvjIopDqVpgaNrwkAzVcnkHyNiPdSmgJmgrPiMjpnjdbuPucHnouwfKuPcybromnmbvfxJqRnnOvWsceZeYzRyqnkaaFsffjenxoIhqHnIzorlOdwZoxYmAuNwNnRppguwidvbtOqdbUngpZdbGqwYjfpLzPjRtwVwEqBbYmCqbKwuziCoEwPsIkJgruTbhdyWpvPztAodufjZxLaZcUeFaklSmeRfolohVbXoDfIqMqgIrQhzedqZlFwaBndQkQexBdLsCfXebrEfiOnSgYquyaqohxoDmLdDhwoOpgtkuRzeYziuvnuvnUuOtqasZueYpKfAkmKcJcWeocQvJguVsZfVovgrztAiryZivHqyMjoLyJdklKifmoWeOjVnogiiaBzDfrsWlOeAzPxltamqQiujZrpZrUcIlyktdJbhmNpDbltOlLnAqVhcxgObghpdcScgIiayqygUgwatiEzgzTsZgApUbbPynLfbzehzWsxcPbdcdfMucsCzjkWvjhMkiWuHfquqrcKwedqghiyHyMkSayRegeJcGw");
foreach($str as $char)
{
if (ord($char) >96 ) $i++;
}
junkpete
Posts: 4 Joined: Sat Oct 16, 2010 12:50 pm
Post
by junkpete » Sat Oct 16, 2010 10:28 pm
C
Code: Select all
char str[] = "mQmPtphqGrboHhmgaqVhCdwTwignlQvjIopDqVpgaNrwkAzVcnkHyNiPdSmgJmgrPiMjpnjdbuPucHnouwfKuPcybromnmbvfxJqRnnOvWsceZeYzRyqnkaaFsffjenxoIhqHnIzorlOdwZoxYmAuNwNnRppguwidvbtOqdbUngpZdbGqwYjfpLzPjRtwVwEqBbYmCqbKwuziCoEwPsIkJgruTbhdyWpvPztAodufjZxLaZcUeFaklSmeRfolohVbXoDfIqMqgIrQhzedqZlFwaBndQkQexBdLsCfXebrEfiOnSgYquyaqohxoDmLdDhwoOpgtkuRzeYziuvnuvnUuOtqasZueYpKfAkmKcJcWeocQvJguVsZfVovgrztAiryZivHqyMjoLyJdklKifmoWeOjVnogiiaBzDfrsWlOeAzPxltamqQiujZrpZrUcIlyktdJbhmNpDbltOlLnAqVhcxgObghpdcScgIiayqygUgwatiEzgzTsZgApUbbPynLfbzehzWsxcPbdcdfMucsCzjkWvjhMkiWuHfquqrcKwedqghiyHyMkSayRegeJcGw";
int sum=0;
for (int i=0; i<strlen(str); i++)
if(str[i] > 96 && str[i] < 132) sum++;
printf("%d", sum);
return 0;
Adriano
Posts: 6 Joined: Sun Oct 17, 2010 11:33 am
Post
by Adriano » Wed Oct 20, 2010 1:00 pm
Ruby one-liner - sort of
Code: Select all
puts 'mQmPtphqGrboHhmgaqVhCdwTwignlQvjIopDqVpgaNrwkAzVcnkHyNiPdSmgJmgrPiMjpnjdbuPucHnouwfKuPcybromnmbvfxJqRnnOvWsceZeYzRyqnkaaFsffjenxoIhqHnIzorlOdwZoxYmAuNwNnRppguwidvbtOqdbUngpZdbGqwYjfpLzPjRtwVwEqBbYmCqbKwuziCoEwPsIkJgruTbhdyWpvPztAodufjZxLaZcUeFaklSmeRfolohVbXoDfIqMqgIrQhzedqZlFwaBndQkQexBdLsCfXebrEfiOnSgYquyaqohxoDmLdDhwoOpgtkuRzeYziuvnuvnUuOtqasZueYpKfAkmKcJcWeocQvJguVsZfVovgrztAiryZivHqyMjoLyJdklKifmoWeOjVnogiiaBzDfrsWlOeAzPxltamqQiujZrpZrUcIlyktdJbhmNpDbltOlLnAqVhcxgObghpdcScgIiayqygUgwatiEzgzTsZgApUbbPynLfbzehzWsxcPbdcdfMucsCzjkWvjhMkiWuHfquqrcKwedqghiyHyMkSayRegeJcGw'.count("a-z")