Coffee Break

AUTHOR

Nelo Onyiah

Itā€™s Monday morning, at least half the people in the building had to work through the weekend, everyoneā€™s a little tired and thereā€™s still a ton of work to do. So the kindly group assistant has decided to go get everyone coffee. Each person can choose between a Latte, an Espresso, and a Cappuccino. The assistant wanders from one office to the next taking orders. (There are several people in each office.) He writes down the office number, then the number of Lattes, Espressos, and cappuccinos for each. His list looks like this:

Office 100
    Espresso 3
    Latte 1
    Cappuccino 1
    Office 200
    Cappucino 2
    Latte 2
    Espresso 1
    Office 300
    ā€¦

And so on. As soon as heā€™s done, however, he realizes he has one problem: he doesnā€™t want to place an order for 3 espressos and 1 espresso and 2 espressos, etc. He needs to place an order for the total number of each type of drink. Youā€™ll successfully complete this event if you read from the text file containing the order (Coffee.txt in the Scripting Games 2008 Competitorā€™s Pack) and correctly output a tally of the number of each type of drink the assistant needs to order, something like this:

Espresso: 15
    Latte: 10
    Cappuccino: 14

Make sure that you put the file Coffee.txt in the C:\Scripts folder. If you reference any path other than C:\Scripts\Coffee.txt your script will probably fail when we test it.

http://web.archive.org/web/20081210123558/http://www.microsoft.com/technet/scriptcenter/funzone/games/games08/bevent6.mspx

use v6;



our %count_for;

sub MAIN(Str $orders = $*SPEC.catdir($*PROGRAM-NAME.IO.dirname, 'coffee.txt')) {
    # get the data
    my @contents = $orders.IO.lines;

    # count the orders
    for @contents -> $line {
        unless $line ~~ /^ (Office \s+ \d+) $/ {
            my ($drink, $count) = $line.split(/\s+/);
            %count_for{$drink} += $count;
        }
    }

    # print to screen
    for %count_for.kv -> $drink, $total {
        say $drink ~ ": " ~ $total;
    }
}

# vim: expandtab shiftwidth=4 ft=perl6

See Also

advanced-2008

Could I Get Your Phone Number?

advanced-2008

Skating on Thin Ice

advanced-2008

You Call That a Strong Password?

advanced-2008

Blackjack!

beginner-2007

One of These Things is not Like the Others

beginner-2008

Pairing Off

beginner-2008

Pairing off

beginner-2008

Pairing Off

beginner-2008

Let's Get Together

beginner-2008

Coffee Break

beginner-2008

Random Guess

beginner-2008

Random Guess

beginner-2008

Bowling

README.md

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.