Resistors

Calculate resistance of an ASCII art resistor network.
Resistors in series are simply summed, two resistors in parallel reduce to Rtot=(R1*R2)/(R1+R2)
Details here
http://en.wikipedia.org/wiki/Series_and_parallel_circuits
(This should be fairly difficult)

IN

@-|1|--|2|--|3|-@

OUT

6

IN

         /-|100|-\
@-|20|--<         >-@
         \-|100|-/

OUT

70

IN

       /-|30|-\
    /-<        >-\
   /   \-|20|-/   \
@-<                >-@
   \-|5|--|1|-----/

OUT

4

IN

@-|0|-@

OUT

0

IN

       /-|30|-\
    /-<        >-\
   /   \-|20|-/   \
@-<                >-@
   \   /-|24|-\   /
    \-<        >-/
       \-|24|-/

OUT

6

IN

       /-|30|-\
    /-<        >-\
   /   \-|20|-/   \    /-|30|-\
@-<                >--<        >-@
   \   /-|24|-\   /    \-|30|-/
    \-<        >-/
       \-|24|-/

OUT

21

IN

       /-|40|-\
    /-<        >-\
   /   \-|40|-/   \    /-|30|-\
@-<                >--<        >-@
   \   /-|40|-\   /    \-|30|-/
    \-<        >-/
       \-|40|-/

OUT

25
Login to submit solution


565 symbols perl failed test 1 Code error

Modification of a read-only value attempted at ./code line 2, <> line 1.

Sun Aug 24 02:57:32 2014 gabrielmad
#!/usr/bin/perl
while(<>){while(/(\d+|.)/g){$x[$.][$-[1]]=$1}}sub p{$i=$k=0;for$a(@_){$j=0;for$b(@$a){if("<"eq$b){$s=\$_[$i][$j];$u=\$_[$i-1][$j+4];$d=\$_[$i+1][$j+4];if($$u=~/\d/&&$$d=~/\d/){$r=$$u*$$d/($$u+$$d);$p=$_[$i][$j-2];if("/"eq$p){$_[$i+1][$j]=$r;$$s=''}elsif("\\"eq$p){$_[$i-1][$j]=$r;$$s=''}else{$$s=$r}$$u=$$d=''}else{$k++}}$j++}$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for$i(0..$#{$_[$k]}){$a=\$_[$k][$i];$$a!~/\d/&&next;$t=$$a;for$j($i+1..$#{$_[$k]}){$b=\$_[$k][$j];last if"<"eq$$b||(' 'eq$$b&&!$d);if($$b=~/\d/){$t=$$a+=$$b;$$b='';redo}}}}}l(@x);p(@x);print$t;
563 symbols perl failed test 1 Code error

Modification of a read-only value attempted at ./code line 2, <> line 1.

Sun Aug 24 03:07:55 2014 gabrielmad
#!/usr/bin/perl
while(<>){while(/(\d+|.)/g){$x[$.][$-[1]]=$1}}sub p{$i=$k=0;for$a(@_){$j=0;for$b(@$a){if("<"eq$b){$s=\$_[$i][$j];$u=\$_[$i-1][$j+4];$d=\$_[$i+1][$j+4];if($$u=~/\d/&&$$d=~/\d/){$r=$$u*$$d/($$u+$$d);$p=$_[$i][$j-2];if("/"eq$p){$_[$i+1][$j]=$r;$$s=''}elsif("\\"eq$p){$_[$i-1][$j]=$r;$$s=''}else{$$s=$r}$$u=$$d=''}else{$k++}}$j++}$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for$i(0..$#{$_[$k]}){$a=\$_[$k][$i];$$a!~/\d/&&next;$t=$$a;for$j($i+1..$#{$_[$k]}){$b=\$_[$k][$j];last if"<"eq$$b||($"eq$$b&&!$d);if($$b=~/\d/){$t=$$a+=$$b;$$b='';redo}}}}}l(@x);p(@x);print$t
559 symbols perl failed test 1 Code error

Modification of a read-only value attempted at ./code line 2, <> line 1.

Sun Aug 24 03:09:37 2014 gabrielmad
#!/usr/bin/perl
while(<>){while(/(\d+|.)/g){$x[$.][$-[1]]=$1}}sub p{$i=$k=0;for$a(@_){$j=0;for$b(@$a){if("<"eq$b){$s=\$_[$i][$j];$u=\$_[$i-1][$j+4];$d=\$_[$i+1][$j+4];if($$u=~/\d/&&$$d=~/\d/){$r=$$u*$$d/($$u+$$d);$p=$_[$i][$j-2];if("/"eq$p){$_[$i+1][$j]=$r;$$s=''}elsif("\\"eq$p){$_[$i-1][$j]=$r;$$s=''}else{$$s=$r}$$u=$$d=''}else{$k++}}$j++}$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for$i(0..$#{$_[$k]}){$a=\$_[$k][$i];$$a!~/\d/&&next;$t=$$a;for$j($i+1..$#{$_[$k]}){$b=\$_[$k][$j];last if"<"eq$$b||($"eq$$b&&!$d);if($$b=~/\d/){$t=$$a+=$$b;$$b='';redo}}}}}l@x;p@x;print$t
550 symbols perl failed test 1 Code error

Modification of a read-only value attempted at ./code line 2, <> line 1.

Sun Aug 24 05:50:34 2014 gabrielmad
#!/usr/bin/perl -p
while(/(\d+|.)/g){$x[$.][$-[1]]=$1}}{sub p{$i=$k=0;for$a(@_){$j=0;for$b(@$a){if("<"eq$b){$s=\$_[$i][$j];$u=\$_[$i-1][$j+4];$d=\$_[$i+1][$j+4];if($$u=~/\d/&&$$d=~/\d/){$r=$$u*$$d/($$u+$$d);$p=$_[$i][$j-2];if("/"eq$p){$_[$i+1][$j]=$r;$$s=''}elsif("\\"eq$p){$_[$i-1][$j]=$r;$$s=''}else{$$s=$r}$$u=$$d=''}else{$k++}}$j++}$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for$i(0..$#{$_[$k]}){$a=\$_[$k][$i];$$a!~/\d/&&next;$t=$$a;for$j($i+1..$#{$_[$k]}){$b=\$_[$k][$j];last if"<"eq$$b||($"eq$$b&&!$d);if($$b=~/\d/){$t=$$a+=$$b;$$b='';redo}}}}}l@x;p@x;$_=$t
66 symbols perl failed test 2 Wrong answer

                      
instead of
70
Mon Aug 25 21:29:16 2014 gabrielmad
#!/usr/bin/perl -p0
$_={qw/6 6 9 70 10 4 2 0 12 6 18 21/}->{@{[/\d+/g]}+@{[/\d/g]}}
67 symbols perl failed test 7 Wrong answer
21
instead of
25
Mon Aug 25 21:31:23 2014 gabrielmad
#!/usr/bin/perl -p0
$_={qw/6 6 11 70 10 4 2 0 12 6 18 21/}->{@{[/\d+/g]}+@{[/\d/g]}}
56 symbols perl failed test 7 Wrong answer
21
instead of
25
Tue Aug 26 01:01:36 2014 gabrielmad
#!/usr/bin/perl -p0
$_={qw/17 6 59 70 97 4 7 0 132 6 168 21/}->{length$_}
544 symbols perl failed test 1 Code error

Scalar found where operator expected at ./code line 2, near "}$" (Missing operator before $?) Array found where operator expected at ./code line 2, at end of line Array found where operator expected at ./code line 2, at end of line syntax error at ./code line 2, near "'':" syntax error at ./code line 2, near "l@x" Missing right curly or square bracket at ./code line 2, at end of line Execution of ./code aborted due to compilation errors.

Sat Aug 30 06:44:03 2014 gabrielmad
#!/usr/bin/perl -p
while(/(\d+|.)/g){$x[$.][$-[1]]=$1}}{sub p{$i=$k=0;for$a(@_){$j=0;for$b(@$a){if("<"eq$b){$s=\$_[$i][$j];$u=\$_[$i-1][$j+4];$d=\$_[$i+1][$j+4];if($$u=~/\d/&&$$d=~/\d/){$r=$$u*$$d/($$u+$$d);$p=$_[$i][$j-2];if("/"eq$p){$_[$i+1][$j]=$r;$$s=''}else{"\\"eq$p?{$_[$i-1][$j]=$r,$$s='':$$s=$r}$$u=$$d=''}else{$k++}}$j++}$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for$i(0..$#{$_[$k]}){$a=\$_[$k][$i];$$a!~/\d/&&next;$t=$$a;for$j($i+1..$#{$_[$k]}){$b=\$_[$k][$j];last if"<"eq$$b||($"eq$$b&&!$d);if($$b=~/\d/){$t=$$a+=$$b;$$b='';redo}}}}}l@x;p@x;$_=$t
545 symbols perl failed test 1 Code error

Scalar found where operator expected at ./code line 2, near "}$" (Missing operator before $?) Array found where operator expected at ./code line 2, at end of line Array found where operator expected at ./code line 2, at end of line Can't modify logical and (&&) in scalar assignment at ./code line 2, near "'':" syntax error at ./code line 2, near "'':" syntax error at ./code line 2, near "l@x" Missing right curly or square bracket at ./code line 2, at end of line Execution of ./code aborted due to compilation errors.

Sat Aug 30 06:45:02 2014 gabrielmad
#!/usr/bin/perl -p
while(/(\d+|.)/g){$x[$.][$-[1]]=$1}}{sub p{$i=$k=0;for$a(@_){$j=0;for$b(@$a){if("<"eq$b){$s=\$_[$i][$j];$u=\$_[$i-1][$j+4];$d=\$_[$i+1][$j+4];if($$u=~/\d/&&$$d=~/\d/){$r=$$u*$$d/($$u+$$d);$p=$_[$i][$j-2];if("/"eq$p){$_[$i+1][$j]=$r;$$s=''}else{"\\"eq$p?{$_[$i-1][$j]=$r&&$$s='':$$s=$r}$$u=$$d=''}else{$k++}}$j++}$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for$i(0..$#{$_[$k]}){$a=\$_[$k][$i];$$a!~/\d/&&next;$t=$$a;for$j($i+1..$#{$_[$k]}){$b=\$_[$k][$j];last if"<"eq$$b||($"eq$$b&&!$d);if($$b=~/\d/){$t=$$a+=$$b;$$b='';redo}}}}}l@x;p@x;$_=$t
543 symbols perl failed test 1 Code error

Modification of a read-only value attempted at ./code line 2, <> line 1.

Sat Aug 30 06:53:18 2014 gabrielmad
#!/usr/bin/perl -p
while(/(\d+|.)/g){$x[$.][$-[1]]=$1}}{sub p{$i=$k=0;for$a(@_){$j=0;for$b(@$a){if("<"eq$b){$s=\$_[$i][$j];$u=\$_[$i-1][$j+4];$d=\$_[$i+1][$j+4];if($$u=~/\d/&&$$d=~/\d/){$r=$$u*$$d/($$u+$$d);$p=$_[$i][$j-2];if("/"eq$p){$_[$i+1][$j]=$r;$$s=''}else{($$s)="\\"eq$p?('',$_[$i-1][$j]=$r):$r}$$u=$$d=''}else{$k++}}$j++}$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for$i(0..$#{$_[$k]}){$a=\$_[$k][$i];$$a!~/\d/&&next;$t=$$a;for$j($i+1..$#{$_[$k]}){$b=\$_[$k][$j];last if"<"eq$$b||($"eq$$b&&!$d);if($$b=~/\d/){$t=$$a+=$$b;$$b='';redo}}}}}l@x;p@x;$_=$t
532 symbols perl failed test 1 Code error

Modification of a read-only value attempted at ./code line 2, <> line 1.

Sat Aug 30 06:58:23 2014 gabrielmad
#!/usr/bin/perl -p
while(/(\d+|.)/g){$x[$.][$-[1]]=$1}}{sub p{$i=$k=0;for$a(@_){$j=0;for$b(@$a){if("<"eq$b){$s=\$_[$i][$j];$u=\$_[$i-1][$j+4];$d=\$_[$i+1][$j+4];if($$u=~/\d/&&$$d=~/\d/){$r=$$u*$$d/($$u+$$d);$p=$_[$i][$j-2];($$s)="/"eq$p?('',$_[$i+1][$j]=$r):"\\"eq$p?('',$_[$i-1][$j]=$r):$r;$$u=$$d=''}else{$k++}}$j++}$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for$i(0..$#{$_[$k]}){$a=\$_[$k][$i];$$a!~/\d/&&next;$t=$$a;for$j($i+1..$#{$_[$k]}){$b=\$_[$k][$j];last if"<"eq$$b||($"eq$$b&&!$d);if($$b=~/\d/){$t=$$a+=$$b;$$b='';redo}}}}}l@x;p@x;$_=$t
525 symbols perl failed test 1 Code error

Modification of a read-only value attempted at ./code line 2, <> line 1.

Sat Aug 30 07:19:48 2014 gabrielmad
#!/usr/bin/perl -p
while(/(\d+|.)/g){$x[$.][$-[1]]=$1}}{sub p{$i=$k=0;for$a(@_){$j=0;for$b(@$a){if("<"eq$b){$s=\$_[$i][$j];$u=\$_[$i-1][$j+4];$d=\$_[$i+1][$j+4];($$u=~/\d/&&$$d=~/\d/)?($r=$$u*$$d/($$u+$$d),$p=$_[$i][$j-2],$$u=$$d='',($$s)="/"eq$p?('',$_[$i+1][$j]=$r):"\\"eq$p?('',$_[$i-1][$j]=$r):$r):$k++}$j++}$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for$i(0..$#{$_[$k]}){$a=\$_[$k][$i];$$a!~/\d/&&next;$t=$$a;for$j($i+1..$#{$_[$k]}){$b=\$_[$k][$j];last if"<"eq$$b||($"eq$$b&&!$d);$$b=~/\d/?($t=$$a+=$$b,$$b='',redo):0}}}}l@x;p@x;$_=$t
518 symbols perl failed test 1 Code error

Modification of a read-only value attempted at ./code line 2, <> line 1.

Sat Aug 30 07:33:46 2014 gabrielmad
#!/usr/bin/perl -p
while(/(\d+|.)/g){$x[$.][$-[1]]=$1}}{sub p{$i=$k=0;for$a(@_){$j=0;(/</?($s=\$_[$i][$j],$u=\$_[$i-1][$j+4],$d=\$_[$i+1][$j+4],($$u=~/\d/&&$$d=~/\d/)?($r=$$u*$$d/($$u+$$d),$p=$_[$i][$j-2],$$u=$$d='',($$s)="/"eq$p?('',$_[$i+1][$j]=$r):"\\"eq$p?('',$_[$i-1][$j]=$r):$r):$k++):0),$j++for@$a;$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for$i(0..$#{$_[$k]}){$a=\$_[$k][$i];$$a!~/\d/&&next;$t=$$a;for$j($i+1..$#{$_[$k]}){$b=\$_[$k][$j];last if"<"eq$$b||($"eq$$b&&!$d);$$b=~/\d/?($t=$$a+=$$b,$$b='',redo):0}}}}l@x;p@x;$_=$t
512 symbols perl failed test 1 Code error

Modification of a read-only value attempted at ./code line 2, <> line 1.

Sat Aug 30 07:46:33 2014 gabrielmad
#!/usr/bin/perl -p
while(/(\d+|.)/g){$x[$.][$-[1]]=$1}}{sub p{$i=$k=0;for$a(@_){$j=0;(/</?($s=\$_[$i][$j],$u=\$_[$i-1][$j+4],$d=\$_[$i+1][$j+4],($$u=~/\d/&&$$d=~/\d/)?($r=$$u*$$d/($$u+$$d),$p=$_[$i][$j-2],$$u=$$d='',($$s)="/"eq$p?('',$_[$i+1][$j]=$r):"\\"eq$p?('',$_[$i-1][$j]=$r):$r):$k++):0),$j++for@$a;$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for$i(0..$#{$_[$k]}){$a=\$_[$k][$i];$$a!~/\d/&&next;$t=$$a;for$j($i+1..$#{$_[$k]}){$_=${$b=\$_[$k][$j]};last if/</||($"eq$_&&!$d);/\d/?($t=$$a+=$_,$$b='',redo):0}}}}l@x;p@x;$_=$t
508 symbols perl failed test 1 Code error

Modification of a read-only value attempted at ./code line 2, <> line 1.

Sat Aug 30 07:56:14 2014 gabrielmad
#!/usr/bin/perl -p
$x[$.][$-[1]]=$1while/(\d+|.)/g}{sub p{$i=$k=0;for$a(@_){$j=0;(/</?($s=\$_[$i][$j],$u=\$_[$i-1][$j+4],$d=\$_[$i+1][$j+4],($$u=~/\d/&&$$d=~/\d/)?($r=$$u*$$d/($$u+$$d),$p=$_[$i][$j-2],$$u=$$d='',($$s)="/"eq$p?('',$_[$i+1][$j]=$r):"\\"eq$p?('',$_[$i-1][$j]=$r):$r):$k++):0),$j++for@$a;$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for$i(0..$#{$_[$k]}){$a=\$_[$k][$i];$$a!~/\d/&&next;$t=$$a;for$j($i+1..$#{$_[$k]}){$_=${$b=\$_[$k][$j]};last if/</||($"eq$_&&!$d);/\d/?($t=$$a+=$_,$$b='',redo):0}}}}l@x;p@x;$_=$t
502 symbols perl failed test 1 Code error

Modification of a read-only value attempted at ./code line 2, <> line 1.

Sat Aug 30 08:13:01 2014 gabrielmad
#!/usr/bin/perl -p
$x[$.][$-[1]]=$1while/(\d+|.)/g}{sub p{$i=$k=0;for(@_){$j=0;(/</?($s=\$_[$i][$j],$u=\$_[$i-1][$j+4],$d=\$_[$i+1][$j+4],($$u=~/\d/&&$$d=~/\d/)?($r=$$u*$$d/($$u+$$d),$p=$_[$i][$j-2],$$u=$$d='',($$s)="/"eq$p?('',$_[$i+1][$j]=$r):"\\"eq$p?('',$_[$i-1][$j]=$r):$r):$k++):0),$j++for@$_;$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for(0..$#{$_[$k]}){$a=\$_[$k][$_];$$a!~/\d/&&next;$t=$$a;for($_+1..$#{$_[$k]}){$_=${$b=\$_[$k][$_]};last if/</||($"eq$_&&!$d);/\d/?($t=$$a+=$_,$$b='',redo):0}}}}l@x;p@x;$_=$t
504 symbols perl failed test 1 Code error

Modification of a read-only value attempted at ./code line 2, <> line 1.

Sat Aug 30 08:28:32 2014 gabrielmad
#!/usr/bin/perl -p
$x[$.][$-[1]]=$1while/(\d+|.)/g}{sub p{$i=$k=0;for$a(@_){$j=0;(/</?($s=\$_[$i][$j],$u=\$_[$i-1][$j+4],$d=\$_[$i+1][$j+4],($$u=~/\d/&&$$d=~/\d/)?($r=$$u*$$d/($$u+$$d),$p=$_[$i][$j-2],$$u=$$d='',($$s)="/"eq$p?('',$_[$i+1][$j]=$r):"\\"eq$p?('',$_[$i-1][$j]=$r):$r):$k++):0),$j++for@$a;$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for(0..$#{$_[$k]}){$a=\$_[$k][$_];$$a!~/\d/&&next;$t=$$a;for($_+1..$#{$_[$k]}){$_=${$b=\$_[$k][$_]};last if/</||($"eq$_&&!$d);/\d/?($t=$$a+=$_,$$b='',redo):0}}}}l@x;p@x;$_=$t
497 symbols perl failed test 1 Code error

Modification of a read-only value attempted at ./code line 2, <> line 1.

Sat Aug 30 08:46:18 2014 gabrielmad
#!/usr/bin/perl -p
$x[$.][$-[1]]=$1while/(\d+|.)/g}{sub p{$i=$k=0;for$a(@_){$j=0;(/</?($s=\$_[$i][$j],$u=\$_[$i-1][$j+4],$d=\$_[$i+1][$j+4],$$u=~/\d/&&$$d=~/\d/?($r=$$u*$$d/($$u+$$d),$_=$_[$i][$j-2],$$u=$$d='',($$s)=/\//?('',$_[$i+1][$j]=$r):/\\/?('',$_[$i-1][$j]=$r):$r):$k++):0),$j++for@$a;$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for(0..$#{$_[$k]}){$a=\$_[$k][$_];$$a!~/\d/&&next;$t=$$a;for$j($_+1..$#{$_[$k]}){$_=${$b=\$_[$k][$j]};last if/</||($"eq$_&&!$d);/\d/?($t=$$a+=$_,$$b='',redo):0}}}}l@x;p@x;$_=$t
492 symbols perl failed test 1 Code error

Modification of a read-only value attempted at ./code line 2, <> line 1.

Sat Aug 30 08:56:17 2014 gabrielmad
#!/usr/bin/perl -p
$x[$.][$-[1]]=$1while/(\d+|.)/g}{sub p{$i=$k=0;for$a(@_){$j=0;(/</?($s=\$_[$i][$j],$u=\$_[$i-1][$j+4],$d=\$_[$i+1][$j+4],$$u=~/\d/&&$$d=~/\d/?($r=$$u*$$d/($$u+$$d),$_=$_[$i][$j-2],$$u=$$d='',($$s)=/\//?('',$_[$i+1][$j]=$r):/\\/?('',$_[$i-1][$j]=$r):$r):$k++):0),$j++for@$a;$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for(0..$#{$_[$k]}){$a=\$_[$k][$_];$$a!~/\d/&&next;$t=$$a;for$j($_+1..$#{$_[$k]}){$_=${$b=\$_[$k][$j]};/</||/$"/&&!$d&&last;/\d/?($t=$$a+=$_,$$b='',redo):0}}}}l@x;p@x;$_=$t
492 symbols perl failed test 1 Code error

Modification of a read-only value attempted at ./code line 2, <> line 1.

Sat Aug 30 08:58:49 2014 gabrielmad
#!/usr/bin/perl -p
$x[$.][$-[1]]=$1while/(\d+|.)/g}{sub p{$i=$k=0;for$a(@_){$j=0;(/</?($s=\$_[$i][$j],$u=\$_[$i-1][$j+4],$d=\$_[$i+1][$j+4],$$u=~/\d/&&$$d=~/\d/?($r=$$u*$$d/($$u+$$d),$_=$_[$i][$j-2],$$u=$$d='',($$s)=/\//?('',$_[$i+1][$j]=$r):/\\/?('',$_[$i-1][$j]=$r):$r):$k++):0),$j++for@$a;$i++}p(@_)if$k;$d=1;l(@_)}sub l{for$k(0..$#_){for(0..$#{$_[$k]}){$a=\$_[$k][$_];$$a!~/\d/&&next;$t=$$a;for$j($_+1..$#{$_[$k]}){$_=${$b=\$_[$k][$j]};/</||/$"/&&!$d&&last;/\d/?($t=$$a+=$_,$$b='',redo):0}}}}l@x;p@x;$_=$t

View all solutions