Write a program called no_vowels.pl that will count
how many words DO NOT have an 'a' or an 'A',
how many DO NOT have an 'e' or an 'E',
how many DO NOT have an 'i' or an
'I', and so on.
The output should look like the below.
Note that the letters must be listed in decreasing order of frequency
14000 words do not have an 'u'
11258 words do not have an 'o'
10123 words do not have an 'i'
11523 words do not have an 'a'
10111 words do not have an 'e'
Name:
Anonymous2011-06-08 4:55
>>39
what does it say here:
$no_vowel{$b} cmp $no_vowel{$a}
i tried sorting:
sort{$a cmp $b} %values_sort...
but it throws a exception saying "a" is not a number. granted.
but doesnt the aboce code say. compare value with string? i dont get it
what does it mean?
how i understood "keys". keys gives you a pair of values from the array-hash. correct?
so what does the $no_vowel($b) cmp $no_vowel($a) say?
>>43
yes that is clear to me that it sorts in a specific way.
but it is a hash. and a hash is key:value
so how do i say: pls use only the values for the comparsion and not the key.
(define (print-result result)
(for-each
(lambda (pair) (printf "~a words do not have an ~a\n" (cdr pair) (car pair)))
(sort (hash->list result) > #:key cdr)))
words := FS.open("/usr/share/dict/words").read().split("\n");
Map
->c[{(
words;
Map \[c !in \w;] $;
Len($);
),c};]
"aeiou".to_list();
Sort($);
Map ->p["%d words do not have a '%s'" % p;] $;
"\n".join($);
Print($);
my ($no_a, $no_e, $no_i, $no_o, $no_u) = (0, 0, 0, 0, 0);
open my $read_file, '<', "test.txt";
my $text = <$read_file>;
close $read_file;
while ($text =~ /(\w+)/g) {
my $word = $1;
$no_a++ if $word !~ /a/i;
$no_e++ if $word !~ /e/i;
$no_i++ if $word !~ /i/i;
$no_o++ if $word !~ /o/i;
$no_u++ if $word !~ /u/i; }
my @no_vowel = ("$no_a a", "$no_e e", "$no_i i", "$no_o o", "$no_u u");
for (sort {$b <=> $a} @no_vowel) {
/^([0-9]+) ([a-z])$/;
print "$1 words do not have an '$2'\n"; }
Hash table at the end for sorting:
#!/usr/bin/perl
my ($no_a, $no_e, $no_i, $no_o, $no_u) = (0, 0, 0, 0, 0);
open my $read_file, '<', "test.txt";
my $text = <$read_file>;
close $read_file;
while ($text =~ /(\w+)/g) {
my $word = $1;
$no_a++ if $word !~ /a/i;
$no_e++ if $word !~ /e/i;
$no_i++ if $word !~ /i/i;
$no_o++ if $word !~ /o/i;
$no_u++ if $word !~ /u/i; }
my %no_vowel = ('a', $no_a, 'e', $no_e, 'i', $no_i, 'o', $no_o, 'u', $no_u);
for my $key (sort { $no_vowel{$b} <=> $no_vowel{$a} } keys %no_vowel) {
print "$no_vowel{$key} words do not have an '$key'\n"; }
Name:
Anonymous2011-06-08 22:42
>>50
You're a fucking moron. Do society a favor and go back to playing with your sister's barbie dolls.
">Face it. It's just PASCAL with proper pointers and memory management tacked on. "
With that, maybe I'm not the C language master like you, but the only memory management that I'm aware of for ANSI/ISO C are for local variables with automatic duration.
Name:
!!kCq+A64Losi56ze2011-06-09 15:48
>>68
Fuck, I still can't get the quoting correct on this fucking site.