Rainbows tend to be pretty cool to look at. If you're lucky you'll even find a pot of gold at the end of one. Today's problem is to create a program that generates a random RGB hex value (#7A340E) then prints out the next 100 values (#7A340F, #7A3410, etc.) after that. Afterwards it should print out "POT OF GOLD!!" and then exit.
Comments:
Dan - 10 years, 7 months ago
Quick javascript ```javascript var r = ~~(Math.random() * 255), g = ~~(Math.random() * 255), b = ~~(Math.random() * 255); var currentDigit = 0; console.log("#" + r.toString(16) + g.toString(16) + b.toString(16)); for(var i = 0; i < 100; i++) { if(b >= 254) currentDigit++; if(g >= 254) currentDigit++; b = (b+1) % 255; if(currentDigit==1) g = (g+1) % 255; if(currentDigit==2) r = (r+1) % 255;
} console.log("POT OF GOLD"); ```
reply permalink
Dan Brinkman - 10 years, 7 months ago
Whoops not logged in, here's the javascript with proper formatting
reply permalink
Pyro - 10 years, 7 months ago
Python solution
reply permalink
Anonymous - 10 years, 6 months ago
reply permalink