Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

PERL counting words that are missing a vowel

Name: Anonymous 2011-06-04 16:02

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: Anonymous 2011-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

Name: Anonymous 2011-06-08 5:01

sort { $no_vowel{$b} cmp $no_vowel{$a} } keys %no_vowel

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?

dont you compare 0 with "a" ?

Name: Anonymous 2011-06-08 5:18

my @sorted = sort { $hash{$a} cmp $hash{$b} } keys %hash;

{ $hash{$a} cmp $hash{$b} } means sort values in ascending order.
{ $hash{$b} cmp $hash{$a} } means sort values in descending order.

See: http://www.perlfect.com/articles/sorting.shtml

Name: Anonymous 2011-06-08 5:37

>>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.

Name: Anonymous 2011-06-08 5:41

>>43
sry i didnt understand at first.

ok so $hash($a) means use the values.
and how do i access the key?

Name: Anonymous 2011-06-08 5:44

ok disregard that.
i understand now.
$hash($a) means get the value of $a-key from $hash and compare then.

fucking weed. slowing the brain down -.-

Name: Anonymous 2011-06-08 6:12

#lang racket
(define vowels (string->list "uoiae"))

(define (split-input text)
  (map string->list (regexp-match* #px"\\w+" text)))

(define (count-vowels words)
  (foldr (lambda (word result)
           (foldr (lambda (vowel result)
                    (if (not (member vowel word)) (hash-update result vowel add1 0) result))
                  result vowels))
         (hash) words))

(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)))

(print-result (count-vowels (split-input (read-line))))

Name: Anonymous 2011-06-08 7:37

>>44-45
Use the Schwarts!

Name: Anonymous 2011-06-08 15:32

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($);


disregard that, my toy language sucks cocks

Name: Anonymous 2011-06-08 18:15

>>40
Came up with two more variations.

No hash tables involved:

#!/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 = ("$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: Anonymous 2011-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.

Name: Anonymous 2011-06-08 22:52

>>51
Back to the IMAGEBOARDS with you.

Name: Anonymous 2011-06-09 0:33

>>49
Is that Ruby or Python?

Name: Anonymous 2011-06-09 1:28

>>53
That's clearly jewish ``in Lisp'' DSL based on jewish Set Theory.

Name: Anonymous 2011-06-09 1:49

>>54
but >>49 isn't "in Lisp" DSL. It's some OOP language.

Name: Anonymous 2011-06-09 1:54

>>55
"
IHBT.

Name: Anonymous 2011-06-09 2:06

>>56
none cares 'bout u

Name: Anonymous 2011-06-09 7:51

>>57
u
Jewish Set Theory union operator. Your an jew.

Name: Anonymous 2011-06-09 11:50

>>58
What about my an Jew?

Name: >>49 2011-06-09 14:01

>>55
It's actually a fairly functional language. But yeah, it's probably going nowhere, like most of my petty projects ;_;

Name: Anonymous 2011-06-09 14:20

Notice how there are no C posts here: REAL PROGRAMMERS have no time for toy programmes !

Name: Anonymous 2011-06-09 14:27

>>61
Because C is a fuckawful language. Shit for libraries. Shit for language features.

Face it. It's just PASCAL with proper pointers and memory management tacked on.

Name: Anonymous 2011-06-09 14:45

>>62
Then why is it used for any good low-level application?  Why are there so many languages based directly on C?

Name: Anonymous 2011-06-09 14:52

>>63
Because Unix is written in C. Don't say that Unix is good, you know it's not.

Name: !!kCq+A64Losi56ze 2011-06-09 15:01

>>62
Wtf? Did you fail your sophmore level computer science classes at Devry?

Name: Anonymous 2011-06-09 15:34

>>65
I program for a commercial Unix for a living. C is all I do. I've heard several people say the same thing I did.

Like it or not, C IS a shit language. It has very few language features and the standard libraries are pretty bare.

Sure it's fast and there's compilers for it for almost everything, but as a language itself, it is shit.

Name: VIPPER 2011-06-09 15:46

>>65
but as a language itself, it is shit.
But as a troll yourself, you are shit.

Name: !!kCq+A64Losi56ze 2011-06-09 15:47

>>66
I was commenting on

">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+A64Losi56ze 2011-06-09 15:48

>>68
Fuck, I still can't get the quoting correct on this fucking site.

Name: VIPPER 2011-06-09 15:48

>>69
<-

Name: VIPPER 2011-06-09 15:49

fuck

Name: Anonymous 2011-06-09 15:49

>>69
>spacetext

Name: Anonymous 2011-06-09 16:07

> > > > > > > > > >

Name: Anonymous 2011-06-09 16:11

>>69
Lurk more, guides have been posted.

Name: Anonymous 2011-06-09 16:14

 

Name: Anonymous 2011-06-09 16:14

sfdhjgshj
lolzzz
faget

Name: Anonymous 2011-06-09 16:18

T
h
i
s

t
h
r
e
a
d
 
i
s

s
o

2
0
0
8

Name: Anonymous 2011-06-09 16:58

>me

Name: Anonymous 2011-06-09 17:03

fuck

Name: Anonymous 2011-06-09 17:23

>>68
Obviously I meant malloc/realloc/calloc/memset/etc.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List