This is my first golf contest.

What you need to do

Build me, in the shortest amount of bytes possible, my AC remote control system. My room is too cold right now, and I'm missing my remote.

Now, I don't want you literally building it or anything, just golf this:

A slow increment of temperature, starting at 40 degrees, and ending at exactly 72. The increment time must always be 500 millis per increment. It can wait another 500ms at the end. I would prefer it to stop however. The increment itself must go up by two each time, like my remote.

There is no need to clear the screen on each update.

What should happen

Example output (everything in parentheses shouldn't be outputted).

40
(wait 500 millis)
42
(wait 500 millis)
44
(..repeat until 72..)
72
(stop or wait 500ms)

Keep in mind This is my first golf, so I apologize if this is too hard to golf. :(

Best of luck, golfers!

share|improve this question
3  
Welcome to PPCG! The challenge says to start at 65, but the example starts at 40. Which is correct? (Also, it's impossible to count by twos from 65 to 72.) – ETHproductions 14 hours ago
    
I apologise :| I was pasting this from a notepad document. I probably forgot to save the file when I made fixed that mistake.... – IMustBeSomeone 14 hours ago
    
Minor thing, but "must always be 500 millis" is fundamentally too strict for any reasonable device. I'd recommend specifying a variance, something like +/-10%. – FryAmTheEggman 14 hours ago
2  
Also, you can use the Sandbox next time to "iron out" the bugs in your challenge. – Erik the Outgolfer 8 hours ago
1  
-1 for using Fahrenheit (not really, but you should at least say you're using it; 40 degrees celsius isn't too cold in the slightest) – Jan Dvorak 5 hours ago

19 Answers 19

Bash + linux utilities, 19

seq 40 2 72|pv -qlL2

seq generates the numerical output. pv ratelimits it to 2 lines/sec.

share|improve this answer
1  
The output -q suppresses goes to STDERR, so I don't think you need it. – Dennis 13 hours ago
2  
An excellent demonstration of "do one thing and do it well" with the right tools for the job. :) – Doorknob 13 hours ago

Perl 6, 30 bytes

for 20..36 {sleep .5;say 2*$_}

Sorry that it looks like un-golfed code, I don't see a way to make it shorter...

The version that stops right after the last number, would be 37 bytes:

for 20..36 {sleep .5 if $++;say 2*$_}
share|improve this answer
    
Do you need the space after 36? – SeeOneRhino 24 mins ago

JavaScript (ES6), 52 bytes

f=(i=40)=>console.log(i)|i-72&&setTimeout(f,500,i+2)

f()

share|improve this answer

Vim, 24, 23 bytes/keystrokes

i40<esc>qq:sl500m
Yp2<C-a>q15@q

One byte saved thanks to @Kritixi Lithos!

Written from my phone, tested in mobile vim (which is apparently a real thing). I'll post a gif and an explanation later once I have access to a computer.

share|improve this answer
    
The s in ms is optional, you can remove it to save a byte :) – Kritixi Lithos 8 hours ago
    
@KritixiLithos I knew that! How did I overlook that? Thanks! – DJMcMayhem 2 hours ago
2  
The student has become the teacher :P – Kritixi Lithos 2 hours ago

Mathematica, 34 bytes

Pause[Print@#;.5]&/@Range[40,72,2]

Full program. Takes no input and outputs to STDOUT.

share|improve this answer

Haskell, 67 bytes

import System.Posix.Unistd
mapM((>>usleep 500000).print)[40,42..70]

If you want to go with ghc only, you can save a few bytes by importing GHC.Conc and using threadDelay instead of usleep.

share|improve this answer

Perl 6, 27 bytes

sleep .say/2 for 40,42...72

say returns True, which is coerced to a numeric 1 when divided by 2.

share|improve this answer

MATL, 14 bytes

17:E38+"5&Xx@D

Try it in MATL Online! You may need to reload the page if it doesn't initially work.

Explanation

17:     % Push array [1 2 ... 17]
E       % Multiply by 2, element-wise
38+     % Add 38, element-wise. This gives [40 42 ... 72]
"       % For each k in that array
  5&Xx  %   Pause 0.5 seconds and clear screen
  @D    %   Push k and display
        % End (implicit)
share|improve this answer

Octave, 38 35 bytes

Saved 3 bytes thanks to @LuisMendo by changing endfor to end

for i=21:36;disp(2*i);sleep(.5);end

Try it online!

I am new to Octave, so this solution still might be golfed further. Any tips are welcome!

Ungolfed

for i=21:36
  disp(2*i)
  sleep(.5)
end
share|improve this answer
    
@LuisMendo Thanks! – Kritixi Lithos 1 hour ago

Jelly, 13 12 bytes

40µṄœS.+2µ⁴¡

Try it online! The Jelly prohram is wrapped in a Bash script to prefix each line of output by a timestamp.

How it works

40µṄœS.+2µ⁴¡  Main link. No arguments.

40             Set the return value to 40.
  µ      µ⁴¡  Execute the chain between the two µ 16 times.

After the last iteration, the final value of 72 is printed implicitly and the program exits.

share|improve this answer

Python 3, 57 56 Bytes

import time
a=40
while a<73:print(a);time.sleep(.5);a+=2

EDIT:

-1 Byte thanks to Mega Man

share|improve this answer
    
You could save one byte by using .5 instead of 0.5 – Mega Man 5 hours ago
    
@MegaMan Thanks, I hadn't realised that could work – sonrad10 1 hour ago

Common Lisp, 57

(loop for b from 40 do(print b)while(< b 72)do(sleep .5))

Does not sleep after reaching 72.

(loop
  for b from 40
  do (print b)
  while (< b 72)
  do (sleep .5))
share|improve this answer

php, 38 bytes

for(;35>$t+=2;usleep(5e5))echo$t+38,_;

uses underscore as delimiter. Run with -nr.

share|improve this answer

QBIC, 21 bytes

[44,72,4|?a $sleep 1.

QBIC starts a FOR-loop, running from 44 to 72 and incrementing the counter by 4 on every loop. Ith then sleeps for 1 second. QBasic doesn't have a more finegrained control foor sleep, so I've added a . to simulate giving .5 as an argument.

share|improve this answer

Racket 44 bytes

(for((i(range 40 73)))(println i)(sleep .5))

Ungolfed:

(define (f1)
  (for ((i (range 40 73)))
    (println i)
    (sleep .5)))

Testing:

(f)

Output:

40
41
42
43
44
45
...
71
72
share|improve this answer
    
I don't think this is correct; the output should count by 2's (40, 42, 44, ...) – ETHproductions 49 secs ago

R, 49 bytes

x=38;while(x<72){Sys.sleep(.5);x=x+2;cat(x,"\n")}

Very trivial solution but it does the trick.

share|improve this answer
    
Initial x=40 does not print 40 at start. You have to start with x=38. – rnso 4 hours ago
    
@rnso Good catch, thanks! – Billywob 4 hours ago

Clojure, 54 bytes

(doseq[t(range 32 73 2)](println t)(Thread/sleep 500))

Third lisp ftw. Just iterates over the range, printing and sleeping each iteration. Sleeps at the end.

Ungolfed:

(doseq [t (range 32 73 2)]
    (println t)
    (Thread/sleep 500)))

A version that doesn't sleep at the end, 66 bytes

(doseq[t(range 32 73 2)](println t)(if(< t 72)(Thread/sleep 500)))

Note, these are full programs since the instructions don't specify. Add a byte to each if a function is required.

share|improve this answer

*><>, 20 bytes

"H&"v
?;5S>2+:n:{:}=

Try it here!

This outputs the 40 and adds two every 500ms, outputting the new number. At 72 the program does not wait and exits immediately. Wasn't sure if we needed any sort of deliminator in-between the temperatures so there isn't one included.

Explanation

Setup:

"J("   push 72 and 38 (temp) to the stack
    v  enter main loop at ">"

Main loop:

>               move the IP right
 2+             add two to temp
   :n           copy and output temp
     :{:}       copy temp and 72
         =?;    if temp == 72, exit
            5S  sleep 500ms
share|improve this answer

TI-Basic (CE or CSE only), 8 bytes

:For(A,42,72
:Pause A,.4
:End

Note that many commands are single byte tokens.

share|improve this answer
    
I see 29 bytes? Is it possible for you to show the 8 byte code? – redstarcoder 2 hours ago
    
TI-Basic has its own character set. For(, Pause , End, and the colons at the beginning of lines are all single bytes. – Julian Lachniet 36 mins ago
    
Strange ... alright, it seems like other answers do that too. – redstarcoder 32 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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