#!/usr/bin/perl -Tw # # $Id: smoke,v 1.15 2006/01/11 22:50:35 nugget Exp $ # # For future use (Thanks Rayden242!): # http://www.ftc.gov/os/1997/9707/cigarett.htm # Lucky Strike: 26 mg tar, 1.7mg nicotine, 16mg carbon monoxide. # # Thanks to jeff for the apple equivalency idea! # 15:48 Nugget: how long until your quit-smoking-this-long-ago counter measures money saved in terms of various bits of apple hardware? # use Time::Local; use strict; my $quit = timelocal(0,0,12,8,4,1997); # sec,min,hour,day,month,year # Remeber: perl's timelocal numbers the months # from 0-11, so "4" is really May. my $perday = 22; my $perpack = 3.50; my @toys = ( 'Apple 20" Cinema Displays:799', 'Apple 23" Cinema Displays:1299', 'Apple 30" Cinema Displays:2499', 'Quad G5 PowerMacs:3299', 'Mac Minis:499', 'MacBook Pros:1999', 'iPod Nanos:199', 'iPods:299', 'iMacs:1299', ); my $now = time(); my $diff = $now - $quit; my $work = $diff; my $yys = (365*24*60*60); my $mos = (365/12)*(24*60*60); my $wks = (7*24*60*60); my $dys = (24*60*60); my $hrs = (60*60); my $mns = (60); my $persec = $perday/(24*60*60); my $cigs = int $diff*$persec; my $tar = $cigs*26; my $nicotine = $cigs*1.6; my $monoxide = $cigs*16; my $milecig = sprintf "%.2f", ($cigs*3)/(5280*12); my $monrw = $perpack*($cigs/20); my $money = sprintf "%.2f", $monrw; my ($toy,$toycount) = split /:/,howmanytoys(); print "I quit smoking "; my $years = int $work / $yys; $work = $work - $years*$yys; pstr($years,"year"); my $months = int $work / $mos; $work = $work - $months*$mos; pstr($months,"month"); my $weeks = int $work / $wks; $work = $work - $weeks*$wks; pstr($weeks,"week"); my $days = int $work / $dys; $work = $work - $days*$dys; pstr($days,"day"); my $hours = int $work / $hrs; $work = $work - $hours*$hrs; pstr($hours,"hour"); my $mins = int $work / $mns; $work = $work - $mins*$mns; pstr($mins,"minute"); my $secs = int $work; pstr($secs,"second","."); print "ago."; $cigs = num_format($cigs); $milecig = num_format($milecig); $money = num_format($money); $tar = mg_format($tar); $nicotine = mg_format($nicotine); $monoxide = mg_format($monoxide); print " During that time, I would have smoked $cigs cigarettes."; print " (That's like smoking a $milecig mile-long cigarette)"; print " By quitting, I've saved \$$money!"; if($toycount > 0) { print " (That's " . num_format($toycount) . " " . $toy . " and change)"; } print " I've avoided inhaling"; print " $tar of tar, $nicotine of nicotine, and $monoxide of carbon monoxide."; print "\n"; sub pstr { my ($val,$tag,$extra) = @_; if ($val>0) { if($extra) { print "and "; } print "$val $tag"; if ($val>1) { print "s"; } if(!$extra) { print ", "; } else { print " "; } } } sub num_format { my ($f_num) = @_; my $f_outstr = ""; my $f_counter = 0; my $f_dotspot = 0; if($f_num =~ m/\./g) { $f_dotspot = (pos $f_num)-1; } else { $f_dotspot = 999; } for(my $i=length($f_num)-1; $i>=0; $i--) { my $f_char = substr($f_num,$i,1); if( $f_counter == 3 ) { $f_outstr = "$f_char,$f_outstr"; $f_counter = 0; } else { $f_outstr = "$f_char$f_outstr"; } if($i < $f_dotspot) { $f_counter++; } } return $f_outstr; } sub mg_format { my ($f_mg) = @_; my @units = ('mg','grams','kg'); my $work = $f_mg; my $i = 0; my $unit = $units[0]; while($work>1000) { $work = $work/1000; $i++; $unit = $units[$i]; } if($i > 1) { $work = sprintf "%.2f", $work; } else { $work = int $work; } my $f_num = num_format($work); my $f_outstr = "$f_num $unit"; return $f_outstr; } sub howmanytoys { my @affordable; foreach my $item (@toys) { my ($desc,$price) = split /:/,$item; if($price < $money) { if( ($money / $price) > 2 ) { $affordable[@affordable] = $item; } } } if(@affordable > 0) { my $choice = int (rand @affordable); my ($whichtoy,$whichprice) = split /:/,$affordable[$choice]; return $whichtoy . ':' . int ($money / $whichprice); } else { return 'nothing:0'; } }