# 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? – Martin Ender Jul 10 '16 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. – Martin Ender Jul 10 '16 at 11:35
• Is the example order of colors binding, or may we use any order as long as all 16 are used? – Adám Jul 10 '16 at 18:01
• Can I write "Heyyyyy..."? – A. Mirabeau Aug 2 '16 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:

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? – Adám Jul 10 '16 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: $ octave hey.m
Hey!Hey!Hey!Hey!


## Pyke, 25 bytes

"Hey!"4*F\mo8.D6*3+"["s_


Try it here!

                           - o = 0
"Hey!"4*                   -   "Hey!Hey!Hey!Hey!"
F                  -  for i in ^:
-   stack = [i]
\m                -   stack.append("m")
o               -    o += 1
8.D            -   stack.extend(divmod(^, 8))
6*3+        -   stack[-1] = stack[-1]*6+3
"["     -   stack.append("[\x1b")
s  -   stack = sum(stack)
_ -  stack = reverse(stack)
- print "".join(^)


# Python 3, 81 bytes

print(*['\33[%sm%s'%(i,'Hey!'[i%4-2])for i in range(30,98)if not 37<i<90],sep='')


A full program that prints to STDOUT.

How it works

for i in range(30,98)...       For all possible colour codes i in [30,97]...
...if not 37<i<90              If i is in the desired range [30,37] or [90,97]...
'\33[%sm%s'%(i,'Hey!'[i%4-2])  ...create a string of the form
'\033[{colour code}m{current string character}'...
[...]                          ...and store all strings in a list X
print(*...,sep='')             Print all strings in X with no separating space


Try it on CodingGround

# SmileBASIC, 39 bytes

FOR I=0TO 15COLOR I?("Hey!"*4)[I];
NEXT


# APL (Dyalog), 38 41 bytes

Now returns right result too!

∊(⍕¨∊29 89∘.+⍳8){'\e[',⍺,'m',⍵}¨16⍴'Hey!'


Try it online!

16⍴'Hey!' cyclically reshape the string to length 16

(){}¨ apply the below anonymous function to each letter pairing it with the corresponding element for this list as left argument:

⍳8 1 through 8
29 89∘.+ addition table with these numbers vertically and those horizontally
∊ϵnlist (flatten)
⍕¨ format (stringify) each

'm',⍵ prepend an "m"
⍺, prepend the left argument
'\e[', prepend the string

∊ϵnlist (flatten)

# 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

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.