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

Update MATL Online URL
Source Link
Suever
  • 11.2k
  • 1
  • 24
  • 52

MATL, (削除) 30 (削除ここまで) (削除) 29 (削除ここまで) 25 bytes

2ZG:i:!J*+2&!-|i<so2&!1YG

Input format:

  • Colormap as a matrix of values between 0 and 255, where each row defines a color
  • W
  • H
  • Column vector of 1-based center coordinates as complex values (x is the real part, y is the imaginary part)
  • Column vector of radii.

Try at MATL Online! MATL Online! Or verify the last test case verify the last test case. (The interpreter is still experimental. You may need to refresh the page and try again if it doesn't work).

Explanation

The code uses complex numbers to define the grid of points and to compute distances, and makes heavy use of array operations with broadcasting.

2ZG % Implicitly input matrix of colors. Set as colormap
: % Implicitly input W. Push [1 2 ... W]
i: % Input H. Push [1 2 ... H]
!J* % Transpose, multiply by 1i
+ % Add element-wise with broadcast. Gives ×ばつW grid of points as
 % complex numbers, 1-based 
2&! % Permute first dimension with the third. Gives a ×ばつH array
-| % Implicitly input center coordinates. Subtract grid from them,
 % element-wise with broadcast. Gives a ×ばつW array, where C is the
 % number of circles
i % Input column vector of circle radii
< % Less than, element-wise with broadcast
so % Sum along first dimension, modulo 2. Gives a ×ばつH array
2&! % Permute first dimension with the third. Gives a a ×ばつW array
1YG % Display as scaled image

MATL, (削除) 30 (削除ここまで) (削除) 29 (削除ここまで) 25 bytes

2ZG:i:!J*+2&!-|i<so2&!1YG

Input format:

  • Colormap as a matrix of values between 0 and 255, where each row defines a color
  • W
  • H
  • Column vector of 1-based center coordinates as complex values (x is the real part, y is the imaginary part)
  • Column vector of radii.

Try at MATL Online! Or verify the last test case. (The interpreter is still experimental. You may need to refresh the page and try again if it doesn't work).

Explanation

The code uses complex numbers to define the grid of points and to compute distances, and makes heavy use of array operations with broadcasting.

2ZG % Implicitly input matrix of colors. Set as colormap
: % Implicitly input W. Push [1 2 ... W]
i: % Input H. Push [1 2 ... H]
!J* % Transpose, multiply by 1i
+ % Add element-wise with broadcast. Gives ×ばつW grid of points as
 % complex numbers, 1-based 
2&! % Permute first dimension with the third. Gives a ×ばつH array
-| % Implicitly input center coordinates. Subtract grid from them,
 % element-wise with broadcast. Gives a ×ばつW array, where C is the
 % number of circles
i % Input column vector of circle radii
< % Less than, element-wise with broadcast
so % Sum along first dimension, modulo 2. Gives a ×ばつH array
2&! % Permute first dimension with the third. Gives a a ×ばつW array
1YG % Display as scaled image

MATL, (削除) 30 (削除ここまで) (削除) 29 (削除ここまで) 25 bytes

2ZG:i:!J*+2&!-|i<so2&!1YG

Input format:

  • Colormap as a matrix of values between 0 and 255, where each row defines a color
  • W
  • H
  • Column vector of 1-based center coordinates as complex values (x is the real part, y is the imaginary part)
  • Column vector of radii.

Try at MATL Online! Or verify the last test case. (The interpreter is still experimental. You may need to refresh the page and try again if it doesn't work).

Explanation

The code uses complex numbers to define the grid of points and to compute distances, and makes heavy use of array operations with broadcasting.

2ZG % Implicitly input matrix of colors. Set as colormap
: % Implicitly input W. Push [1 2 ... W]
i: % Input H. Push [1 2 ... H]
!J* % Transpose, multiply by 1i
+ % Add element-wise with broadcast. Gives ×ばつW grid of points as
 % complex numbers, 1-based 
2&! % Permute first dimension with the third. Gives a ×ばつH array
-| % Implicitly input center coordinates. Subtract grid from them,
 % element-wise with broadcast. Gives a ×ばつW array, where C is the
 % number of circles
i % Input column vector of circle radii
< % Less than, element-wise with broadcast
so % Sum along first dimension, modulo 2. Gives a ×ばつH array
2&! % Permute first dimension with the third. Gives a a ×ばつW array
1YG % Display as scaled image
Commonmark migration
Source Link

#MATL , (削除) 30 (削除ここまで)(削除) 29 (削除ここまで) 25 bytes

MATL , (削除) 30 (削除ここまで)(削除) 29 (削除ここまで) 25 bytes

2ZG:i:!J*+2&!-|i<so2&!1YG

Input format:

  • Colormap as a matrix of values between 0 and 255, where each row defines a color
  • W
  • H
  • Column vector of 1-based center coordinates as complex values (x is the real part, y is the imaginary part)
  • Column vector of radii.

Try at MATL Online! Or verify the last test case. (The interpreter is still experimental. You may need to refresh the page and try again if it doesn't work).

###Explanation

Explanation

The code uses complex numbers to define the grid of points and to compute distances, and makes heavy use of array operations with broadcasting.

2ZG % Implicitly input matrix of colors. Set as colormap
: % Implicitly input W. Push [1 2 ... W]
i: % Input H. Push [1 2 ... H]
!J* % Transpose, multiply by 1i
+ % Add element-wise with broadcast. Gives ×ばつW grid of points as
 % complex numbers, 1-based 
2&! % Permute first dimension with the third. Gives a ×ばつH array
-| % Implicitly input center coordinates. Subtract grid from them,
 % element-wise with broadcast. Gives a ×ばつW array, where C is the
 % number of circles
i % Input column vector of circle radii
< % Less than, element-wise with broadcast
so % Sum along first dimension, modulo 2. Gives a ×ばつH array
2&! % Permute first dimension with the third. Gives a a ×ばつW array
1YG % Display as scaled image

#MATL , (削除) 30 (削除ここまで)(削除) 29 (削除ここまで) 25 bytes

2ZG:i:!J*+2&!-|i<so2&!1YG

Input format:

  • Colormap as a matrix of values between 0 and 255, where each row defines a color
  • W
  • H
  • Column vector of 1-based center coordinates as complex values (x is the real part, y is the imaginary part)
  • Column vector of radii.

Try at MATL Online! Or verify the last test case. (The interpreter is still experimental. You may need to refresh the page and try again if it doesn't work).

###Explanation

The code uses complex numbers to define the grid of points and to compute distances, and makes heavy use of array operations with broadcasting.

2ZG % Implicitly input matrix of colors. Set as colormap
: % Implicitly input W. Push [1 2 ... W]
i: % Input H. Push [1 2 ... H]
!J* % Transpose, multiply by 1i
+ % Add element-wise with broadcast. Gives ×ばつW grid of points as
 % complex numbers, 1-based 
2&! % Permute first dimension with the third. Gives a ×ばつH array
-| % Implicitly input center coordinates. Subtract grid from them,
 % element-wise with broadcast. Gives a ×ばつW array, where C is the
 % number of circles
i % Input column vector of circle radii
< % Less than, element-wise with broadcast
so % Sum along first dimension, modulo 2. Gives a ×ばつH array
2&! % Permute first dimension with the third. Gives a a ×ばつW array
1YG % Display as scaled image

MATL , (削除) 30 (削除ここまで)(削除) 29 (削除ここまで) 25 bytes

2ZG:i:!J*+2&!-|i<so2&!1YG

Input format:

  • Colormap as a matrix of values between 0 and 255, where each row defines a color
  • W
  • H
  • Column vector of 1-based center coordinates as complex values (x is the real part, y is the imaginary part)
  • Column vector of radii.

Try at MATL Online! Or verify the last test case. (The interpreter is still experimental. You may need to refresh the page and try again if it doesn't work).

Explanation

The code uses complex numbers to define the grid of points and to compute distances, and makes heavy use of array operations with broadcasting.

2ZG % Implicitly input matrix of colors. Set as colormap
: % Implicitly input W. Push [1 2 ... W]
i: % Input H. Push [1 2 ... H]
!J* % Transpose, multiply by 1i
+ % Add element-wise with broadcast. Gives ×ばつW grid of points as
 % complex numbers, 1-based 
2&! % Permute first dimension with the third. Gives a ×ばつH array
-| % Implicitly input center coordinates. Subtract grid from them,
 % element-wise with broadcast. Gives a ×ばつW array, where C is the
 % number of circles
i % Input column vector of circle radii
< % Less than, element-wise with broadcast
so % Sum along first dimension, modulo 2. Gives a ×ばつH array
2&! % Permute first dimension with the third. Gives a a ×ばつW array
1YG % Display as scaled image
added 4 characters in body; added 3 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382

#MATL, (削除) 30 (削除ここまで) (削除) 29 (削除ここまで) 25 bytes

2ZG:i:!J*+2&!-|i<so2&!1YG

Input format:

  • Colormap as a matrix of values between 0 and 255, where each row defines a color
  • W
  • H
  • Column vector of 1-based center coordinates as complex values (x is the real part, y is the imaginary part)
  • Column vector of radii.

Try at MATL Online! Or verify the last test case. (The interpreter is still experimental. You may need to refresh the page and try again if it doesn't work).

###Explanation

ThisThe code uses complex numbers to define the grid of points and to compute distances, and makes heavy use of array operations with broadcasting.

2ZG % Implicitly input matrix of colors. Set as colormap
: % Implicitly input W. Push [1 2 ... W]
i: % Input H. Push [1 2 ... H]
!J* % Transpose, multiply by 1i
+ % Add element-wise with broadcast. Gives ×ばつW grid of points as
 % complex numbers, 1-based 
2&! % Permute first dimension with the third. Gives a ×ばつH array
-| % Implicitly input center coordinates. Subtract grid from them,
 % element-wise with broadcast. Gives a ×ばつW array, where C is the
 % number of circles
i % Input column vector of circle radii
< % Less than, element-wise with broadcast
so % Sum along first dimension, modulo 2. Gives a ×ばつH array
2&! % Permute first dimension with the third. Gives a a ×ばつW array
1YG % Display as scaled image

#MATL, (削除) 30 (削除ここまで) (削除) 29 (削除ここまで) 25 bytes

2ZG:i:!J*+2&!-|i<so2&!1YG

Input format:

  • Colormap as a matrix of values between 0 and 255, where each row defines a color
  • W
  • H
  • Column vector of 1-based center coordinates as complex values (x is the real part, y is the imaginary part)
  • Column vector of radii.

Try at MATL Online! Or verify the last test case. (The interpreter is still experimental. You may need to refresh the page and try again if it doesn't work).

###Explanation

This uses complex numbers to define the grid of points and compute distances, and makes heavy use of array operations with broadcasting.

2ZG % Implicitly input matrix of colors. Set as colormap
: % Implicitly input W. Push [1 2 ... W]
i: % Input H. Push [1 2 ... H]
!J* % Transpose, multiply by 1i
+ % Add element-wise with broadcast. Gives ×ばつW grid of points as
 % complex numbers, 1-based 
2&! % Permute first dimension with the third. Gives a ×ばつH array
-| % Implicitly input center coordinates. Subtract grid from them,
 % element-wise with broadcast. Gives a ×ばつW array, where C is the
 % number of circles
i % Input column vector of circle radii
< % Less than, element-wise with broadcast
so % Sum along first dimension, modulo 2. Gives a ×ばつH array
2&! % Permute first dimension with the third. Gives a a ×ばつW array
1YG % Display as scaled image

#MATL, (削除) 30 (削除ここまで) (削除) 29 (削除ここまで) 25 bytes

2ZG:i:!J*+2&!-|i<so2&!1YG

Input format:

  • Colormap as a matrix of values between 0 and 255, where each row defines a color
  • W
  • H
  • Column vector of 1-based center coordinates as complex values (x is the real part, y is the imaginary part)
  • Column vector of radii.

Try at MATL Online! Or verify the last test case. (The interpreter is still experimental. You may need to refresh the page and try again if it doesn't work).

###Explanation

The code uses complex numbers to define the grid of points and to compute distances, and makes heavy use of array operations with broadcasting.

2ZG % Implicitly input matrix of colors. Set as colormap
: % Implicitly input W. Push [1 2 ... W]
i: % Input H. Push [1 2 ... H]
!J* % Transpose, multiply by 1i
+ % Add element-wise with broadcast. Gives ×ばつW grid of points as
 % complex numbers, 1-based 
2&! % Permute first dimension with the third. Gives a ×ばつH array
-| % Implicitly input center coordinates. Subtract grid from them,
 % element-wise with broadcast. Gives a ×ばつW array, where C is the
 % number of circles
i % Input column vector of circle radii
< % Less than, element-wise with broadcast
so % Sum along first dimension, modulo 2. Gives a ×ばつH array
2&! % Permute first dimension with the third. Gives a a ×ばつW array
1YG % Display as scaled image
deleted 188 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
added 1219 characters in body
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading
added 1219 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
Source Link
Luis Mendo
  • 106.7k
  • 10
  • 139
  • 382
Loading

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