Use 16 colors while writing Hey! 4 times

7

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: Reference output Obviously colours will vary based on terminal colour scheme.

Scoring

This is , so lowest bytes wins.

figgycity50

Posted 2016-07-10T11:28:35.217

Reputation: 727

9

"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 – 2016-07-10T11:33:39.107

11

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 – 2016-07-10T11:35:51.060

3Is the example order of colors binding, or may we use any order as long as all 16 are used? – Adám – 2016-07-10T18:01:01.373

Can I write "Heyyyyy..."?

– A. Mirabeau – 2016-08-02T03:25:56.540

Answers

7

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.

Digital Trauma

Posted 2016-07-10T11:28:35.217

Reputation: 64 644

3

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:

Looks like this on my phone

betseg

Posted 2016-07-10T11:28:35.217

Reputation: 8 493

1

SmileBASIC, 39 bytes

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

12Me21

Posted 2016-07-10T11:28:35.217

Reputation: 6 110

1

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

brhfl

Posted 2016-07-10T11:28:35.217

Reputation: 1 291

1

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.

miles

Posted 2016-07-10T11:28:35.217

Reputation: 15 654

Doesn't this do only one single output of the entire string? – Adám – 2016-07-10T18:14:44.423

1

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!

Marco

Posted 2016-07-10T11:28:35.217

Reputation: 581

1

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)

Adám

Posted 2016-07-10T11:28:35.217

Reputation: 37 779

1

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

TheBikingViking

Posted 2016-07-10T11:28:35.217

Reputation: 3 674

1

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(^)

Blue

Posted 2016-07-10T11:28:35.217

Reputation: 26 661

1

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

Titus

Posted 2016-07-10T11:28:35.217

Reputation: 13 814

1Hooray 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! – Dom Hastings – 2017-08-15T11:48:51.717

0

4, 392 bytes

3.600486014960250603516045260553606546075560957610276119161318012111362072623336241062530021112402211255105115035005125205105115035015125215105115035025125225105115035035125235105115035045125205105115035055125215105115035065125225105115035075125235105115095005125205105115095015125215105115095025125225105115095035125235105115095045125205105115095055125215105115095065125225105115095075125234

Try it online!

Tip: use the -verbose flag.

Uriel

Posted 2016-07-10T11:28:35.217

Reputation: 11 708

Is it this language? http://esolangs.org/wiki/4

– Jerry Jeremiah – 2017-08-16T03:44:07.953

@JerryJeremiah yes – Uriel – 2017-08-16T08:38:43.857

0

Perl 5, 50 bytes

49 bytes code + 1 for -p. Note that \x1b is a literal escape character. Utilises empty input which TIO doesn't support, so a newline is provided and not used.

$_="Hey!"x4;s/./\x1b[@{[(30..37,90..97)[$-++]]}m$&/g

Try it online!

Dom Hastings

Posted 2016-07-10T11:28:35.217

Reputation: 16 415

0

PowerShell, 41 Bytes.

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

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

enter image description here

colsw

Posted 2016-07-10T11:28:35.217

Reputation: 3 195

0

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>

Roman Gräf

Posted 2016-07-10T11:28:35.217

Reputation: 2 915