Animate the text in your terminal

46

7

Animate the text in your terminal

The goal

The goal is to "animate" the string "Hello world" in your output so that each character gets capitalised after each other.

Your program can exit after each letter has been capitalised.

For example;

# Iteration 1
Hello world

# Iteration 2
hEllo world

# Iteration 3
heLlo world

# Iteration 4
helLo world

# Iteration 5
hellO world

# Iteration 6 (note: it should capitilize the space char (ie: a break between iteration 5 and iteration 7)
hello world

# Iteration 7
hello World

# Iteration 8
hello wOrld

# Iteration 9
hello woRld

# Iteration 10
hello worLd

# Iteration 11
hello worlD

It should only animate the string once and between each state there should be a 1 second delay.

Input

No input is required, but "Hello world" must be the string that is "animated".

Output

The string "Hello world" must be animated. The output must be as 1 line to create a sort of wave animation. An empty trailing new line is allowed. Example gif;

https://i.gyazo.com/be12b693063b463540c5bf1f03d2454a.gif

I saw this on a metasploit youtube video and thought the effect was pretty cool, which is where I recorded the gif from, so it's a little laggy, but I hope it illustrates the output fine

This is , lowest byte-count will be deemed the winner.

Sandbox Link

ʰᵈˑ

Posted 2017-02-13T10:04:49.527

Reputation: 1 426

Can it exit and stop with an error? – Stewie Griffin – 2017-02-13T12:26:45.323

@StewieGriffin as long as the animation is viewable, sure. – ʰᵈˑ – 2017-02-13T13:38:23.730

I don't think the 1 second delay adds to the challenge. We've had a bunch like that and each time it seems like the same boilerplate is added. – xnor – 2017-02-13T13:39:07.283

2@xnor Do you mean the duration of the delay being 1 second explicitly, or do you mean any delay at all? Latter wouldn't make any sense since it's an animation after all.. – Metoniem – 2017-02-13T13:43:40.180

@Metoniem Any fixed-time delay. – xnor – 2017-02-13T13:44:14.837

Oh, in that case I agree for sure. Writing 1000 instead of 1 costs me 3 bytes already >:( @xnor – Metoniem – 2017-02-13T13:45:58.777

@ʰᵈˑAre additional leading iterations allowed? – Metoniem – 2017-02-14T14:44:17.020

1@Metoniem No, only the ones described in the goal. Unless I've misunderstood. Each letter must be capitalised once from left to right once only, starting with "H" in "hello" and ending with "D" in "world" – ʰᵈˑ – 2017-02-14T17:06:54.563

@ʰᵈˑYou understood! Okay then, thanks. – Metoniem – 2017-02-15T08:17:29.473

For a better view of this effect as seen when starting the Metasploit Framework: Metasploit For Beginners - #1 @~5:50

– 3D1T0R – 2018-07-16T19:05:15.397

Answers

33

Vim 26 bytes

ihello world<ESC>qq~gsul@qq0@q

Explanation (no .gif yet):

First, we must enter the 'hello world' text. This is pretty straightforward. It's just:

ihello world<ESC>

At this point, the cursor is on the 'd' in 'world'. Next:

qq              " Start recording into register 'q'
  ~             " Swap the case of the character underneath the cursor, and move the cursor to the right
   gs           " Sleep for one second
     u          " Undo the last change (of swapping case).
      l         " Move one character to the right (Get it? 'l' == 'Right' because vim is intuitive!)
                " This will cause the error to break on the last character of the input.
       @q       " Call register 'q'
         q      " Stop recording
          0     " Move to the first character
           @q   " Call the recursive macro

There are also two other 26 byte versions I found:

ihello world<ESC>qq~gsulq011@q
ihello world<ESC>011@='~gsul'<cr>

James

Posted 2017-02-13T10:04:49.527

Reputation: 54 537

Man that's cool! Here's the output: https://i.gyazo.com/52d0b9268446aed36ce7eb641c40ff6c.gif (half of it anyway, Gyazo stopped recording)

– ʰᵈˑ – 2017-02-13T10:46:42.270

I don't think ~ breaks the loop. I believe it's the l that does the hard work

– user41805 – 2017-02-13T16:23:22.910

@KritixiLithos Ah, after testing it, it seems you're right. Good point, I'll edit that out – James – 2017-02-13T16:24:48.483

1Can confirm -- This works. – SIGSTACKFAULT – 2017-02-13T19:48:37.880

15

Python 2, 98 94 90 bytes

for x in range(11):s='hello world';print'\r'+s[:x]+s[x:].capitalize(),;[1for y in' '*8**8]

-9 -4 bytes thanks to @ElPedro -4 bytes thanks to @JonathanAllan and @Rod

Trelzevir

Posted 2017-02-13T10:04:49.527

Reputation: 987

3Welcome to PPCG, nice first post c: – Rod – 2017-02-13T11:24:10.173

2

Nice post! This seems to have a capital "H" and "W" at the same time though https://repl.it/Fhii - It seems to not lowercase the "H"

– ʰᵈˑ – 2017-02-13T11:25:00.600

1

About the printing problem, you can pass -u argument and use print"\t"+s[:x]+s[x:].title(),; (note the trailing comma). And this won't change your byte count (because the argument would add +2 bytes)

– Rod – 2017-02-13T11:38:45.983

Isn't each flag only one byte? Or am I confusing two different topics? @Rod – Timtech – 2017-02-13T11:45:17.323

@Timtech hmm, I couldn't find any meta topic about, but other answers count as 2 – Rod – 2017-02-13T11:51:24.280

@Rod Strange I can't either, maybe I am missing something. – Timtech – 2017-02-13T12:01:59.697

2@Rod The flag would count as one byte because an acceptable invocation for Python is python -c 'code here'. With the flag, the invocation would be python -uc 'code here', which is one byte different. – Mego – 2017-02-13T13:16:43.367

print"\r"+s[:x]+s[x:].capitalize(),; doesn't require an extra flag – JMat – 2017-02-13T14:03:47.513

@JMat Technically? No. In practice? Yes.

– Rod – 2017-02-13T14:30:03.000

1Pretty much your version, but 95 bytes and clears the screen (I tested with 2.7.8 on Windows 7-64). Try It Online does not give the animation, just the line by line result. – Jonathan Allan – 2017-02-13T15:02:37.010

@JonathanAllan i=-11 with while i: also works (to save 1 byte) – Rod – 2017-02-13T16:08:58.410

@Rod, that it does. – Jonathan Allan – 2017-02-13T16:35:28.947

You can get it down to 85 by replacing sleep with a "time-wasting" loop [1for y in' '*8**8] and doing away with the import. 8**8 gives a delay of approximately one second on my machine but will vary depending on hardware. Doesn't actually work on Try it online! as it just dumps the whole list at the end but the code is there for reference.

– ElPedro – 2017-02-14T15:16:40.093

My mistake. Actually 90 because .title() will always capitalize the w after the space. Updated with capitalize() Try it online!. Sorry about that.

– ElPedro – 2017-02-14T17:58:13.967

1@ElPedro thanks for pointing this out, already corrected this mistake previously, so forgot to check again. – Trelzevir – 2017-02-14T18:17:55.187

12

Commodore 64, 168 162 137 133 BASIC (and tokenized) bytes used

 0s=1024:?"{control+n}{clear home}hello world":fOi=.to1:fOj=.to11:x=pE(s+j):pokes+j,x+64
 1x=pE(1023+j):pO1023+j,abs(x-64):pO1029,32:pO1035,32:fOz=.to99:i=.:nEz,j,i

You will need to use BASIC keyword abbreviations to enter this into a real C64 or emulator (or enter the program into a Commodore 128 and load it back in C64 mode, although this should work on the 128 as well). The {control+n} will only work/display after the opening quote. It is shorthand for chr$(14) and therefore saves some bytes and switches the character set to business mode or upper/lower case characters.

I have added in some abbreviations for you so you. The {clear home} character is made by pressing Shift and the CLR/HOME key after the opening quotation mark.

For illustrative purposes the unobfustcated listing may be entered as follows:

 0 let s=1024
 1 print chr$(14); chr$(147); "hello world"
 2 for i=0 to 1
 3  for j=0 to 11
 4   let x=peek(s + j)
 5   poke s + j, x + 64
 6   let x=peek(1023 + j)
 7   poke 1023 + j, abs(x - 64)
 8   poke 1029, 32
 9   poke 1035, 32
10   for z=0 to 99
11    let i=0
12   next z
13  next j
14 next i

It works by switching the PETSCII charset into business mode (upper/lower case), and writing the hello world string to the top line of the screen which is located at memory location $0400, it will then take the value at each location for the next 11 bytes from there and increase each value by 64 (the upper case equivalent). If the j counter is > 0, it calls a routine at line 2 to decrease the previous memory location by 64 again.

Line 3 is a pause, it also writes a space to to location $0405 and $040b, which is a bug fix (which could probably be removed to save some bytes).

Commodore C64 animated hello world

Shaun Bebbers

Posted 2017-02-13T10:04:49.527

Reputation: 1 814

I should add that fori=0to1step0 ... nexti is essentially creating an infinite (goto-less) loop, kind of like while(true){...} in more modern languages. – Shaun Bebbers – 2017-02-13T17:21:05.083

1Why don't you just use a goto instead of an infinite loop? Even with the 2 newlines that would have to be added, it would still save bytes. Also RAM bytes isn't the same as the number of bytes in your code. – MilkyWay90 – 2018-11-12T02:42:55.303

Because GO TO is banned, right ;-) One may easily work out the listing by itself by CLR before working out the remain free bytes with the broken FRE(0) function – Shaun Bebbers – 2018-11-12T17:03:27.120

1oh sorry about that – MilkyWay90 – 2018-11-13T00:04:51.213

11

C#, 230 215 193 161 135 134 130 bytes

It's C# so it's long right! :-( But after some help and searching, I (and others, really) managed to remove exactly 100 bytes already.

Golfed

()=>{for(int i=1;;){var b="\rhello world".ToCharArray();b[i++]-=' ';System.Console.Write(b);System.Threading.Thread.Sleep(1000);}}

Ungolfed

class P
{
    static void Main()
    {
        for (int i = 1;;)
        {
            var b = "\rhello world".ToCharArray();
            b[i++] -= ' ';
            System.Console.Write(b);
            System.Threading.Thread.Sleep(1000);
        }
    }
}

Screenshot

Animation with 1 second delay Although it looks alot better when looping and faster..

Updates

  • Lost 15 bytes by using carriage return instead of Clear() which also allowed me to replace a using with System.Consolesomewhere inline.

  • Replaced program with lambda saving 23 bytes thanks to @devRicher

  • It became kind of a collaboration with @devRicher at this point, thanks to some of his suggestions I managed to lose another 32 bytes!
  • Thanks to 2 really smart and interesting suggestions by @Kratz I managed to replace new string(b) with b and b[i]=char.ToUpper(b[i]) with b[i]-=' ', saving me another 26 bytes!
  • 1 byte less by moving i++ thanks to @Snowfire
  • 4 bytes less by moving carriage return to the beginning of the string and removing i<11 from my for loop

Metoniem

Posted 2017-02-13T10:04:49.527

Reputation: 387

1Change class P{static void Main(){ ... }} to ()=>{ ... } to snip off a few bytes. PPCG accepts functions as answers, so a lambda works fine. – devRicher – 2017-02-13T12:29:48.787

@devRicher Ah I see, I never used lambas before, but that seems like a cool improvement. Thanks! – Metoniem – 2017-02-13T12:32:33.100

If you don't know how to use them (or don't want to), its still fine for a simple void g(){ ... }. – devRicher – 2017-02-13T12:33:16.793

You can access strings with array indices (char g = string j[x]), to save around 50 bytes: ()=>{var s="Hello world";for(int i=1;i<11;i++){string h = s;h[i]=char.ToUpper(s[i]);System.Console.Write(h+"\r");System.Threading.Thread.Sleep(1000);}} – devRicher – 2017-02-13T12:39:08.943

@devRicher I know you can access them using indices, but unfortunately they're readonly, so I think that might not work here. Correct me if I'm wrong though! – Metoniem – 2017-02-13T12:46:24.057

Sorry, yeah, I got that wrong. I'll look for more stuff to golf. i love c# answers – devRicher – 2017-02-13T12:57:22.603

How about ()=>{var s="Hello world\r".ToCharArray();for(int i=1;i<11;i++){var b=s;b[i]=char.ToUpper(s[i]);System.Console.Write(new string(b));System.Threading.Thread.Sleep(1000);}}? Not sure if Hello World\r yields right results, but I changed up other parts of it too. – devRicher – 2017-02-13T13:15:41.507

@devRicher This turns them all uppercase and not lowercase anymore. Probably because b is just a pointer to s, also if we would actually copy the array and use this, I think the "H" in Hello world will stay capitalized which isn't supposed to happen. The idea behind it is nice, though! – Metoniem – 2017-02-13T13:21:54.500

Let us continue this discussion in chat.

– Metoniem – 2017-02-13T13:24:53.963

Instead of Char.ToUpper, you can do s[i]-=' '; Also, write will take an array of char, no need to make a new string, just Write(s). – Kratz – 2017-02-13T20:40:04.150

@Kratz that sounds interesting. Let me try that real quick! – Metoniem – 2017-02-14T08:11:46.423

@Kratz Woah, the -=' ' is very smart. Added both to my answer, thanks! – Metoniem – 2017-02-14T08:24:05.600

1You can save another byte by removing the incrementation from the for clause and putting it in the array access like b[i++]-=' '. That would come in handy, because then you could also remove the condition in the for loop and just write for(int i=0;;). OP pointed out in the comments, that the program may exit with an error, so you can allow an IndexOutOfRangeException – Snowfire – 2017-02-14T13:15:58.177

@Snowfire Nice find! Thanks (edit: See you edited your comment, you're right, removing the condition from the for loop will work, thanks again!) – Metoniem – 2017-02-14T13:20:21.223

Actually @Snowfire I'm afraid I will have to rollback the removal of that condition. I forgot it'll then reach \r too, and '\r'-' ' becomes ? which is then printed :-( – Metoniem – 2017-02-14T14:30:59.290

I wasn't 100% sure about that either, but it isn't really specified, whether that is allowed or not. – Snowfire – 2017-02-14T14:37:16.233

@Snowfire True.. I asked in a comment just now. i'll leave it out of my answer until I know for sure. – Metoniem – 2017-02-14T14:44:57.407

@BenVoigt Not possible without casting to int I think. – Metoniem – 2017-02-15T21:40:35.317

I'm wondering if you can use the exact carriage return character (0x0d) instead of \r in your code to save 1 more byte. – Chromium – 2018-07-19T03:16:09.523

10

Powershell, 126 119 107 104 Bytes

'Hello world';$s='hello world';1..10|%{sleep 1;cls;-join($s[0..($_-1)]+[char]($s[$_]-32)+$s[++$_..11])}

enter image description here

Revisions (there will likely be many):

Change $s.Length to const 10 11

Restructured string builder, removed 1 join statement and used ++$s instead of ($s+1), to save some bytes thanks to @AdmBorkBork

AdmBorkBork points out just using the string twice is actually shorter than encapsulating and then .ToLower()'ing it - which says a lot about how verbose powershell is, -3!


basically loop through the length of the string, form an array of three parts, the pre-capitcal, capital, and post-capital, take 32 away from the middle letter, then convert back to a char to get upper case, luckily this doesn't turn space into a visible character either, I hope this is acceptable?

colsw

Posted 2017-02-13T10:04:49.527

Reputation: 3 195

2You can save three more bytes off the front by simply printing the string rather than saving it into $s and .ToLower()ing it. -- 'Hello world';$s='hello world'; – AdmBorkBork – 2017-02-13T14:24:18.480

102 bytes inline-ing $s – Veskah – 2019-07-18T15:21:13.640

9

CP-1610 assembly, 50 DECLEs = 63 bytes

This code is intended to be run on an Intellivision.

A CP-1610 opcode is encoded with a 10-bit value, known as a 'DECLE'. This program is 50 DECLEs long, starting at $4800 and ending at $4831.

                                  ROMW  10          ; use 10-bit ROM
                                  ORG   $4800       ; start program at address $4800

                          main    PROC
4800 0002                         EIS               ; enable interrupts (to enable display)

4801 0001                         SDBD              ; load pointer to string in R4
4802 02BC 0026 0048               MVII  #@@str, R4

4805 02A2                         MVI@  R4,     R2  ; R2 = length of string
4806 0091                         MOVR  R2,     R1  ; R1 = uppercase counter

4807 02BD 0214            @@loop  MVII  #$214,  R5  ; R5 = video memory pointer
4809 0093                         MOVR  R2,     R3  ; R3 = character counter

480A 02A0                 @@next  MVI@  R4,     R0  ; R0 = next character
480B 0338 0020                    SUBI  #32,    R0  ; minus 32 -> character #
480D 004C                         SLL   R0,     2   ; multiply by 8 to get the
480E 0048                         SLL   R0          ; correct GROM card
480F 03F8 0007                    XORI  #7,     R0  ; add 7 (for white)

4811 014B                         CMPR  R1,     R3  ; uppercase? ...
4812 020C 0002                    BNEQ  @@draw

4814 0338 0100                    SUBI  #256,   R0  ; ... yes: sub 32*8

4816 0268                 @@draw  MVO@  R0,     R5  ; draw character
4817 0013                         DECR  R3          ; decrement character counter
4818 022C 000F                    BNEQ  @@next      ; process next character or stop

481A 0001                         SDBD              ; R0 = spin counter to wait ~1 second
481B 02B8 0038 00D3               MVII  #$D338, R0  ;    = 54072 = 13518 * 60 / 15
                                                    ; (assuming 13518 cycles per frame)

481E 0010                 @@spin  DECR  R0          ; 6 cycles
481F 022C 0002                    BNEQ  @@spin      ; 9 cycles
                                                    ; -> 15 cycles per iteration

4821 0114                         SUBR  R2,     R4  ; reset pointer to beginning of string
4822 0011                         DECR  R1          ; decrement uppercase counter
4823 022C 001D                    BNEQ  @@loop      ; process next iteration or stop

4825 0017                         DECR  PC          ; infinite loop

4826 000B 0068 0065 006C  @@str   STRING 11, "hello world"
482A 006C 006F 0020 0077
482E 006F 0072 006C 0064
                                  ENDP

Output

enter image description here

Arnauld

Posted 2017-02-13T10:04:49.527

Reputation: 111 334

7

MATL, 30 bytes

11:"10&Xx'hello world't@)Xk@(D

Try it at MATL Online!

11:              % Push [1 2 ... 11]
  "              % For each k in [1 2 ... 11]
  10&Xx          %   Pause for 10 tenths of a second and clear screen
  'hello world'  %   Push this string
  t              %   Duplicate
  @)             %   Get the k-th character from the duplicated string
  Xk             %   Convert to uppercase
  @(             %   Write into the k-th position of the string
  D              %   Display
                 % Implicit end

Luis Mendo

Posted 2017-02-13T10:04:49.527

Reputation: 87 464

5

PHP, 76 74 71 bytes

Thank you @hd for the delay being a full second and no fraction thereof!
Thanks @user63956 for 2 bytes and @aross for 3 bytes.

for(;$c=($s="hello world")[$i];sleep(print"$s\r"))$s[$i++]=ucfirst($c);

Run with -nr.

Titus

Posted 2017-02-13T10:04:49.527

Reputation: 13 814

1You can save 2 bytes with sleep(print"$s\r"). – user63956 – 2017-02-14T05:54:46.230

1

Save 3 bytes with ucfirst

– aross – 2017-02-15T15:11:24.093

4

C, 97 withdrawn 106 bytes

with escaped characters counted as 1 byte

char*a="HELLO\0WORLD\xED";b,c;m(){for(b=0;b<156;putchar(a[c]+32*(b/12^c||c==5)))(c=b++%12)||fflush(sleep(1));}

Note: I have commented out the time delay on unlinked TIO because it waits for completion before displaying the output, it also doesn't seem to recognize carriage returns and puts new lines. Also, if you're on Windows, sleep is in milliseconds instead of seconds, so sleep(1) should become sleep(1000).

Note 2: I've withdrawn this entry for the moment until the output bugs have been ironed out.

Ahemone

Posted 2017-02-13T10:04:49.527

Reputation: 608

For some reason, this doesn't output anything on my machine – user41805 – 2017-02-13T12:35:48.520

If you're on windows you will have to change the delay, it will also finish on a carriage return so you may want to change 130 to 129 so it avoids printing it during the last iteration. – Ahemone – 2017-02-13T12:38:25.277

For me this program does not end at all, and it doesn't output anything. I had to manually ^C it to stop it . (also I'm on mac) – user41805 – 2017-02-13T12:40:20.137

I believe it's a print buffer issue, I'll withdraw my entry for now. – Ahemone – 2017-02-13T12:57:55.267

4

JavaScript (ES6), 141 139 131 bytes

Saved 8B thanks to Apsillers

_=>a=setInterval("b=[...`hello world`],c.clear(b[d]=b[d].toUpperCase(++d>10&&clearInterval(a))),c.log(b.join``)",1e3,c=console,d=0)

Explanation

This creates a function with no arguments, which splits the string hello world into an array of characters and capitalises the d+1th character. d is a counter that starts as 0 and is increased every time.

Usage

f=_=>a=setInterval("b=[...`hello world`],c.clear(b[d]=b[d].toUpperCase(++d>10&&clearInterval(a))),c.log(b.join``)",1e3,c=console,d=0)
f()

Luke

Posted 2017-02-13T10:04:49.527

Reputation: 4 675

Clever, I'll update it. – Luke – 2017-02-13T15:32:40.297

Also, I don't see any reason to make this a function, since it takes no input -- just run the code, right? – apsillers – 2017-02-13T15:33:30.963

The question says it's supposed to be a program, but in that case you can also submit a function. Code snippets are generally not allowed. – Luke – 2017-02-13T15:38:32.437

This is nice, gg! – ʰᵈˑ – 2017-02-13T15:45:21.750

Can you distinguish between your understanding of a disallowed "code snippet" versus an allowed "program" in this case? If you just remove the leading _=> you do have a complete program (e.g., if you stuck it in a file, Node.js would run successfully it to completion). My understanding of the prohibition against "code snippets" is against writing code that implicitly accepts some input as a variable, like "if we assume i already has the input, we can do..." which is not happening here, since there explicitly is no input. – apsillers – 2017-02-13T15:45:24.107

4

Noodel, 22 bytes

”<8@\|DḶ|\6þıHḶƥɲSḍsɲS

Try it:)


How it works

”<8@\|DḶ|\6þ           # Displays the string "hello¤world".
”<8@\|DḶ|\6            # Decompresses to the array ["h", "e", "l", "l", "o", "¤", "w", "o", "r", "l", "d"] and pushes it on top of the stack.
           þ           # Pushes a copy of the array to the screen which since is an array is done by reference.

            ı          # Makes the array on the top of the stack the new stack.

             HḶƥɲSḍsɲS # Loops eleven times creating the animation.
             H         # Pushes the string "H" on to the top of the stack.
              Ḷ        # Consumes the "H" that gets evaluated as a base 98 number which comes out to eleven.
               ƥ       # Move the stack pointer up one.
                ɲS     # Switch the case of the top of the stack which will show up on the screen because the array is done by reference.
                  ḍs   # Delay for one second.
                    ɲS # Switch the case back.
                       # Implicit end of the loop.

The snippet uses a 25 byte version that loops continuously.

<div id="noodel" cols="10" rows="2" code="”<8@\|DḶ|\6þıḷʠ*HḶƥɲSḍsɲS" input=""/>
<script src="https://tkellehe.github.io/noodel/release/noodel-2.5.js"></script>
<script src="https://tkellehe.github.io/noodel/ppcg.min.js"></script>

tkellehe

Posted 2017-02-13T10:04:49.527

Reputation: 605

4

Bash + coreutils, 99 98 bytes

x=hello\ world
for((;n<11;)){
echo -en "\r${x:0:n}"`tr a-z A-Z<<<"${x:n:1}"`"${x:n+++1}"
sleep 1
}

Mitchell Spector

Posted 2017-02-13T10:04:49.527

Reputation: 3 392

3

Perl 6, 65 61 bytes

for 3..12 ->\i{sleep say "\echello world".&{S:nth(i)/./{$/.uc}/}}

(sleep say S:nth(3+$++)/./{$/.uc}/with "\echello world")xx 11

GIF: enter image description here

How it works

The ANSI escape sequence \ec clears the screen.
Each iteration, the i'th character of the hard-coded string is substituted by its upper-case version.
The say function always returns True, which is passed on to the sleep function which interprets it as 1 second.

smls

Posted 2017-02-13T10:04:49.527

Reputation: 4 352

3

Ruby, 82 81 bytes

12.times{|a|$><<?^H*11;'Hello world'.chars{|y|$><<((0!=a-=1)?y:y.upcase)};sleep 1}

^H is ascii 8 (backspace), and is only 1 byte.

G B

Posted 2017-02-13T10:04:49.527

Reputation: 11 099

3

C, 87 bytes

m(){char*f,a[]="\rhello world";for(f=a;*++f;*f&=95,printf(a),*f|=32,fflush(sleep(1)));}

Compiles and runs on Linux.

Bart Friederichs

Posted 2017-02-13T10:04:49.527

Reputation: 131

3

R, 106 103 bytes

x=el(strsplit("hello world",""))
for(i in 1:11){y=x;y[i]=toupper(y[i]);cat('\f',y,sep='');Sys.sleep(1)}

Just a simple loop, clearing the console with cat('\f') seems somewhat system-dependent but I am not aware of a better way.

Robert Hacken

Posted 2017-02-13T10:04:49.527

Reputation: 371

I tried outgolfing this using utf8ToInt. This did not work, the space needs to be handled as a special case. In the process I discovered that cat("\014") seemed to work better then work where cat("\f") did not.but not on TIO

– JayCe – 2018-07-16T17:33:57.363

3

Mathematica, 130 128 123 110 108 bytes

Dynamic@o
s="hello world";i=1;t=StringTake;Do[o=t[s,{1,i-1}]<>Capitalize@t[s,{i}]<>t[s,{++i,11}];Pause@1,11]

Explanation: From i=1 to 11, print from the 1st to the (i-1)th character of "hello world", capitalise "hello world"[i], then print the rest of the string, incrementing i at the same time.

numbermaniac

Posted 2017-02-13T10:04:49.527

Reputation: 639

3

Java 215 212 204 203 bytes

interface A{static void main(String z[])throws Exception{for(int i=0;i<10;i++){char[]b="helloworld".toCharArray();b[i]=Character.toUpperCase(b[i]);System.out.println(new String(b));Thread.sleep(1000);}}}

Ungolfed:

 interface A {
 static void main(String z[]) throws Exception {
    for (int i = 0; i < 10; i++) {
        char[] b = "helloworld".toCharArray();
        b[i] = Character.toUpperCase(b[i]);
        System.out.println(new String(b));
        Thread.sleep(1000);
    }
  }
}

DevelopingDeveloper

Posted 2017-02-13T10:04:49.527

Reputation: 1 415

1Shouldn't it be interface A (with a space)? Plus you can remove the space between , and Character.toUpperCase. – NoOneIsHere – 2017-12-07T21:51:49.297

2Welcome to the site! – James – 2017-12-07T21:53:48.037

Kudos to @NoOneIsHere for the 3 points – DevelopingDeveloper – 2017-12-07T21:55:42.803

Thanks @DJMcMayhem, Always liked reading through the challenges and finally got to answer one! – DevelopingDeveloper – 2017-12-07T22:00:01.810

2

C, 122 bytes

i;f(){char s[]="Hello world\r";for(i=0;i<11;i++){s[i]=toupper(s[i]);s[i-1]=tolower(s[i-1]);printf(s);fflush(0);sleep(1);}}

Shorter than C# :D

betseg

Posted 2017-02-13T10:04:49.527

Reputation: 8 493

1Also for the last frame to be visible, you have to do i<11 instead of i<10 in your for-loop – user41805 – 2017-02-13T11:23:57.303

2

Perl, 75 bytes

sleep print"\33c".("hello world"=~s/(.{$_})(.)(.*)/$1\U$2\E$3\n/r)for 0..10

Uses the ANSI code ESCc to clear the console and move the cursor to the top left at every iteration, but still needs \n at the end of the replace string to avoid having the whole animation lost in the line buffer.

A successful call to print returns a value of 1, which can be passed directly to sleep.

r3mainer

Posted 2017-02-13T10:04:49.527

Reputation: 19 135

You can use $\`` and$'to save a few bytes on that(.{$_})(.)(.*)(it won't work in a terminal, but that's not a problem). It requires modifying a little bit the rest of your code though:"hello world"=~s/./sleep print"\33c$`\U$&\E$'\n"/ger. (I wrote almost this exact code, then when looking if anyone had posted a perl answer yet, I found yours). And a little detail about the bytecount : you can use a litteral newline to save a byte, and maybe some kind of litteral\33c` (not too sure about that last one though). – Dada – 2017-02-14T22:12:06.297

2

C 120 110 104 96 bytes

f(){char *j,s[]="\rhello world";for(j=s;*++j;*j-=32,printf(s),*j+=32,fflush(0),sleep(‌​1));}

Ungolfed version

void f()
{
  char *j;
  char s[]="hello world";
  j=s; 

   for (;*j;j++)
   {
      *j-=32;  
       printf(s); // print the string and right after change the same char to lower case
       *j+=32;
      fflush(0);
      sleep(1);
   }

}

@Pakk Thanks for saving some bytes, great idea. :)

@Pakk @KarlNapf Thanks guys for your inputs.

can still be shortened!? :)

Abel Tom

Posted 2017-02-13T10:04:49.527

Reputation: 1 150

Use -= and +=. Also, a pointer variable might save the [] but i am not sure. – Karl Napf – 2017-02-13T12:33:05.790

The j should be outside the function – user41805 – 2017-02-13T12:37:53.067

@KarlNapf You're obviously right about the += and -= , completely forgot. Updated. :) – Abel Tom – 2017-02-13T12:48:18.123

@KritixiLithos Thanks for pointing out, Updated! – Abel Tom – 2017-02-13T12:49:03.447

I'm not sure, but I think instead of if(j)s[j-1]+=32 you can do j&&s[j-1]+=32 (haven't tested it though) – user41805 – 2017-02-13T12:49:09.220

1char j;f(){char s[]="hello world";for(j=s;j;j++){j-=32;printf("\r%s",s);j+=32;fflush(0);sleep(1);}} (103 chars) – None – 2017-02-13T12:52:10.963

1Idea behind previous comment: Make it lowercase again after the printf, then you don't have to check if j-1 exists. And use pointers to save some characters. – None – 2017-02-13T12:53:27.393

@KritixiLithos j&&s[j-1]+=32 does not work. compilaton error – Abel Tom – 2017-02-13T12:53:56.697

@Pakk Updated, Thanks for the idea. :) – Abel Tom – 2017-02-13T14:24:42.893

2char *j,s[]="hello world"; to save a few more chars. – None – 2017-02-13T14:40:15.340

And my final idea: define s as "\rhello world";, add a ++j to skip the \r, then you can print with printf(s);, which should save a few bytes. Not tested. – None – 2017-02-13T14:44:01.230

1f(){char*j,s[]="\rhello world";for(j=s;*++j;*j-=32,printf(s),*j+=32,fflush(0),sleep(1));} 89 bytes. – Karl Napf – 2017-02-14T11:47:10.403

@KarlNapf you can shorten it to fflush(sleep(1)) – Bart Friederichs – 2017-02-14T14:44:03.983

@KarlNapf, It fails at the 5'th iteration where ' ' - 32 truncates the string into 'hello\0' – Johan du Toit – 2017-05-05T16:47:32.987

2

Pascal, 187 152 bytes

Not exactly the most efficient or the shortest, but works quite well!

uses crt,sysutils;label R;const X:Word=1;P='hello world';begin
R:clrscr;write(P);gotoxy(X,1);write(upcase(P[X]));sleep(999);X:=X*Ord(X<11)+1;goto R
end.

Tested and works on Free Pascal Compiler 2.6+.

Thanks to @manatwork for saving 35 bytes!


I've used http://www.onlinecompiler.net/pascal to compile the file and run it on Windows.
Haven't seen any problem with it, so far.

Ismael Miguel

Posted 2017-02-13T10:04:49.527

Reputation: 6 797

An UpCase function exists since the old Turbo times. (There it handled only Char, but in Free Pascal also handles strings.) – manatwork – 2017-02-14T08:35:23.500

A couple of minor tweaks: is enough to declare X Word (or Byte); make P a const so it infers type from initialization value; while there, make X an initialized constant to get rid of separate var keyword (this one may not work in all Pascal variants, but certainly does in Free Pascal); use ClrScr to jump to top left corner; replace that if with a single expression: X:=X*Ord(X<11)+1. http://pastebin.com/FfaixkES

– manatwork – 2017-02-14T08:56:48.347

I really didn't knew that const X:Word=1;P='hello world'; and that const X:Word=1;P='hello world'; were possible. I learned Pascal on Turbo Pascal 7, which may not be compatible with that. And completely forgot about upcase. Thank you a lot! – Ismael Miguel – 2017-02-14T11:58:21.107

2

SmileBASIC, 90 71 bytes

FOR I=0TO 10CLS?"hello world
LOCATE I,0?CHR$(CHKCHR(I,0)-32)WAIT 60NEXT

12Me21

Posted 2017-02-13T10:04:49.527

Reputation: 6 110

2

Jelly, 24 21 bytes

”Æ⁹Œu⁸¦ȮœS
“½,⁻⁸3»Jç€

This is a niladic link/function that prints to STDOUT. It does not work as a full program.

The code can't be tested on TIO; it uses control characters and TIO has no terminal emulator (yet).

How it works

“½,⁻⁸3»Jç€  Niladic link. No arguments.

“½,⁻⁸3»     Index into Jelly's dictionary to yield "hello world".
       J    Indices; yield [1, ..., 11].
        ç€  Apply the helper link to each index, with right arg. "hello world".


”Æ⁹Œu⁸¦ȮœS  Dyadic helper link. Left argument: i. Right argument: "hello world"

Ӯ          Set the return value to '\r'.
  ⁹         Set the return value to "hello world". Implicitly prints '\r'.
   Œu⁸¦     Uppercase the i-th letter.
       Ȯ    Print.
        œS  Sleep "hello world" seconds. (Strings are cast to Boolean.)

Dennis

Posted 2017-02-13T10:04:49.527

Reputation: 196 637

(Strings are cast to Boolean.) That's devious! – Erik the Outgolfer – 2017-05-05T13:35:48.390

2

C, 122 bytes

As an exercise, I wrote this to provide a more optimal output format than some of the other answers. Also it means the cursor sits after the most recently capitalized letter during the pauses.

main(){
    char*p=".Hello world\rH";
    write(1,p+1,13);
    do{
        sleep(1);
        *p=8;
        p[1]|=32;
        p[2]^=(p[2]>32)*32;
        write(1,p++,3);
    }while(p[4]);
}

(Newlines and indentations cosmetic and not part of byte count)

Now, some readers may note that this requires some massaging to get to run on modern machines (the magic incantation is -static -Wl,-N), but this is how real implementations of C used to behave, so I think it is valid. It also assumes the character set is ASCII, and it does not print a trailing newline.

Bonus: For an EBCDIC version, you can replace 8 with 22 and 64 with 32, and switch the logic for p[1] and p[2]. To test on a non-EBCDIC system, you can compile with -funsigned-char -fexec-charset=cp037.

Output is 43 bytes: Hello world«H‹hE‹eL‹lL‹lO‹o ‹ W‹wO‹oR‹rL‹lD

Random832

Posted 2017-02-13T10:04:49.527

Reputation: 796

2

Scala, 92 bytes

val h="hello world"
0 to 10 map{i=>print("\b"*99+h.updated(i,h(i)toUpper))
Thread sleep 999}

Ungolfed

val h="hello world"    //declare a variable h with the string "hello world"
0 to 10                //create a range from 0 to 10
map { i=>              //loop with index i
  print(                 //print
    "\b" * 99              //99 backspace chars
    + h.updated(           //and h with
      i,                     //the i-th char
      h(i).toUpper           //replaced with the i-th char in uppercase
    )     
  )
  Thread sleep 999       //sleep 999 ms
}

corvus_192

Posted 2017-02-13T10:04:49.527

Reputation: 1 889

1+1 for h(i)toUpper – Always Asking – 2017-02-14T02:48:39.353

2

Batch, 184 bytes

@echo off
for %%h in (Hello hEllo heLlo helLo hellO hello)do call:c %%h world
for %%w in (World wOrld woRld worLd worlD)do call:c hello %%w
exit/b
:c
timeout/t>nul 1
cls
echo %*

Curiously the command line for timeout/t>nul 1 gets corrupted if there is no trailing newline, so I can't put it at the end of the file.

Neil

Posted 2017-02-13T10:04:49.527

Reputation: 95 035

2

Python 2, 220 189 179 bytes

Solution without using strings and capitalize(), byte count as is:

import time,sys
from numpy import *
F=fromstring("\rhello world",int8)
for i in range(1,12):
    time.sleep(1)
    F[i]-=32
    savetxt(sys.stdout,F,fmt="%c",newline="")
    F[i]+=32

And a bit longer variant (191 chars) without case resetting:

import time,sys
from numpy import *
a=arange(11)
F=tile(fromstring("\rhello world",int8),(11,1))
F[a,a+1]-=32
for i in a:
    time.sleep(1)
    savetxt(sys.stdout,F[i],fmt="%c",newline="")

Mikhail V

Posted 2017-02-13T10:04:49.527

Reputation: 251

Welcome to the site! It looks like you have done extra whitespace. Particularly around your equal signs – Post Rock Garf Hunter – 2017-02-14T01:58:16.333

2

Ruby, 108 bytes

First time, first year student. It's no eagle but I'm at least a little proud.

12.times{|i|sleep(0.1); puts "\e[H\e[2J", "hello world".sub(/(?<=.{#{Regexp.quote(i.to_s)}})./, &:upcase);}

Simon Fish

Posted 2017-02-13T10:04:49.527

Reputation: 21

2

C++, 88 125 Bytes

#include<iostream>#include<unistd.h>
int main(){for(int c;++c<12;){char a[]="\rhello world";a[c]-=32;std::cout<<a;sleep(1);}}

Ungolfed version:

#include <iostream>
#include <unistd.h>

int main()
{
   for (int c;++c<12;)
   {
      char a[] = "\rhello world";
      a[c]-=32;
      std::cout << a;
      sleep(1);
   }
}

Compiled with TDM-GCC on a Windows 10 machine with Dev-C++.

Edit: I forgot the includes in my first version.

Snowfire

Posted 2017-02-13T10:04:49.527

Reputation: 181

Hey, you're the guy that helped me with my C# answer! Your C++ approach made me realise I can actually remove that condition from my for loop by moving the carriage return to the beginning of the string.. I'll help you too: Doing for(int c=1;;c++) will save you 1 byte. – Metoniem – 2017-02-15T12:38:09.657

Also like you suggested in my C# answer, in combination with my last comment you could then do for(int c=1;;) and then a[c++]-=32; to save another byte. – Metoniem – 2017-02-15T12:44:30.120

But even with the carriage return in the beginning, it still prints a character (Ó in my case) to the output after hello world even though I'm not really sure why... – Snowfire – 2017-02-15T12:48:25.967

That's... rather strange. That shouldn't happen?! – Metoniem – 2017-02-15T12:57:53.997

2

Linux C, 180 bytes code, 6336 bytes binary (gcc+strip x86_64)

#include<unistd.h>
char s[]="\rhello world";
int main(){int n;for(n=1;s[n]!=0;n++){if(s[n]>0x40)s[n]^=0x20;if(n>1)if(s[n-1]>0x40)s[n-1]^=0x20;write(1,&s,sizeof(s)-1);sleep(1);};};

HRH Sven Olaf von CyberBunker

Posted 2017-02-13T10:04:49.527

Reputation: 21

1Do you mind putting the byte count and language in the header? Formatting is like this: # <Language>, <N> bytes – Cyoce – 2017-02-15T19:59:58.587

You can golf a few bytes by changing 0x20 into 32 – cookie – 2017-03-13T12:28:18.197

2

AWK, 123 bytes

BEGIN{s="hello world\n"
split(s,a,"")
for(L=1;L<12;L++){for(m=1;m<13;m++)printf m==L?toupper(a[m]):a[m]
system("sleep 1")}}

Fairly standard AWK but it does require the availability of sleep. On my Linux box the default argument to sleep is an integer number of seconds.

Robert Benson

Posted 2017-02-13T10:04:49.527

Reputation: 1 339

2

Java, 137 bytes

String q="HELLO WORLD";for(int x,i=0;i<132;System.out.print((char)(x>10?10:(x!=i/12?32:0)|q.charAt(x))))Thread.sleep((x=i++%12)<1?999:0);

Ungolfed and with comments:

    String q = "HELLO WORLD"; // note that the string is 11 characters long
    for (int x, i = 0;
         i < 132; // 11 rows, 12 columns (one column for newlines)
         System.out.print((char) (x > 10 ? // if this is the last column
                 10 // print newline
                 : // else:
                 (x != i / 12 ? //check if column == row
                         32 : 0) | q.charAt(x)))) // de-capitalize
        Thread.sleep((x = i++ % 12) < 1 ? 999 : 0); // if this is the first column, wait almost 1 second.
    // the above line will also update i and x

Edit: A full program would take 196 bytes

Local Maximum

Posted 2017-02-13T10:04:49.527

Reputation: 21

2

Common Lisp, 108 bytes

(let((a"hello world"))(dotimes(i 11)(format t"~a~c"(string-upcase a :start i :end(1+ i))#\return)(sleep 1)))

Works on a regular terminal, on tio.run does not overwrite the string.

Renzo

Posted 2017-02-13T10:04:49.527

Reputation: 2 260

2

PowerShell 3.0, 72 63 Bytes

-9 bytes thanks to mazzy

0..10|%{cls;($s=[char[]]'hello world')[$_]-=32;-join$s;sleep 1}

Not too shabby.

Veskah

Posted 2017-02-13T10:04:49.527

Reputation: 3 580

It can to save some bytes 0..10|%{cls;($s=[char[]]'hello world')[$_]-=32;-join$s;sleep 1} – mazzy – 2018-07-18T12:47:08.797

1

Haskell 232 212 Bytes

The trickiest part was reliably implementing a delay using prelude. Control.Concurrent threadDelay could be used for a robust solution. I started with delay n= foldr seq "\&" (drop n[5.5*10^6..10^7] which works in the REPL, however does not work compiled into a .exe.

enter image description here

Golfed Version

d=[0..10]>>"\BS"
p=concat$replicate(2*10^5)" \BS"
l=zip['a'..'z']['A'..'Z']
t x=([u|(l,u)<-l,l==x]++" ")!!0
y(x:xs)e|length xs==12-e=t x:xs|1>0=x:(y xs e)
main = do mapM_ putStr$[y"hello world"x++p++d|x<-[2..12]]

Explanation:

--Create a row of backspaces. When sent to IO deletes last character
delrow= [0..10]>>"\BS"

--print beaucoup spaces and backspaces
printblank = concat $ replicate (200000)  (' ':"\BS")


--Helpers to create a caps letter
lowerandupper = zip (['a'..'z']) (['A'..'Z'])
toupper x = head ([u|(l,u)<-lowerandupper, l==x]++" ")
touppers (x:xs) elem | length xs == 12- elem = toupper x :xs
                   | 1>0 = x: (touppers xs elem)

main = do
        --use mapM_ to putStr for each element of list
        mapM_ putStr $ [touppers "hello world" x ++ printblank++delrow|x <-[2..12]]

Looking forward to comments, feedback and improvements.

@laikoni thanks for the inputs saving numerous bytes.

brander

Posted 2017-02-13T10:04:49.527

Reputation: 111

1There appears to be an identifier elem in your golfed code which could be shortened. Also using line breaks instead of ; results in the same byte count but slightly better readable code. – Laikoni – 2017-02-13T21:48:12.067

Instead of delrow, can't you just print a carriage return? – Carcigenicate – 2017-02-13T21:50:51.027

1(' ':"\BS") is just " \BS". You don't need parenthesis around lists. There is unnecessary whitespace in your main and I think you don't need the do. – Laikoni – 2017-02-13T21:54:04.310

@Carcigenicate I was looking at that, but carriage return will start a new line. For example, putStr "Hello world">>= \x -> (putStr "\r")>>= (\y -> putStr "Hello world") would return 2 lines: Hello world Hello world whereas putStr "Hello world">>= \x -> (putStr delrow)>>= (\y -> putStr "Hello world") returns just 1 line – brander – 2017-02-13T22:07:41.643

It shouldn't. And why not just do putStr "\rhello world"? – Carcigenicate – 2017-02-13T22:09:46.317

The identifier xs can be shortened. You can omit the parenthesis in x:(y xs e). Instead of comparing e to the length of the rest list it might be shorter to check if e is zero and decrement it in each recursive call. Your main can start with main=mapM_ ... and finally you can inline d, p, l and e because they are called only at one position each. – Laikoni – 2017-02-14T06:31:03.650

1

Clojure, 116 bytes

(doseq[i(range 11)](Thread/sleep 1000)(print"\r"(apply str(update(vec"hello world")i #(char(-(int %) 32)))))(flush))

Basically a for-loop that goes over the indices of each character, updating each character in turn.

(defn -main []
  (doseq [i (range 11)] ; For the index of each character...
    (Thread/sleep 1000)
    (print "\r" ; Clear old line
           (apply str ; Turn the vector back into a string
             (update ; Update the char at index i
               (vec "hello world") ; Turn the string into a vector so it's updatable
               i ; Index to update
               #(char (- (int %) 32))))) ; Subtract 32 from the character to make uppercase
    (flush)))

Carcigenicate

Posted 2017-02-13T10:04:49.527

Reputation: 3 295

1

Rebol, 70 bytes

repeat n 11[prin[head uppercase/part at copy"hello world^M"n 1]wait 1]

Ungolfed:

repeat n 11 [
    prin [head uppercase/part at copy "hello world^M" n 1]
    wait 1
]

draegtun

Posted 2017-02-13T10:04:49.527

Reputation: 1 592

1

Java - 240 bytes

interface a{static void main(String[]a)throws Throwable{int x=1;char[]b="\rhello world".toCharArray();while(x<12){if(b[x]!=' ')b[x]=(char)((int)b[x]^32);System.out.print(b);Thread.sleep(1000);if(b[x]!=' ')b[x]=(char)((int)b[x]^32);x++;}}}

Ungolfed version:

interface a {
    static void main(String[] a) throws Throwable {
        int x = 1;
        char[] b = "\rhello world".toCharArray();
        while(x < 12) {
            if (b[x] != ' ')
                b[x]=(char)((int)b[x]^32);
            System.out.print(b);
            Thread.sleep(1000);
            if (b[x] != ' ')
                b[x]=(char)((int)b[x]^32);
            x++;
        }
    }
}

GIF of it

cookie

Posted 2017-02-13T10:04:49.527

Reputation: 271

1

Scala, 139 Bytes

() => {
    val a = "\033[H\033[2J\nhello world"
    8 to 19 map{c=>
        print(a.updated(c,a(c)toUpper))
        Thread.sleep(1000)
    }
}

Stefan Aleksić

Posted 2017-02-13T10:04:49.527

Reputation: 119

1

C (MinGW), 83 80 77 bytes

Only tested on Windows.

f(){for(char s[]="\rhello world",*t=s;*++t;*t+=32)*t-=32,printf(s),sleep(1);}

gastropner

Posted 2017-02-13T10:04:49.527

Reputation: 3 264

1

Ruby, 56 bytes

"hello world".gsub(/./){$><<?\r+$`+$&.upcase+$'
sleep 1}

Jordan

Posted 2017-02-13T10:04:49.527

Reputation: 5 001

1

Perl 5, 49 bytes

sleep say"chello world"^""x$_.$"x!/7/ for 2..12

Try it online! - only really works in a terminal, but you can easily copy/paste from here.

Explanation

This script uses the stringwise XOR operation to capitalise the needed letters in each iteration. First we build the string 'hello world' (which includes \x1bc as an ANSI escape sequence to clear the screen), then we XOR (^) against a string of repeating NUL bytes (repeating as needed, 2 on the first iteration and finishing with 12), followed by a space ($") on all but the 7th iteration (which would remove the space in the middle - well, set it to NUL).

Please note this script contains unprintables, here's a reversible hex dump:

00000000: 736c 6565 7020 7361 7922 1b63 6865 6c6c  sleep say".chell
00000010: 6f20 776f 726c 6422 5e22 0022 7824 5f2e  o world"^"."x$_.
00000020: 2422 7821 2f37 2f20 666f 7220 322e 2e31  $"x!/7/ for 2..1
00000030: 32                                       2

Dom Hastings

Posted 2017-02-13T10:04:49.527

Reputation: 16 415

1

x86 opcode(.COM), 48 bytes

  org 100h
  mov ax, 0x0900
  mov bx, -34
  out 0x70,al
  mov dx, stri
  int 0x21
  push 0xa802
  pop ds
r:in  al,0x71
  cmp al,cl
  jz  r
  xchg ax,cx
  xor [bx],dword 0x200020
  add bx, 2
  jnz r
  stri db 'hello world$'  

l4m2

Posted 2017-02-13T10:04:49.527

Reputation: 5 985

1

Small Basic, 166 bytes

Takes no input and outputs to the TextWindow.

For i=1To 11
l=0
t="hello world
p()
l=i-1
t=Text.GetSubText("HELLO WORLD",i,1)
p()
Program.Delay(1000)
EndFor
Sub p
TextWindow.CursorLeft=l
TextWindow.Write(t)
EndSub

Try it at SmallBasic.com! Requires Silverlight/IE

Taylor Scott

Posted 2017-02-13T10:04:49.527

Reputation: 6 709

1

Forth (gforth), 103 bytes

: f s" hello world"11 0 do page over dup i type i + dup c@ toupper emit 1+ over i - type 1000 ms loop ;

Try it online!

Doesn't work properly in TIO, but if you copy and paste into a gforth interpreter/terminal you get a proper animation.

I overwrote page and 1000 in the tio header so the output was readable and didn't take 10+ seconds to render, but the value in the "code" box is correct

Explanation

Loops through all characters in "hello world". For each one:

  • Clear screen and set cursor to top left of terminal/window
  • Output all characters before the current one
  • Output the current character uppercase (or as-is for space)
  • Output all characters after the current one
  • Wait 1 sec (1000 milliseconds)

Code Explanation

: f                 \ start a new word definition
  s" hello world"   \ create a string containing "hello world"
  11 0              \ set up loop parameters
  do                \ loop from 0 to 10 inclusive
    page            \ clear the screen/terminal and set cursor to top left
    over            \ get the string's starting address
    dup i type      \ output the first i characters of the string
    i + dup c@      \ get the value at the address of the current character
    toupper emit    \ convert to uppercase and output
    1+ over i -     \ add 1 to address, subtract current index from string length
    type            \ output end of string
    1000 ms         \ wait 1 seconds
  loop              \ end loop
;                   \ end word definition

reffu

Posted 2017-02-13T10:04:49.527

Reputation: 1 361

0

PowerShell, 76 bytes

$b= # The solution is the next line
{$a=[char[]]$_;1..$a.length|%{$a[--$_]-=32;cls;-join$a;$a[$_]-=-32;sleep 1}}
'hello world'|% $b

Andrei Odegov

Posted 2017-02-13T10:04:49.527

Reputation: 939

0

ES2015, 126 bytes

Based on this answer.

c=console;d=0;t=_=>setTimeout(_=>{a=[...`hello world`];a[d]?c.clear(a[d]=a[d++].toUpperCase())|t(c.log(a.join``)):a},1e3);t()

fardjad

Posted 2017-02-13T10:04:49.527

Reputation: 101

0

Mathematica, 104 bytes

Monitor[Do[s=y=Characters@"hello world";s=s~Delete~i;Pause@1,{i,11}],""<>Insert[s,Capitalize[y][[i]],i]]

J42161217

Posted 2017-02-13T10:04:49.527

Reputation: 15 931

0

C# (Visual C# Compiler), 217 bytes

using u=System.Console;class P{static string a="hello world";static void Main(){for(int i=0;i<11;i++){u.Clear();u.WriteLine(a.Substring(0,i)+char.ToUpper(a[i])+a.Substring(i+1));System.Threading.Thread.Sleep(1000);}}}

Try it online!

facepalm42

Posted 2017-02-13T10:04:49.527

Reputation: 405