From 122f3c401f23f84799802c7b9667bda222646487 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 8 Apr 2015 03:18:53 -0400 Subject: initial commit --- parallel_resistors | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 parallel_resistors (limited to 'parallel_resistors') diff --git a/parallel_resistors b/parallel_resistors new file mode 100755 index 0000000..18df62d --- /dev/null +++ b/parallel_resistors @@ -0,0 +1,45 @@ +#!/usr/bin/perl -w + +if(@ARGV < 2) { + usage(); + exit 0; +} + +for(@ARGV) { + if(/^([\d.]+)k/i) { + $_ = $1 * 1000; + } elsif(/^([\d.]+)m/i) { + $_ = $1 * 1000000; + } + + if(not $_+0) { + warn "Invalid resistance: $_\n"; + usage(); + exit 1; + } +} + +$res += 1/$_ for @ARGV; +printf "%.2f\n", 1/$res; +#print 1/$res, "\n"; + +sub usage { + my $b = $0; + $b =~ s/.*\///; + print <