Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

gpa.pl

by rescdsk (Novice)
on Aug 19, 2000 at 06:45 UTC ( [id://28622]=obfuscated: print w/replies, xml ) Need Help??

%g=("a"=>4, "b"=>3, "c"=> 2, "d"=>1, "f"=>0, "+"=> 1/3 , "-"=> -1/3); while (<>){ chomp; next unless m/^([abcdf])([+-])?$/; $n+=1; $t+= $g{$1}; m/(a\+|f-)/ or $t+=$g{$2};} print($t/$n,"\n");
(takes input in the form of one grade, lower case, per line.)
-resc

Replies are listed 'Best First'.
RE: gpa.pl
by ColonelPanic (Friar) on Aug 23, 2000 at 23:02 UTC
    Here's a better one, maybe. Note: my method of calculating GPA is slightly different. + and - add/sub. .5 instead of 1/3.
    chomp($_=<>);$a=$_;s/([^a-f+-]|e)//ig;s/f//ig;s/a/spit(2);/ig; s/b/print;/ig;s/c/eof;/ig;s/d/}d/ig;s/.\-//ig;$b=$_;$_=$a; s/[^abcdf]//ig;$_=length;$b=length$b;$_=$b/(2*$_);print;
    Update: Hey, the first time I didn't see the big 4...it was just mashed together. Neat. BTW, this can take input from a file or STDIN, formatted in any way or not at all. And it uses the rare spit() function :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://28622]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found