-6
\$\begingroup\$

Write a program, which outputs I'm Blue, and then Da, Ba, Dee, Da, Ba, Die, forever, the words must be space-seperated in one line, and it must pause 0.4 to 0.6 seconds after printing each word. Also, the text should be outputted in the color blue 0x0000FF or in ANSI escape code blues.

So the output must be something like this: enter image description here

You can use any programming language you want. The output can be in either text or image form (escape codes allowed!).

This is , so shortest program in bytes wins!

\$\endgroup\$
8
  • 2
    \$\begingroup\$ Welcome to Code Golf and nice first question! For future reference, we recommend using the Sandbox to get feedback on challenge ideas before posting them to main. You might want to allow some lenience with the 0.5s (0.45s to 0.55s or something). Also, should it pause between "I'm" and "Blue"? \$\endgroup\$
    – emanresu A
    Sep 13, 2022 at 20:05
  • 4
    \$\begingroup\$ Also, can we use 4-bit ANSI escape code blues which aren't exactly #0000FF, or do we have to use 8-bit or truecolour? (context: Many answers will print the output to a terminal) \$\endgroup\$
    – emanresu A
    Sep 13, 2022 at 20:12
  • 1
    \$\begingroup\$ Should the words be space-separated, or could each word optionally be on its own line? \$\endgroup\$ Sep 14, 2022 at 8:32
  • 1
    \$\begingroup\$ +1 to Kevin's question - I'm guessing that the requirement "without any trailing newlines" is actually talking about when we print a word we cannot print a newline, rather than saying that after "forever" has passed we can't print a newline (unobservable) - but clarity would be good. \$\endgroup\$ Sep 14, 2022 at 17:35
  • 2
    \$\begingroup\$ Your challenge and the tags contradict eachother. You say it has to generate a specific output, but that output has to run forever. Therefore, the output is always changing. The question has kolmogorov-complexity, which requires a constant output. I don't think this challenge matches that tag, as the whole output is never constant. If I'm wrong, please ignore me. \$\endgroup\$ Sep 14, 2022 at 23:24

6 Answers 6

2
\$\begingroup\$

05AB1E, 46 45 bytes

27ç"ÿ[34mI'm"?…žå°êèÞ#5∍'—ǪÞ'‡—š',«™1úε₄;.W?

Uses an ANSI escape code to print in blue (which is rgb(0,55,218) in Windows 10 by default - see screenshot below - but could be changed to the required rgb(0,0,255) in the console properties itself if necessary).

Try it online (with the sleep ₄;.W removed).

Screenshot:
enter image description here

Explanation:

27ç             # Push 27, and convert it to a character with this codepoint: <ESC>
   "ÿ[34mI'm"   # Push this string, where `ÿ` is filled with the earlier <ESC> character
             ?  # Pop and print it (without newline)
…žå°êèÞ         # Push dictionary string "da ba dee"
       #        # Split it on spaces: ["da","ba","dee"]
        5∍      # Extend it to size 5: ["da","ba","dee","da","ba"]
          '—Ç  '# Push dictionary string "die"
             ª  # Append it to the list: ["da","ba","dee","da","ba","die"]
Þ               # Cycle this list indefinitely:
                #  ["da","ba","dee","da","ba","die","da","ba","dee","da",...]
 '‡—           '# Push dictionary string "blue"
    š           # Prepend it in front of the infinite list
     ',«       '# Append a comma to each string
        ™       # Titlecase each word
         1ú     # Prepend a leading space to each string
ε               # Foreach over the list:
 ₄;             #  Push 500 (push 1000 and halve it)
   .W           #  Pop and sleep that many millisecond
     ?          #  Print the string (without newline)

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why …žå°êèÞ is "da ba dee"; '—Ç is "die"; and '‡— is "blue".

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Thanks a lot! But you can save one byte by using for titlecased dictionary-compressed strings \$\endgroup\$
    – HelloWorld
    Sep 15, 2022 at 18:35
  • 1
    \$\begingroup\$ @HelloWorld Unfortunately not, since uses both an opening and closing quote, so …žå°êèÞ, '—Ç, and '‡— would all three become ”žå°êèÞ”/”—Ç”/”‡—”, making it +3 bytes to save the -1 byte of . :) \$\endgroup\$ Sep 16, 2022 at 6:59
2
\$\begingroup\$

HTML + JavaScript (All Browsers), 30 + 77 = 107 24 + 90 = 114 24 + 87 = 111 bytes

i=5
setInterval(a=>b.append("Da0Ba0Dee0Da0Ba0Die0Blue".split(0)[(i<6)+i++%6]+", "),500)
<body id=b text=blue>I'm 


+7 because the original code didn't match the spec.
-3 from @jdt for using .append(...) instead of .innerHTML+=...

\$\endgroup\$
4
  • \$\begingroup\$ It looks like your cycle is starting on "Ba" in the snippet, should be an easy fix \$\endgroup\$
    – xnor
    Sep 17, 2022 at 19:57
  • \$\begingroup\$ @xnor Hm, it's working for me; what browser are you using? \$\endgroup\$ Sep 17, 2022 at 20:04
  • \$\begingroup\$ Chrome on Windows \$\endgroup\$
    – xnor
    Sep 17, 2022 at 20:25
  • \$\begingroup\$ The issue is that the code depends on the number of calls to setInterval/setTimeout and how the browser assigns them IDs. It seems that in this context, on Firefox / Chrome (?) it always starts at 3, and in Brave it starts at 8 (???), but I don't know if I can rely on that. \$\endgroup\$ Sep 17, 2022 at 20:40
1
\$\begingroup\$

HTML + JavaScript, 22 18 + 90 89 88 86 = 104 bytes

setInterval("b.append(`${'Da Ba Dee Da Ba Die Blue'.split` `[i++%7]}, `);i%=6",i=419)
<a href=# id=b>I'm

-6 bytes: use .append() instead of .before(), use setInterval string eval (from @jdt)

\$\endgroup\$
2
  • \$\begingroup\$ There was a stray ` character at the end of your javascript. \$\endgroup\$
    – jdt
    Sep 23, 2022 at 17:51
  • \$\begingroup\$ And since the link has been visited, the text is now coming out in purple :-) \$\endgroup\$
    – jdt
    Sep 23, 2022 at 17:53
1
\$\begingroup\$

Python 3, 135 bytes

import time
def f(l):[print(end=i+' ')==time.sleep(.5)for i in l.split()]
f("\033[34mI'm Blue,")
while 1:f("Da, Ba, Dee, Da, Ba, Die,")

Works on Windows Command Prompt

Try it online!

Python 3, 145 bytes

import time
def f(l):[print(end=i+' ',flush=1)==time.sleep(.5)for i in l.split()]
f("\033[1;34mI'm Blue,")
while 1:f("Da, Ba, Dee, Da, Ba, Die,")

Works on MacOS iTerm

Try it online!

-8 thanks to 97.100.97.109

Python 3, 196 bytes

from time import*;from itertools import*
p=print;s=sleep
p(end="\033[1;33mI'm ",flush=1);s(.5)
p(end="Blue, ",flush=1)
for i in cycle(['Da','Ba','Dee','Da','Ba','Die']):s(.5);p(end=i+', ',flush=1)

Works on MacOS iTerm

Try it online!


Note: on TIO, colours aren't shown, and everything gets shown when the program finishes. Here is a video of this running on another editor:

Output

\$\endgroup\$
17
  • \$\begingroup\$ I have an answer that uses a 3rd party library and is 40 bytes shorter, waiting to see if you can outgolf me! \$\endgroup\$ Sep 23, 2022 at 13:08
  • \$\begingroup\$ Now it’s 29 bytes shorter \$\endgroup\$ Sep 24, 2022 at 2:46
  • \$\begingroup\$ @py3programmer - 24 bytes shorter than yours, no 3rd party libraries. \$\endgroup\$
    – The Thonnu
    Sep 24, 2022 at 6:16
  • \$\begingroup\$ Just reduced mine by 4 bytes, will golf when I have more time. \$\endgroup\$ Sep 24, 2022 at 16:54
  • \$\begingroup\$ @py3programmer, I don't think yours outputs a comma between "Da", "Ba", etc. \$\endgroup\$
    – The Thonnu
    Sep 24, 2022 at 16:55
1
\$\begingroup\$

Python 3 + colorama, 177 176 175 167 166 162 160 bytes

I used colorama when I was interested in coloring stdout, and it certainly should help here!

(Also used because The Thonnu's answer was really long)

import colorama,time;colorama.init()
def m(n):[print(end=i+" ")==time.sleep(.5)for i in n.split()]
m("\033[34mI'm Blue,")
while 1:m("Da, Ba, Dee, Da, Ba, Die,")

How to use:

As The Thonnu pointed out, this program fails on TIO, so to execute it:

  1. Download IDLE (if you don't have it)
  2. Open your terminal
  3. Type py -m pip install colorama
  4. Create a new file
  5. Copy the code
  6. Save it (here it will be colored.py)
  7. Type py -m colored (or whatever you saved the file as without the py part) on your terminal.

See this video that shows it being done.

Direct downloading version, 223 bytes:

Will download colorama from pip and executes.

import os,time
os.system("py -mpip install colorama")
import colorama;colorama.init
m=lambda n:print(end="\033[34m"+n)or time.sleep(.5)
m("I'm ");m("Blue, ")
while 1:
    for i in['Da','Ba','Dee','Da','Ba','Die']:m(i+", ");

Non-Windows version, 135 bytes:

On windows platforms, Colorama is required for initializing the terminal. Other ones, don't think so.

import time
def m(n):[print(end=i+' ')==time.sleep(.5)for i in n.split()]
m("\033[34mI'm Blue,")
while 1:m("Da, Ba, Dee, Da, Ba, Die,")
\$\endgroup\$
7
  • \$\begingroup\$ I don't think that works, because you need the flush=1 in print if you use it in combination with time.sleep If you don't have that, nothing will print. \$\endgroup\$
    – The Thonnu
    Oct 2, 2022 at 12:39
  • \$\begingroup\$ It does work for me. \$\endgroup\$ Oct 2, 2022 at 12:41
  • \$\begingroup\$ I'm using CMD prompt \$\endgroup\$ Oct 2, 2022 at 12:41
  • \$\begingroup\$ Ok, then on your computer, I can take 8 bytes off my answer, making it 4 bytes shorter than yours. \$\endgroup\$
    – The Thonnu
    Oct 2, 2022 at 12:42
  • \$\begingroup\$ Doesn't matter; now my code's on a tie. \$\endgroup\$ Oct 2, 2022 at 12:52
0
\$\begingroup\$

Batch, 148 bytes

@set/p=␛[94mI'm <nul
@call:c Blue
:l
@for %%i in (Da Ba Dee Da Ba Die) do @call:c %%i
@goto l
:c
@ping 192.512 -n 1 -w 500>nul
@set/p=%1, <nul

Note: represents the Escape character (^[). Explanation:

@set/p=␛[94mI'm <nul

Set the text colour to bright blue and write the initial I'm without starting a new line.

@call:c Blue

Start with the word Blue.

:l
@for %%i in (Da Ba Dee Da Ba Die)do @call:c %%i
@goto l

Loop over the remaining words, and then repeat indefinitely.

:c
@ping 192.512 -n 1 -w 500>nul
@set/p=%1, <nul

Wait 500ms, and then output the word with a trailing , without starting a new line. 192.512 is a reserved IP address and it should not be possible to ping it, so the ping will time out after 0.5s as desired.

\$\endgroup\$
1
  • \$\begingroup\$ @DLosc Thanks, fixed. \$\endgroup\$
    – Neil
    Sep 18, 2022 at 6:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.