Skip to main content
Commonmark migration
Source Link

Octave, 65 60 50 bytes

Edit: Saved 10 bytes thanks to pawel.boczarski

An approximate solution...

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)

Test run

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([0   182   255])
ans =  196.14

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([127   247   103])
ans =  111.05

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([0   0   1])
ans =  240.00

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([255   165   245])
ans =  305.82

Octave, 107 bytes

My original (exact-ish) solution...

###Code: function H=r(c) [b,i]=sort(c);h=60*6*(i(1)~=3),2,4;H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

Code:

###Explained:

function H=r(c) [b,i]=sort(c);h=60*[6*(i(1)~=3),2,4](i);H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

Explained:

function H=r(c)
   [b,i]=sort(c);
   h=60*[6*(i(1)~=3),2,4](i);
   H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

This function takes a vector containing the R,G,B values as input c and sorts the input in ascending order

  • b contains the sorted values [z, y, x]
  • i contains the RGB plane associated with each value in b

The vector h is populated with the values

  • 60*[6, 2, 4] = [360, 120, 240] (but 3 bytes shorter)
  • unless the lowest value is in Blue (i(1) == 3), in which case the first hue value becomes zero
  • then use (i) to rearrange h into [h(Z), h(Y), h(X)] order

From there it's just a straight transcription of the formula. You can try it here.

Octave, 65 60 50 bytes

Edit: Saved 10 bytes thanks to pawel.boczarski

An approximate solution...

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)

Test run

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([0   182   255])
ans =  196.14

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([127   247   103])
ans =  111.05

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([0   0   1])
ans =  240.00

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([255   165   245])
ans =  305.82

Octave, 107 bytes

My original (exact-ish) solution...

###Code: function H=r(c) [b,i]=sort(c);h=60*6*(i(1)~=3),2,4;H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

###Explained:

function H=r(c)
   [b,i]=sort(c);
   h=60*[6*(i(1)~=3),2,4](i);
   H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

This function takes a vector containing the R,G,B values as input c and sorts the input in ascending order

  • b contains the sorted values [z, y, x]
  • i contains the RGB plane associated with each value in b

The vector h is populated with the values

  • 60*[6, 2, 4] = [360, 120, 240] (but 3 bytes shorter)
  • unless the lowest value is in Blue (i(1) == 3), in which case the first hue value becomes zero
  • then use (i) to rearrange h into [h(Z), h(Y), h(X)] order

From there it's just a straight transcription of the formula. You can try it here.

Octave, 65 60 50 bytes

Edit: Saved 10 bytes thanks to pawel.boczarski

An approximate solution...

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)

Test run

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([0   182   255])
ans =  196.14

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([127   247   103])
ans =  111.05

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([0   0   1])
ans =  240.00

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([255   165   245])
ans =  305.82

Octave, 107 bytes

My original (exact-ish) solution...

Code:

function H=r(c) [b,i]=sort(c);h=60*[6*(i(1)~=3),2,4](i);H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

Explained:

function H=r(c)
   [b,i]=sort(c);
   h=60*[6*(i(1)~=3),2,4](i);
   H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

This function takes a vector containing the R,G,B values as input c and sorts the input in ascending order

  • b contains the sorted values [z, y, x]
  • i contains the RGB plane associated with each value in b

The vector h is populated with the values

  • 60*[6, 2, 4] = [360, 120, 240] (but 3 bytes shorter)
  • unless the lowest value is in Blue (i(1) == 3), in which case the first hue value becomes zero
  • then use (i) to rearrange h into [h(Z), h(Y), h(X)] order

From there it's just a straight transcription of the formula. You can try it here.

Removed the explicit function handle and used `ans` instead.
Source Link
beaker
  • 2.6k
  • 1
  • 10
  • 18

Octave, 65 60 50 5250 bytes

Edit: Saved 10? 810 bytes thanks to pawel.boczarski

An approximate solution...

r=@@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)

Added handle anonymous function pending clarification on whether the function will work without it.

Test run

r@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([0   182   255])
ans =  196.14

r@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([127   247   103])
ans =  111.05

r@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([0   0   1])
ans =  240.00

r@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([255   165   245])
ans =  305.82

Octave, 107 bytes

My original (exact-ish) solution...

###Code: function H=r(c) [b,i]=sort(c);h=60*6*(i(1)~=3),2,4;H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

###Explained:

function H=r(c)
   [b,i]=sort(c);
   h=60*[6*(i(1)~=3),2,4](i);
   H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

This function takes a vector containing the R,G,B values as input c and sorts the input in ascending order

  • b contains the sorted values [z, y, x]
  • i contains the RGB plane associated with each value in b

The vector h is populated with the values

  • 60*[6, 2, 4] = [360, 120, 240] (but 3 bytes shorter)
  • unless the lowest value is in Blue (i(1) == 3), in which case the first hue value becomes zero
  • then use (i) to rearrange h into [h(Z), h(Y), h(X)] order

From there it's just a straight transcription of the formula. You can try it here.

Octave, 65 60 50 52 bytes

Edit: Saved 10? 8 bytes thanks to pawel.boczarski

An approximate solution...

r=@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)

Added handle anonymous function pending clarification on whether the function will work without it.

Test run

r([0   182   255])
ans =  196.14

r([127   247   103])
ans =  111.05

r([0   0   1])
ans =  240.00

r([255   165   245])
ans =  305.82

Octave, 107 bytes

My original (exact-ish) solution...

###Code: function H=r(c) [b,i]=sort(c);h=60*6*(i(1)~=3),2,4;H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

###Explained:

function H=r(c)
   [b,i]=sort(c);
   h=60*[6*(i(1)~=3),2,4](i);
   H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

This function takes a vector containing the R,G,B values as input c and sorts the input in ascending order

  • b contains the sorted values [z, y, x]
  • i contains the RGB plane associated with each value in b

The vector h is populated with the values

  • 60*[6, 2, 4] = [360, 120, 240] (but 3 bytes shorter)
  • unless the lowest value is in Blue (i(1) == 3), in which case the first hue value becomes zero
  • then use (i) to rearrange h into [h(Z), h(Y), h(X)] order

From there it's just a straight transcription of the formula. You can try it here.

Octave, 65 60 50 bytes

Edit: Saved 10 bytes thanks to pawel.boczarski

An approximate solution...

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)

Test run

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([0   182   255])
ans =  196.14

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([127   247   103])
ans =  111.05

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([0   0   1])
ans =  240.00

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)
ans([255   165   245])
ans =  305.82

Octave, 107 bytes

My original (exact-ish) solution...

###Code: function H=r(c) [b,i]=sort(c);h=60*6*(i(1)~=3),2,4;H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

###Explained:

function H=r(c)
   [b,i]=sort(c);
   h=60*[6*(i(1)~=3),2,4](i);
   H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

This function takes a vector containing the R,G,B values as input c and sorts the input in ascending order

  • b contains the sorted values [z, y, x]
  • i contains the RGB plane associated with each value in b

The vector h is populated with the values

  • 60*[6, 2, 4] = [360, 120, 240] (but 3 bytes shorter)
  • unless the lowest value is in Blue (i(1) == 3), in which case the first hue value becomes zero
  • then use (i) to rearrange h into [h(Z), h(Y), h(X)] order

From there it's just a straight transcription of the formula. You can try it here.

Added handle to anonymous function (for now?) just to be safe...
Source Link
beaker
  • 2.6k
  • 1
  • 10
  • 18

Octave, 65 60 5050 52 bytes

Edit: Saved 1010? 8 bytes thanks to pawel.boczarski

An approximate solution...

@r=@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)

Added handle anonymous function pending clarification on whether the function will work without it.

Test run

r([0   182   255])
ans =  196.14

r([127   247   103])
ans =  111.05

r([0   0   1])
ans =  240.00

r([255   165   245])
ans =  305.82

Octave, 107 bytes

My original (exact-ish) solution...

###Code: function H=r(c) [b,i]=sort(c);h=60*6*(i(1)~=3),2,4;H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

###Explained:

function H=r(c)
   [b,i]=sort(c);
   h=60*[6*(i(1)~=3),2,4](i);
   H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

This function takes a vector containing the R,G,B values as input c and sorts the input in ascending order

  • b contains the sorted values [z, y, x]
  • i contains the RGB plane associated with each value in b

The vector h is populated with the values

  • 60*[6, 2, 4] = [360, 120, 240] (but 3 bytes shorter)
  • unless the lowest value is in Blue (i(1) == 3), in which case the first hue value becomes zero
  • then use (i) to rearrange h into [h(Z), h(Y), h(X)] order

From there it's just a straight transcription of the formula. You can try it here.

Octave, 65 60 50 bytes

Edit: Saved 10 bytes thanks to pawel.boczarski

An approximate solution...

@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)

Test run

r([0   182   255])
ans =  196.14

r([127   247   103])
ans =  111.05

r([0   0   1])
ans =  240.00

r([255   165   245])
ans =  305.82

Octave, 107 bytes

My original (exact-ish) solution...

###Code: function H=r(c) [b,i]=sort(c);h=60*6*(i(1)~=3),2,4;H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

###Explained:

function H=r(c)
   [b,i]=sort(c);
   h=60*[6*(i(1)~=3),2,4](i);
   H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

This function takes a vector containing the R,G,B values as input c and sorts the input in ascending order

  • b contains the sorted values [z, y, x]
  • i contains the RGB plane associated with each value in b

The vector h is populated with the values

  • 60*[6, 2, 4] = [360, 120, 240] (but 3 bytes shorter)
  • unless the lowest value is in Blue (i(1) == 3), in which case the first hue value becomes zero
  • then use (i) to rearrange h into [h(Z), h(Y), h(X)] order

From there it's just a straight transcription of the formula. You can try it here.

Octave, 65 60 50 52 bytes

Edit: Saved 10? 8 bytes thanks to pawel.boczarski

An approximate solution...

r=@(c)mod(atan2d(.866*c*[0;1;-1],c*[2;-1;-1]/2),360)

Added handle anonymous function pending clarification on whether the function will work without it.

Test run

r([0   182   255])
ans =  196.14

r([127   247   103])
ans =  111.05

r([0   0   1])
ans =  240.00

r([255   165   245])
ans =  305.82

Octave, 107 bytes

My original (exact-ish) solution...

###Code: function H=r(c) [b,i]=sort(c);h=60*6*(i(1)~=3),2,4;H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

###Explained:

function H=r(c)
   [b,i]=sort(c);
   h=60*[6*(i(1)~=3),2,4](i);
   H=(h(3)-h(2))*(1+(b(3)-b(2))/(b(3)-b(1)))/2+h(2);

This function takes a vector containing the R,G,B values as input c and sorts the input in ascending order

  • b contains the sorted values [z, y, x]
  • i contains the RGB plane associated with each value in b

The vector h is populated with the values

  • 60*[6, 2, 4] = [360, 120, 240] (but 3 bytes shorter)
  • unless the lowest value is in Blue (i(1) == 3), in which case the first hue value becomes zero
  • then use (i) to rearrange h into [h(Z), h(Y), h(X)] order

From there it's just a straight transcription of the formula. You can try it here.

Changed to anonymous function thanks to pawel.boczarski.
Source Link
beaker
  • 2.6k
  • 1
  • 10
  • 18
Loading
Removed return value. Removed trailing semicolon to force result to be sent to console.
Source Link
beaker
  • 2.6k
  • 1
  • 10
  • 18
Loading
Added test run for new code.
Source Link
beaker
  • 2.6k
  • 1
  • 10
  • 18
Loading
added 190 characters in body
Source Link
beaker
  • 2.6k
  • 1
  • 10
  • 18
Loading
Source Link
beaker
  • 2.6k
  • 1
  • 10
  • 18
Loading