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

Pages: 1-4041-8081-

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-04 16:06


#!/usr/bin/perl
print "14000 words do not have an \'u\'\n";
print "11258 words do not have an \'o\'\n";
print "10123 words do not have an \'i\'\n";
print "11523 words do not have an \'a\'\n";
print "10111 words do not have an \'e\'\n";
exit 0

Name: Anonymous 2011-06-04 16:12

$DO_NOT = grep !/a/i, /\w+/g;

Name: Anonymous 2011-06-04 16:19

>>1
Damn it, Tim, how often do I have to repeat this? It's not autism if you don't count them by hand.

Name: VIPPER 2011-06-04 16:29

Do your own homework.

Name: Anonymous 2011-06-04 17:51

>>2 YES

Name: Anonymous 2011-06-04 20:10

boyz its done

Name: Anonymous 2011-06-04 20:41

>>1
IF AND ELSE CLAUSES, SAVIOUR OF THE FLESH!

Name: Anonymous 2011-06-05 9:39

"uoiae" >>= \f → [(f, length . filter (not.(f `elem`)) $ words file)]

Name: Anonymous 2011-06-05 9:57

>>9
Not completely point-free, it's shit.

Name: Anonymous 2011-06-06 11:30

Name: Anonymous 2011-06-06 17:35

bampu

Name: Anonymous 2011-06-06 17:47

Name: Anonymous 2011-06-07 1:43

#!/usr/bin/ruby
# Fuck your shit, I use awesome languages
def no_vowels(word_list) # word_list is expected to be an array
        # Containing a string of every word to be counted
  no_a, no_e, no_i, no_o, no_u = 0
  word_list.each do |cap| cap.downcase! end
  word_list.each do |word|
    no_a += 1 unless word.include? "a"
    no_e += 1 unless word.include? "e"
    no_i += 1 unless word.include? "i"
    no_o += 1 unless word.include? "o"
    no_u += 1 unless word.include? "u"
  end
  [no_a, no_e, no_i, no_o, no_u] # can be sorted later
end

Name: Anonymous 2011-06-07 8:58

>>14

Clearly not ready for enterprise.

Name: Anonymous 2011-06-07 9:14

>>14
SLOW AS FUCK

Name: Anonymous 2011-06-07 9:16

>>14
oh_shit_nigger_what_are_you_doing.png

Name: Anonymous 2011-06-07 9:18

>>17
What part of textboard did you not get?

Name: chris 2011-06-07 10:14

#!/usr/bin/perl -w

my $a_count = 0;
my $e_count = 0;
my $i_count = 0;
my $o_count = 0;
my $u_count = 0;
my $i;
my @splitted_i;
open(FILE,"/no_vowl/test");


while(defined($i = <FILE>)){
        print "i:".$i."\n";
   @splitted_i = split(/ /,$i);
        foreach(@splitted_i){
        print "splitted_i: ".$_."\n";
        if($_ =~ m/a|A/){
                $a_count ++;
           }
        elsif($_ =~ m/e|E/){
                $e_count ++;
           }
        elsif($_ =~ m/i|I/){
                $i_count ++;
           }
        elsif($_ =~ m/o|O/){
                $o_count ++;
           }
        elsif($_ =~ m/u|U/){
                $u_count ++;
           }
}
print "A_count:".$a_count."\n";
print "E_count:".$e_count."\n";
print "I_count:".$i_count."\n";
print "O_count:".$o_count."\n";
print "U_count:".$u_count."\n";
}
close(FILE);

sorting you need to do for yourself. but that shouldnt be so hard . right?

Name: Anonymous 2011-06-07 10:16

oh sry. this code counts the occurance of a,e,i,o,u. sry >:

Name: Anonymous 2011-06-07 10:21

here the right shit :
#!/usr/bin/perl -w

my $a_count = 0;
my $e_count = 0;
my $i_count = 0;
my $o_count = 0;
my $u_count = 0;
my $i;
my @splitted_i;
open(FILE,"/no_vowl/test");


while(defined($i = <FILE>)){
        print "i:".$i."\n";
   @splitted_i = split(/ /,$i);
        foreach(@splitted_i){
        print "splitted_i: ".$_."\n";
        if($_ =~ m/a|A/){
                #$a_count ++;
           }
        else{
                $a_count ++;
        }
        if($_ =~ m/e|E/){
                #$e_count ++;
           }
        else{
                $e_count ++;
        }
        if($_ =~ m/i|I/){
                #$i_count ++;
           }
        else{
                $i_count ++;
        }
        if($_ =~ m/o|O/){
                #$o_count ++;
           }
        else{
                $o_count ++;
        }
        if($_ =~ m/u|U/){
                #$u_count ++;
           }
        else{
                $u_count ++;
        }

}
print "A_count:".$a_count."\n";
print "E_count:".$e_count."\n";
print "I_count:".$i_count."\n";
print "O_count:".$o_count."\n";
print "U_count:".$u_count."\n";
}
close(FILE);

Name: Anonymous 2011-06-07 10:45

>>21
See >>3.

Name: VIPPER 2011-06-07 11:19

>>1
In my language every word is missing all wovels!

Name: VIPPER 2011-06-07 13:36

>>23
In my anus every word is a moving of bowels.

Name: Anonymous 2011-06-07 14:37

>>21
if it ain't Lisp, it's crap.

Name: Anonymous 2011-06-07 16:26


#lang racket
(require srfi/13)
(define (no-vowels words)
  (define (display-summary no-A no-E no-I no-O no-U)
    (display no-U) (displayln " words do not have an 'u'")
    (display no-O) (displayln " words do not have an 'o'")
    (display no-I) (displayln " words do not have an 'i'")
    (display no-A) (displayln " words do not have an 'a'")
    (display no-E) (displayln " words do not have an 'e'"))
 
  (define (no-vowels-loop words no-A no-E no-I no-O no-U)
    (if (empty? words)
        (display-summary no-A no-E no-I no-O no-U)
        (let ((no-A-inc (+ no-A (if (string-contains-ci (car words) "a") 0 1)))
              (no-E-inc (+ no-E (if (string-contains-ci (car words) "e") 0 1)))
              (no-I-inc (+ no-I (if (string-contains-ci (car words) "i") 0 1)))
              (no-O-inc (+ no-O (if (string-contains-ci (car words) "o") 0 1)))
              (no-U-inc (+ no-U (if (string-contains-ci (car words) "u") 0 1))))
          (no-vowels-loop (cdr words) no-A-inc no-E-inc no-I-inc no-O-inc no-U-inc))))
  (no-vowels-loop words 0 0 0 0 0))

(no-vowels (string-tokenize (read-line)))

Name: Anonymous 2011-06-07 16:35

>>25
2/10

Name: Anonymous 2011-06-07 17:40


# pythonistas do it better

def check_word(word, counter):
    for i in range(len(counter)):
        if word.lower().find(counter[i][1]) == -1:
            counter[i][0] += 1

try:
    ls = [[0, 'a'], [0, 'e'], [0, 'i'], [0, 'o'], [0, 'u']]
   
    with open('words.txt', 'r') as f:
        for s in f:
            check_word(s.strip(), ls)

    ls.sort()
    ls.reverse()
    for i in range(len(ls)):
        print ls[i][0], ' words do not have \'', ls[i][1], '\''

except IOError as e:
    print e

Name: Anonymous 2011-06-07 17:47

>>28
    ls.sort()
    ls.reverse()

Why can't I stop laughing?

Name: Anonymous 2011-06-07 17:49

Name: Anonymous 2011-06-07 17:56

>>29
ls = sorted(ls, reverse=True)

Happy?

Name: Anonymous 2011-06-07 17:57

ls.sort(lambda x, y: cmp(y, x))

Name: Anonymous 2011-06-07 22:00

I think we should set a youtube video as the desktop background of this web sight

Name: Anonymous 2011-06-07 22:29

<?php
$file = file("words.txt");
$total = sizeof($file);
$letters = array('a', 'e', 'i', 'o', 'u');

array_map(
    function($letter, $count) use ($total) {
        echo ($total - $count) . ' words do not have ' . strtolower($letter) . ' or ' . strtoupper($letter) . "\n";
    },   
    $letters,
    array_map(
        function($letter, $count) use ($file, $total) {
            for ($i = 0; $i < $total; $count += false !== stripos($file[$i++], $letter) ? 1 : 0);
            return $count;
        },
        $letters,
        array_fill(0, sizeof($letters) - 1, 0)
    )
);

Name: Anonymous 2011-06-08 0:28

<?php
class Timer { public $start, $end; function __construct() { $this->start = microtime(true); } function end() { $this->end = $this->end ? $this->end : microtime(true); return $this->end - $this->start; } }
class Test { public $f, $t; function __construct(Closure $f) { $this->f = $f; } function exec() { $this->t = new Timer(); $f = $this->f; $f(); return $this->t->end(); } }
class Tester { const NL = "________\n\n"; public $tests = array(); function add(Closure $f) { $this->tests[] = new Test($f); } function exec() { $times = array(); foreach ($this->tests as $i => $t) {    echo self::NL, "Call $i \n", self::NL; $times[$i] = $t->exec(); echo self::NL, "Time: {$times[$i]} \n", self::NL; echo "\n"; } $fastest = array_reduce(array_keys($times), function($a, $b) use ($times) { return $times[$a] <= $times[$b] ? $a : $b; }, 0);echo "Fastest call was [$fastest] by: ", array_reduce($times, function($a, $b) use ($times, $fastest) { $diff = $b - $times[$fastest]; return !$diff ? $a : $a < $diff && $a > 0 ?  $a : $diff;}, 0), "\n"; } }

$t = new Tester();

$t->add(function() {
    $file = file("words.txt");
    $total = sizeof($file);
    $letters = array('a', 'e', 'i', 'o', 'u');

    array_map(
        function($letter, $count) use ($total) {
            echo ($total - $count) . ' words do not have ' . strtolower($letter) . ' or ' . strtoupper($letter) . "\n";
        },   
        $letters,
        array_map(
            function($letter) use ($file) {
                return array_reduce($file, function($count, $word) use ($letter) {
                    return $count + (stripos($word, $letter) ? 1 : 0);
                }, 0);
            },
            $letters
        )
    );
});


$t->add(function() {
    $file = file("words.txt");
    $total = sizeof($file);

    foreach($file as $word) {
        foreach (str_split($word) as $letter) {
            @${$letter}++;
        }
    }

    foreach (array('a', 'e', 'i', 'o', 'u') as $letter) {
        echo ($total - ${$letter}) . ' words do not have ' . strtolower($letter) . ' or ' . strtoupper($letter) . "\n";
    }
});

$t->exec();


I hate PHP actually

Name: Anonymous 2011-06-08 1:59

I would rather shove a fork in my anus than write a line of PHP code!

Name: chris 2011-06-08 2:15

>>36
why did i know that already.

freak!

Name: Anonymous 2011-06-08 2:54


try:
    counter = {'a':0, 'e':0, 'i':0, 'o':0, 'u':0}
    total = 0

    with open('words.txt', 'r') as f:
        for s in f:
            total += 1
            for c in set(s.strip().lower()):
                if c in counter:
                    counter[c] += 1

    ls = counter.items()
    ls.sort(lambda x,y: cmp(x[1],y[1]))
    for i in range(len(ls)):
        print (total - ls[i][1]), 'words do not have \'' + ls[i][0] + '\''
       
except IOError as e:
    print e

Name: Anonymous 2011-06-08 4:47

This actually does everything OP specified, right down to the sorting. I know this is OP's homework, but it helped me learn how to work with Perl hashes.

#!/usr/bin/perl

my %no_vowel = ('a', 0, 'e', 0, 'i', 0, 'o', 0, 'u', 0);
open my $read_file, '<', "test.txt";
my $text = <$read_file>;
close $read_file;
while ($text =~ /(\w+)/g) {
    for my $key (keys %no_vowel) {
        my $value = $no_vowel{$key};
        $value++ if $1 !~ /$key/i;
        delete $no_vowel{$key};
        $no_vowel{$key} = $value; }}
for my $key (sort { $no_vowel{$b} cmp $no_vowel{$a} } keys %no_vowel) {
    print "$no_vowel{$key} words do not have an '$key'\n"; }

Name: Anonymous 2011-06-08 4:53

Whoops. I fucked up a minor detail.

#!/usr/bin/perl

my %no_vowel = ('a', 0, 'e', 0, 'i', 0, 'o', 0, 'u', 0);
open my $read_file, '<', "test.txt";
my $text = <$read_file>;
close $read_file;
while ($text =~ /(\w+)/g) {
    my $word = $1;
    for my $key (keys %no_vowel) {
        my $value = $no_vowel{$key};
        $value++ if $word !~ /$key/i;
        delete $no_vowel{$key};
        $no_vowel{$key} = $value; }}
for my $key (sort { $no_vowel{$b} cmp $no_vowel{$a} } keys %no_vowel) {
    print "$no_vowel{$key} words do not have an '$key'\n"; }

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.

Name: Anonymous 2011-06-10 20:36

Someone please optimize this, I suck at programming.


#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <boost/smart_ptr.hpp>
#include <list>
#include <vector>
#include <utility>
#include <set>
#include <fstream>
#include <iostream>

#ifdef _WIN32
#include <Windows.h>

size_t CountCPUCores()
{
    SYSTEM_INFO sysinfo;
    GetSystemInfo(&sysinfo);
    return sysinfo.dwNumberOfProcessors;
}

#else

// write this yourself linuxfag
size_t CountCPUCores()
{
    return 1;
}

#endif

typedef std::list< boost::shared_ptr<boost::thread> > threadlist;

struct BasicString
{
    BasicString() : p(0), len(0) {}
    BasicString(char* p_, size_t len_) : p(p_), len(len_) {}
    bool Step() { if(!len) return false; ++p; --len; }
    char* p;
    size_t len;
};

class LineReader
{
public:
    LineReader() {}

    LineReader(char* p, size_t len)
        : s(p, len)
    {
    }

    void Set(char* p, size_t len)
    {
        s.p = p;
        s.len = len;
    }

    bool Read(BasicString& into)
    {
        if(!s.len)
            return false;

        into.p = s.p;
        into.len = 0;
        while(*s.p != '\n' && s.Step())
            ++into.len;
       
        if(s.len)
            s.Step();

        return true;
    }

    size_t Length() const
    {
        return s.len;
    }
private:
    BasicString s;
};

void lower_string(BasicString& s)
{
    char* p = s.p;
    for(size_t i = 0; i < s.len; ++i, ++p)
    {
        if(*p >= 'A' && *p <= 'Z')
            *p = 'a' + (*p - 'A');
    }
}

void BeginCount(int* counter, size_t& total, LineReader& input)
{
    bool seen[256];
    while(true)
    {
        BasicString s;
        if(!input.Read(s))
            return;
        ++total;

        // ignore empty lines
        if(s.len == 0)
            continue;

        lower_string(s);
        memset(seen, 0, sizeof(seen));

        for(size_t i = 0; i < s.len; ++i, ++s.p)
        {
            if(!seen[*s.p])
            {
                ++counter[*s.p];
                seen[*s.p] = true;
            }
        }
    }
}

int main()
{
    // 8 threads per core seems to be the sweet spot for me
    const size_t ncores = CountCPUCores() * 8;
    const char* usechars = "aeiou";
    const size_t usecharslen = strlen(usechars);
    size_t total = 0;
    std::ifstream file("words.txt");
    if(!file.is_open())
    {
        std::cout << "Cannot open file\n";
        return 1;
    }
    file.seekg(0, std::ios::end);
    size_t filelen = (size_t)file.tellg();
    file.seekg(0, std::ios::beg);
    char* strp = new char[filelen];
    file.read(strp, filelen);
    file.close();
   
    std::vector<LineReader> readers(ncores);
    size_t part = filelen / ncores;
    size_t lastp = filelen;
    for(size_t i = 0; i < (ncores-1); ++i)
    {
        size_t cur = ncores - i - 1;
        size_t tpar = part * cur;
        readers[cur].Set(&strp[tpar], lastp - tpar);
        BasicString tmp;
        readers[cur].Read(tmp);
        lastp -= readers[cur].Length();
    }
    readers[0].Set(strp, lastp);

    std::vector< boost::shared_array<int> > counters(ncores);
    for(size_t i = 0; i < ncores; ++i)
    {
        counters[i] = boost::shared_array<int>(new int[256]);
        memset(counters[i].get(), 0, sizeof(int) * 256);
    }

    std::vector<size_t> totals(ncores, 0);

    {
        threadlist threads;
        for(size_t i = 0; i < ncores; ++i)
        {
            try {
                threads.push_back(boost::shared_ptr<boost::thread>(new boost::thread(
                    boost::bind(BeginCount, counters[i].get(), boost::ref(totals[i]),
                        boost::ref(readers[i])))));
            }
            catch(boost::thread_exception& te)
            {
                BeginCount(counters[i].get(), totals[i], readers[i]);
            }
        }

        for(threadlist::iterator it = threads.begin(); it != threads.end(); ++it)
            it->get()->join();
    }

    delete[] strp;

    std::set< std::pair<size_t, char> > ms;
    for(size_t i = 0; i < usecharslen; ++i)
    {
        size_t cnt = 0;
        for(size_t j = 0; j < ncores; ++j)
            cnt += counters[j][usechars[i]];
        ms.insert(std::pair<size_t, char>(cnt, usechars[i]));
    }

    for(size_t i = 0; i < ncores; ++i)
        total += totals[i];

    for(std::set< std::pair<size_t, char> >::iterator it = ms.begin(); it != ms.end(); ++it)
        std::cout << (total - it->first) << " words do not have '" << it->second << "'\n";
}

Name: Anonymous 2011-06-10 20:40

>>81
bool Step() { if(!len) return false; ++p; --len; return true; }

Name: Anonymous 2011-06-10 20:42

>Someone please optimize this, I suck at programming.

Yeah, don't use C++ io streams, they are slow as fuck!, there's like several virtual calls per fucking character read from a file plus 2 or 3 fucking buffers things get copied into. The solution is either to use C style fopen/fread/etc. which is better, but the optimal solution is to use your operating system's file IO facilities, like the POSIX open/read/write calls or Windows OpenFile, ReadFile, etc. and just wrap it in a thin C++ class with no virtual functions.

Also, boost's threads implementation is slow and unoptimized because boost programmers are lazy as fuck like you. Use a C++0x/C++11 threads implementation, which has the same interfaces, but is more optimized.

Name: Anonymous 2011-06-10 20:46

Name: Anonymous 2011-06-10 20:50

>>60
It's actually a fairly functional language. But yeah, it's probably going nowhere, like most of my petty projects ;_;
Well, today it's hard to advance new language, without backing at Microsoft (Haskell) or Google (Python).

Name: Anonymous 2011-06-10 20:55

>>84
I chuckled.

Name: Anonymous 2011-06-10 21:13

>>81
Hmm I just realized you can pass extra parameters directly to boost.thread without using boost.bind.

>>83
Yes I just discovered how slow they are. I wrote the LineReader class after trying to do the whole thing with streams and wondering why it was so butt-fucking-slow.

Name: Anonymous 2011-06-10 22:15

</code>
sub print_vowels {

    my %vowels = @_;
    foreach (sort { $vowels{$a} <=> $vowels{$b} } keys %vowels) {
        print "$_ was not in $vowels{$_} words\n";
    }
}

my %vowels;

while (<>) {
    chomp;
    my @words = split " ", $_;
    foreach (@words) {
        $vowels{a}++ if (/^[^Aa]*$/);
        $vowels{e}++ if (/^[^Ee]*$/);
        $vowels{i}++ if (/^[^Ii]*$/);
        $vowels{o}++ if (/^[^Oo]*$/);
        $vowels{u}++ if (/^[^Uu]*$/);
    }
    print_vowels %vowels;
}
</code>

Name: Anonymous 2011-06-11 4:35

  ∧_∧   ∧_∧   ∧_∧   ∧_∧      ∧_∧
 ( ・∀・)   ( `ー´)  ( ´∀`)  ( ゚ ∀゚ )    ( ^∀^)
 (    つ┳∪━━∪━∪━━∪━∪━∪━┳⊂     つ
 | | |  ┃This thread has peacefully ended.┃ | | |
 (__)_) ┻━━━━━━━━━━━━━━┻ (__)_)     Thank you.

Name: Anonymous 2011-06-11 5:02

>>81
++total;

// ignore empty lines
if(s.len == 0)
     continue;


Whoops, that ++total is supposed to come after the empty string check.

Name: Anonymous 2011-06-11 8:09

>>90
Woohps, taht ++taotl is suoesppd to cmoe aeftr the epmty sirtng cehkc

Name: Anonymous 2011-06-11 8:45

CUNTS

Name: Anonymous 2011-06-11 17:44

>>91
Nigger, that nigger is nigger nigger nigger nigger.

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