# Use 16 colors while writing Hey! 4 times

i.e each byte appears in a different ANSI shell colour.

# Rules

• Resetting the color of the shell after output is not required
• Must be output in STDOUT or the primary colour text output of your language.
• Must be done programmatically (iterating through each color and letter of the string induvidually) instead of just writing a fixed string to shell like the reference command.
• Must output the same as the reference command: echo -e '\e[30mH\e[31me\e[32my\e[33m!\e[34mH\e[35me\e[36my\e[37m!\e[90mH\e[91me\e[92my\e[93m!\e[94mH\e[95me\e[96my\e[97m!' on a recent version of bash (I am using 4.3 installed via Homebrew on OS X) i.e like this: Obviously colours will vary based on terminal colour scheme.

# Scoring

This is , so lowest bytes wins.

• "Must be done programmatically (with iteration) instead of just writing a fixed string to shell like the reference command." Restrictions like this are highly problematic (several other answers on that post also apply). For a start it's not clear how much iteration is enough: can I have a loop with only two iterations that prints the first half and then the second half? Can I have a loop with ten iterations that prints the string on the first run and does nothing at all on the other nine? Jul 10, 2016 at 11:33
• If you're worried that printing the fixed string is always going to beat printing the output in a loop, then that usually indicates a problem of the challenge. Either, loops are going to beat fixed-output answers, in which case the restriction is unnecessary, or the fixed-output answers will be shorter in which case the restriction seems like a very artifical patch to a fundamental problem of the challenge. Jul 10, 2016 at 11:35
• Is the example order of colors binding, or may we use any order as long as all 16 are used?
Jul 10, 2016 at 18:01
• Can I write "Heyyyyy..."? Aug 2, 2016 at 3:25

# Bash, 62

h=y!He
for i in {3,9}{0..7};do printf \\e[${i}m${h:i%4:1};done


Must be run from an actual script file. If you want to try it from the command line, you'll need to escape the !, i.e. h=y\!He

Online.

# C, 126 bytes

#define a"\x1B[%d;%dm"
#define b j,i++
i,j;main(){for(;i=30,j<2;j++)printf(a"H"a"e"a"y"a"!"a"H"a"e"a"y"a"!",b,b,b,b,b,b,b,b);}


output may vary depending on your compiler, linker, operating system, and processor

Ideone doesn't have colour output, so have a screenshot from my phone:

# bash, 101 72 bytes

29 bytes saved with a trick from @DomHastings.

s='y!He'
for i in {30..37} {90..97}
do
printf "\e["$i"m"${s:$i%4:1} done  If I hadn´t scrambled the string, this would have been 105 (($i+2)%4 instead of $i%4), just as my previous approach, 105 bytes function p { s='Hey!' for i in {0..3} do let r=i+$1
printf "\e["$r"m"${s:$i:1} done } p 30;p 34;p 90;p 94  • Hooray for bash! Looks like you can use one brace expansion and negate the need for the if (... for i in {30..37} {90..97} ...) for 72! Aug 15, 2017 at 11:48 # dc, 72 71 bytes Fi4C 2:c6B 3:c81 0:c23 1:c28si20[d1CP61Pn74Pd4%;cP1+dli>P]dsPx68si60lPx  Of course the escape codes won't render right on TIO, but you can still try it online! First we set our input to base 15, this is solely for the sake of saving a byte. Make an array, c, of the code points for 'y', '!', 'H', and 'e'. We'll exploit the fact that 30 mod 4 == 90 mod 4; for both of our sets of color values, value mod 4 starts at 2, so that's where we put our 'H' in the array. From there it's just a matter of setting up a loop that runs until we hit the value stored in i. We have our color code on the stack, we print the necessary escape codes, print the stack value, mod 4 and print that value from the array c, then increment the stack. We run through this once starting from 30 w/ i set at 38, then once more starting from 90 w/ i set at 98. Shaved off one byte by doing everything in base 15; decimal version below for slightly more clarity: 72 2:c101 3:c121 0:c33 1:c38si30[d27P91Pn109Pd4%;cP1+dli>P]dsPx98si90lPx  # J, 59 bytes echo,(u:27 91),"1(16$'Hey!'),.~'m',.~,/30 90":@+/i.8
exit''


Save it as a script to run using J. It will print the output to stdout with the escaped colors.

• Doesn't this do only one single output of the entire string?
Jul 10, 2016 at 18:14

# Octave, 78 bytes

c=[b=[a="\x1b[30m"' a a a;'Hey!'] b];c(4,:)+=0:7;d=c;d(3,:)+=6;disp([c d](:)')


Usage:

If the code is in a file hey.m:

Try it online!

# PowerShell, 41 Bytes.

0..15|%{Write-Host -n('Hey!'[$_%4])-f$_}


The day we get an alias for Write-Host is a good day.

# JavaScript 134 bytes

<script>
var a=0;
var c=["H","e","y","!"];
for(;a<3;){
var b=-1;
for(;++b<4;){
document.write(<b style='color:rgb(0,0,"+(a*4+b)+"'>"+c[b]);
}
}
</script>


Golfed

<script>a=0;c=["H","e","y","!"];for(;a++<3;){b=-1;for(;++b<4;){document.write(<b style='color:rgb(0,0,"+(a*4+b)+"'>"+c[b]);}}</script>