
Task

Given    10×10    grid nodes   (as shown in the image)   interconnected by    1Ω    resistors as shown,

find the resistance between points   A   and   B.



See also

   (humor, nerd sniping)   xkcd.com cartoon


      INSTALL @lib$+"ARRAYLIB"
      *FLOAT 64
      @% = &F0F
 
      PRINT "Resistance = "; FNresistormesh(10, 10, 1, 1, 7, 6) " ohms"
      END
 
      DEF FNresistormesh(ni%, nj%, ai%, aj%, bi%, bj%)
      LOCAL c%, i%, j%, k%, n%, A(), B()
      n% = ni% * nj%
      DIM A(n%-1, n%-1), B(n%-1, 0)
      FOR i% = 0 TO ni%-1
        FOR j% = 0 TO nj%-1
          k% = i% * nj% + j%
          IF i% = ai% AND j% = aj% THEN
            A(k%, k%) = 1
          ELSE
            c% = 0
            IF (i% + 1) < ni% c% += 1 : A(k%, k% + nj%) = -1
            IF i% > 0         c% += 1 : A(k%, k% - nj%) = -1
            IF (j% + 1) < nj% c% += 1 : A(k%, k% + 1)   = -1
            IF j% > 0         c% += 1 : A(k%, k% - 1)   = -1
            A(k%, k%) = c%
          ENDIF
        NEXT
      NEXT
      k% = bi% * nj% + bj%
      B(k%, 0) = 1
      PROC_invert(A())
      B() = A().B()
      = B(k%, 0)