'Removing gray from RGB. I am using coral to learn programming + its apart of a course

Problem :

Summary: Given integer values for red, green, and blue, subtract the gray from each value.

Computers represent color by combining the sub-colors red, green, and blue (rgb). Each sub-color's value can range from 0 to 255. Thus (255, 0, 0) is bright red, (130, 0, 130) is a medium purple, (0, 0, 0) is black, (255, 255, 255) is white, and (40, 40, 40) is a dark gray. (130, 50, 130) is a faded purple, due to the (50, 50, 50) gray part. (In other words, equal amounts of red, green, blue yield gray).

Given values for red, green, and blue, remove the gray part.

Ex: If the input is 130 50 130, the output is:

80 0 80

My code :

integer red

integer green

integer blue

integer gray

red = Get next input

green = Get next input

blue = Get next input

gray = 50

if red >= 50 and red <= 255

red = red - gray

Put red to output

elseif green >= 50 and green <= 255

green = green - gray

Put green to output

elseif blue >= 50 and blue <= 255

blue = blue - gray

Put blue to output

I need help trying to substract the smallest value from an input of three numbers rather than just 50 and output those three integers rather than just the first integer.

Note : I wanted to use the 'min' function but there is not much in the built in library for coral. I think this challenge wants to focus on branching.

(I can fairly read and understand python and java code as well if you wanted to help me using them)



Solution 1:[1]

integer red
integer green
integer blue
integer grey

red = Get next input
green = Get next input
blue = Get next input

if red < green and red < blue 
   grey = red
elseif green < red and green < blue
   grey = green
else 
   grey = blue

red = red - grey
green = green - grey
blue = blue - grey

Put red to output
Put " " to output
Put green to output
Put " " to output
Put blue to output
Put " " to output

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sid Hartman