Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Quite a few bytes saved thanks to rahnema1's idea (Octave answer) rahnema1's idea (Octave answer) of collapsing two convolutions into one

Quite a few bytes saved thanks to rahnema1's idea (Octave answer) of collapsing two convolutions into one

Quite a few bytes saved thanks to rahnema1's idea (Octave answer) of collapsing two convolutions into one

edited body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

Quite a few bytes saved thanks to rahnnema'srahnema1's idea (Octave answer) of collapsing two convolutions into one

Quite a few bytes saved thanks to rahnnema's idea (Octave answer) of collapsing two convolutions into one

Quite a few bytes saved thanks to rahnema1's idea (Octave answer) of collapsing two convolutions into one

added 67 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
  1. To detect vertical and horizontal neighbours, which contribute a distance of 1, the requiresrequired mask would be

    0 1 0
    1 0 1
    0 1 0
    

ToSimilarly, to detect diagonal neighbours, which contribute a distance of sqrt(2), the mask would be

If this mask is multiplied by sqrt(2) and added to the first, the two convolutions can be replaced by one convolution with the combined mask

  1. To detect startStart and end points. These are, by definition, the points with only one neighbour. SeTo detect them we convolve with

    1 1 1
    1 0 1
    1 1 1
    

To generateproduce the combined mask of item 1 it's shorter to producegenerate its square and then take the square root. MaskThe mask in item 2 is a predefined literal.

  1. To detect vertical and horizontal neighbours, which contribute a distance of 1, the requires mask would be

    0 1 0
    1 0 1
    0 1 0
    

To detect diagonal neighbours, which contribute a distance of sqrt(2), the mask would be

If mask is multiplied by sqrt(2) and added to the first, the two convolutions can be replaced by one with the mask

  1. To detect start and end points. These are by definition the points with only one neighbour. Se we convolve with

    1 1 1
    1 0 1
    1 1 1
    

To generate mask 1 it's shorter to produce its square and then take the square root. Mask 2 is a predefined literal.

  1. To detect vertical and horizontal neighbours, which contribute a distance of 1, the required mask would be

    0 1 0
    1 0 1
    0 1 0
    

Similarly, to detect diagonal neighbours, which contribute a distance of sqrt(2), the mask would be

If this mask is multiplied by sqrt(2) and added to the first, the two convolutions can be replaced by one convolution with the combined mask

  1. Start and end points are, by definition, the points with only one neighbour. To detect them we convolve with

    1 1 1
    1 0 1
    1 1 1
    

To produce the combined mask of item 1 it's shorter to generate its square and then take the square root. The mask in item 2 is a predefined literal.

added 6 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
added 6 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
added 11 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
added 1 character in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
deleted 7 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
deleted 7 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
deleted 37 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
added 2460 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
added 5 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
deleted 4 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
deleted 1 character in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading

AltStyle によって変換されたページ (->オリジナル) /