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.

You should not clear the screen. You should have newlines.

What should happen

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

(wait 500 millis)
(wait 500 millis)
(..repeat until 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!

  • 3
    \$\begingroup\$ 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%. \$\endgroup\$ – FryAmTheEggman Dec 24 '16 at 2:52
  • 1
    \$\begingroup\$ Can you wait 500ms before showing initial output? \$\endgroup\$ – FlipTack Dec 24 '16 at 11:25
  • 35
    \$\begingroup\$ -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) \$\endgroup\$ – John Dvorak Dec 24 '16 at 11:54
  • 20
    \$\begingroup\$ +1 for using Fahrenheit, it has better resolution than Celsius and is just as arbitrary as anything not Kelvin or Rankine \$\endgroup\$ – Nick T Dec 24 '16 at 18:20
  • 8
    \$\begingroup\$ @NickT then you're out of luck because this remote's resolution is 2°F which is higher than 1°C. And you can get higher resolution in Celcius than Fahrenheit with a remote that can display 0.5 and much more if it can display to 0.1. Anyway I'm a simple man and can't differentiate between 22 and 23°C so high resolution in this case is useless to me \$\endgroup\$ – phuclv Dec 27 '16 at 12:04

53 Answers 53


Bash + linux utilities, 19

seq 40 2 72|pv -qlL2

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

  • 2
    \$\begingroup\$ The output -q suppresses goes to STDERR, so I don't think you need it. \$\endgroup\$ – Dennis Dec 24 '16 at 3:54
  • 14
    \$\begingroup\$ An excellent demonstration of "do one thing and do it well" with the right tools for the job. :) \$\endgroup\$ – Doorknob Dec 24 '16 at 4:08
  • 2
    \$\begingroup\$ Coming close to "anti-golfscript anti-golf" territory. \$\endgroup\$ – Vi. Dec 25 '16 at 16:03

Minecraft 1.9.0+, 204 162 bytes + 58 36 28 24 20 blocks = 262 240 232 186 182 blytes

This solution is golfed down, and it can't be seen whole in one, or even two screenshots. Uses two glitches and abuses another two features of the game


This solution uses the same principles as the one below, just a 4 blocks more compact design.

  • Abuses the fact that Chain command blocks (green blocks) can't be powered by redstone, only by a singal from a impulse command block (orange).

  • Abuses the fact pistons take 0.30 seconds to extend completely, and redstone needs only 0.10s to register a signal.

  • Also abuses a twofold glitch to set the timer (TNT) off: the redstone next to the timer (TNT) gets not only powered, but also thinks the TNT is another redstone and powers it.

  • On top of all these abuses, the signal shortener (thing under the TNT) is one-use, after it gets powered it changes shape, allowing to pass signal through it to the "incrementer" (topmost orange block)

A bit of explanation on the functionality of it's different parts can be seen in older solutions (but best in the one just below). You can also Try it Offline! (simplified solution incrementing by 4, works only in 1.11+) by running this command in a command block.

Old solution, Minecraft 1.9.0+, 186 blytes:


Since TNT normally explode after 3.0s in Minecraft, this one has to be placed by a command (/setblock) with a specified fuse. Also uses a more compact design to remove redundant command block (containing 42 bytes) and redstone against the older versions. I'm sure this can't get any lower...

Older solution, Minecraft 1.9.0+, 232 blytes:

Oops, I found out these older solutions increment by 4...


Uses the 1.9 command block chain feature (green block thing) to save blocks. Also uses a more compact signal shortener then in the older solutions

Even older solution, Minecraft 1.7.0+, 240 blytes:

the soulless monster

Uses a more compact timer (TNT) then the first solution (below).

Oldest solution, Minecraft 1.7.0+, 262 blytes:

the old monster

This is so long because of the way Minecraft handles variables:

  • To define a variable (int): scoreboard objectives add <variable> dummy

  • To set a value to a variable (each entity including players has it's own variable value): scoreboard players set <entity> <variable> <value>

    • * can be used as <entity> to select all entities and save bytes.

    • only defined variables may be used

    • the value of the variable must be set to a number, not a variable

  • To increment var1 by var2: scoreboard players operation <entity> var1 += <entity> var2

    • <entity> must be a single entity, eg. @p, not *

Screenshots are of my own, dual licenced under WTFPL and what licence SE decides to use today (currently cc by-sa 3.0 with attribution required) :-)

  • 2
    \$\begingroup\$ Wow! You used Minecraft, that is genius! +1 :) \$\endgroup\$ – IMustBeSomeone Dec 25 '16 at 17:15
  • 1
    \$\begingroup\$ @IMustBeSomeone Wait, I found a way to golf this :) \$\endgroup\$ – RudolfJelin Dec 25 '16 at 19:51
  • 1
    \$\begingroup\$ ...your circuit blows itself up when done. \$\endgroup\$ – SuperJedi224 Dec 27 '16 at 13:13
  • \$\begingroup\$ @SuperJedi224 Yes. Is it wrong? \$\endgroup\$ – RudolfJelin Dec 27 '16 at 13:18
  • 2
    \$\begingroup\$ @RudolfL.Jelínek I'm pretty sure it's not actually against the rules, but it is kind of weird. Then again, that's part of what code golf is about. \$\endgroup\$ – SuperJedi224 Dec 27 '16 at 13:23

Vim, 24, 23 bytes/keystrokes


One byte saved thanks to @Kritixi Lithos!

Written from my phone, tested in mobile vim (which is apparently a real thing).

Here's a gif of it running:

enter image description here

And here is a command-by-command explanation:

i40<esc>            " Insert '40' into the buffer
        qq          " Start recording into register 'q'
          :sl500m   " Sleep form 500 ms
Y                   " Yank this line
 p                  " and paste it on a newline
  2<C-a>            " Increment this line twice
        q           " Stop recording
         15@q       " Callback register 'q' 15 times
  • \$\begingroup\$ The s in ms is optional, you can remove it to save a byte :) \$\endgroup\$ – Kritixi Lithos Dec 24 '16 at 9:21
  • \$\begingroup\$ @KritixiLithos I knew that! How did I overlook that? Thanks! \$\endgroup\$ – DJMcMayhem Dec 24 '16 at 14:56
  • 8
    \$\begingroup\$ The student has become the teacher :P \$\endgroup\$ – Kritixi Lithos Dec 24 '16 at 14:58
  • 1
    \$\begingroup\$ "I'll post a gif and an explanation later once I have access to a computer" waits half a year (not quite) \$\endgroup\$ – HyperNeutrino Mar 5 '17 at 2:56
  • \$\begingroup\$ @HyperNeutrino Hahahahaha, I completely forgot about this answer. Is that better :P \$\endgroup\$ – DJMcMayhem Mar 6 '17 at 8:07

JavaScript (ES6), 52 bytes



  • \$\begingroup\$ Here's a more neat re-arrangement of your answer for you: f=(i=40)=>setTimeout(i>70||f,500,i+2,console.log(i)). Sadly, still the same 52 bytes. \$\endgroup\$ – Ismael Miguel Dec 25 '16 at 19:01
  • \$\begingroup\$ Shouldn't this be 50 bytes as you don't need to count the f= based on the meta consensus that anonymous function declarations are allowed? \$\endgroup\$ – R. Kap Feb 26 '17 at 21:52
  • 1
    \$\begingroup\$ @R.Kap Good catch, but in this case, the f= is required because the function needs to call itself (as the first parameter to setTimeout). \$\endgroup\$ – ETHproductions Feb 27 '17 at 1:53

Jelly, 13 12 bytes


Try it online! The Jelly program 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.

   Ṅ           Print the return value, followed by a linefeed.
      .        Yield 0.5.
    œS         Sleep for 0.5 seconds. Yield the previous result.
       +2      Add 2.

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

  • \$\begingroup\$ Wow, is that an intended feature, being able to call other languages from Bash in tio? \$\endgroup\$ – miles Dec 24 '16 at 20:34
  • 2
    \$\begingroup\$ Yes, that's intended. You should be able to do the same from all languages that support system calls or similar features. \$\endgroup\$ – Dennis Dec 24 '16 at 20:37
  • \$\begingroup\$ For a language that wins golfing challenges and the part of the challenge being incrementing by a constant value, this looks very long to me :) \$\endgroup\$ – AlexRacer Dec 25 '16 at 13:28

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*$_}
  • \$\begingroup\$ Do you need the space after 36? \$\endgroup\$ – NoOneIsHere Dec 24 '16 at 17:03
  • 2
    \$\begingroup\$ .say&sleep(.5) for 40,42...72 29 bytes \$\endgroup\$ – ugexe Dec 24 '16 at 19:59
  • \$\begingroup\$ @ugexe: Relying on the side-effects of the arguments of non-shortcircuiting operators to happen in order, feels like an implementation-specific hack to me, because AFAIK the language spec doesn't guarantee this. OTOH, maybe for code golf that's okay? \$\endgroup\$ – smls Dec 27 '16 at 17:25
  • \$\begingroup\$ @SeeOneRhino: Yes. A { bracket following another expression without whitespace, is interpreted as the start of a hash ("associative array") subscript. Perl 6 is strict like that, because its grammar was deliberately designed to allow one-pass parsing of source code with (almost) no backtracking. \$\endgroup\$ – smls Dec 27 '16 at 17:34

Pyth - 12 bytes

Very simple, uses a for loop from 0-17.

  • \$\begingroup\$ Smallest so far, you're tied for first place :) \$\endgroup\$ – IMustBeSomeone Dec 25 '16 at 0:58

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

:Pause A,.5

Note that many commands are single byte tokens.

  • \$\begingroup\$ I see 29 bytes? Is it possible for you to show the 8 byte code? \$\endgroup\$ – redstarcoder Dec 24 '16 at 15:26
  • 1
    \$\begingroup\$ TI-Basic has its own character set. For(, Pause , End, and the colons at the beginning of lines are all single bytes. \$\endgroup\$ – Julian Lachniet Dec 24 '16 at 16:51
  • \$\begingroup\$ Strange ... alright, it seems like other answers do that too. \$\endgroup\$ – redstarcoder Dec 24 '16 at 16:55
  • 1
    \$\begingroup\$ Our best so far! However, I dunno if I'll count the character set kinda thing. \$\endgroup\$ – IMustBeSomeone Dec 25 '16 at 0:58
  • 2
    \$\begingroup\$ Relevant: meta.codegolf.stackexchange.com/questions/1541/… \$\endgroup\$ – Jordan Dec 25 '16 at 5:02

MATL, 14 bytes


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


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
  .5Y.  %   Pause 0.5 seconds
  @D    %   Push k and display
        % End (implicit)

Old version (before spec change), clearing the screen


Try it in MATL Online!

  • \$\begingroup\$ You don't need to clear the screen. \$\endgroup\$ – Adám Dec 25 '16 at 10:22
  • \$\begingroup\$ @Adám Thanks. I know, but it took the same number of bytes and it looks nicer :-) \$\endgroup\$ – Luis Mendo Dec 25 '16 at 10:24
  • 1
    \$\begingroup\$ @LuisMendo The golf challenge states something about not clearing the screen, after edits/clarifying (possibly after your post) \$\endgroup\$ – Thomas Ward Dec 27 '16 at 2:03
  • \$\begingroup\$ @ThomasWard Thanks for the heads-up! The OP really should have notified answerers about the change \$\endgroup\$ – Luis Mendo Dec 27 '16 at 2:08

Dyalog APL, 20 bytes


{ the anonymous function

⎕DL delay...

.5⊣ half (a second) rather than the value of

⎕← print (with newline)

 the argument

applied to each of

38+ thirty eight plus


⍳17 the integers from 1 to 17


C compiled with Clang 3.8.1 on Linux, 62 59 58 bytes

2 bytes saved thanks to @ranisalt


59 bytes


62 Bytes


s=38                # Initializes a global (int) variable, this is only possible in C, in other languages from the C family variables must have an explicit type.
main()              # Is the main entry point, again as before, in case a type isn't specified C defaults to int
printf("%d\n",s+=2) # printf outputs to stdout based on the pattern defined in the first parameter 
                    # %d is a placeholder for an int variable
                    # \n appends a newline to stdout
                    # The second parameter increments the s variable and afterwards it goes in the placeholder's spot.
usleep(500000)      # This function is Linux specific, it takes an int as parameter, it represents how much time the app needs to sleep in microseconds
  • 2
    \$\begingroup\$ Thanks for the answer, and welcome to the site. Could you add a bit of explanation for those who aren't as familiar with your language? \$\endgroup\$ – isaacg Dec 26 '16 at 9:30
  • 1
    \$\begingroup\$ Thanks for welcoming me. Yeah sure, I can do that. Also, how do I make my post calculate how many bytes it takes? I wrote that myself, but in others' posts it looks different. \$\endgroup\$ – Wade Tyler Dec 26 '16 at 10:04
  • \$\begingroup\$ Everyone writes it themself, there's no auto-calculating feature. Your header uses ** ... ** in markup, whereas the traditional header on this site uses # .... I've edited your answer so you can see how it's done. \$\endgroup\$ – isaacg Dec 26 '16 at 10:07
  • 1
    \$\begingroup\$ @isaacg Thanks a lot. It does look better now. \$\endgroup\$ – Wade Tyler Dec 26 '16 at 10:15
  • 1
    \$\begingroup\$ Using s<72 saves another byte. \$\endgroup\$ – ranisalt Dec 27 '16 at 19:32

Scratch, 5 blocks

(disk space 56.0kb)


(sorry for the low resolution!)

Self-explanatory, really. The variable value is displayed in a box on the "stage".

  • \$\begingroup\$ Does this not have an increment of 4? (as opposed to 2 as request) \$\endgroup\$ – VisualMelon Feb 27 '17 at 12:53
  • 1
    \$\begingroup\$ @VisualMelon Ah, thanks for the notice - I had misunderstood the question before it was edited; I later re-read it and edited my other answer while forgetting this one. Thanks! \$\endgroup\$ – RudolfJelin Feb 27 '17 at 18:36

Mathematica, 34 bytes


Full program. Takes no input and outputs to STDOUT.


R, 49 bytes


Very trivial solution but it does the trick.

  • \$\begingroup\$ Initial x=40 does not print 40 at start. You have to start with x=38. \$\endgroup\$ – rnso Dec 24 '16 at 13:06
  • \$\begingroup\$ Funny, same idea but with a for-loop is exactly the same length. \$\endgroup\$ – JAD Dec 24 '16 at 19:42

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.

Unicode shenanigans can get it down to 23 characters:

sleep .say/2 for ㊵,㊷…72

But that's 29 UTF-8-encoded bytes.


Python 2, 57 56 55 Bytes

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


-1 Byte thanks to Mega Man

-1 Byte thanks to Flp.Tkc

  • 1
    \$\begingroup\$ You could save one byte by using .5 instead of 0.5 \$\endgroup\$ – Mega Man Dec 24 '16 at 12:13
  • \$\begingroup\$ @MegaMan Thanks, I hadn't realised that could work \$\endgroup\$ – sonrad10 Dec 24 '16 at 16:01
  • \$\begingroup\$ Why not take off the parenthesis around the print statement and use Python 2? \$\endgroup\$ – FlipTack Dec 24 '16 at 19:41

Ruby, 33 bytes

(40).step(72,2){|n|p n;sleep 0.5}

C#, 95 bytes

()=>{for(int i=40;i<73;i+=2){System.Console.WriteLine(i);System.Threading.Thread.Sleep(500);}};

It is a simple for loop, it waits an extra 500ms at the end.


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. It 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.


Kotlin, 47 bytes

I guess it was not said in the problem statement that solutions should actually contain increment by two, so the 40+2*i is legal here.

If written as a regular Kotlin source with main:

fun main(args:Array<String>){(0..16).map{println(40+2*it);Thread.sleep(500)}}

(77 bytes)

UPD: In Kotlin 1.3, args:Array<String> can be removed, so it's 18 bytes less.

And in Kotlin Script, the whole program would be


(47 bytes)

  • \$\begingroup\$ Your first program seems to first wait a long time, then output all the results. \$\endgroup\$ – devRicher Dec 27 '16 at 11:11
  • 1
    \$\begingroup\$ @devRicher, seems like you are running it at try.kotlinlang.org. If so, that's a problem of the environment, seems like stdout is not flushed or something. When I run it locally, it behaves as intended. \$\endgroup\$ – hotkey Dec 27 '16 at 11:15

Ruby 31 bytes

20.upto(36){|n|p n*2
sleep 0.5}

Try it online!


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.


php, 38 bytes


uses underscore as delimiter. Run with -nr.


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.


(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.


Racket 46 bytes

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


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

Command to run: (f)

  • 1
    \$\begingroup\$ Remember, it doesn't have to stop at 72, it can wait another 500ms. :) \$\endgroup\$ – IMustBeSomeone Dec 25 '16 at 1:00

Octave, 38 35 bytes

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

for i=20: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!


for i=20:36

Python 2, 57 58 Bytes


Counted as 57 bytes on my handy but TIO says 58 now that I'm back on my own machine so that's my final offer. Interestingly enough TIO doesn't seem to respect the timeout and just waits and then prints out the whole list in one go. Works on QPython for Android and Python 2 on my Ubuntu box so that's good enough for me.

import time
for x in range(40,74,2):print x;time.sleep(.5)

Try it online!

Would be 58 59 in Python 3 so doesn't beat @sonrad10 anyway.

  • 1
    \$\begingroup\$ This would throw a syntax error, you need a colon (not semicolon) after the range(...) \$\endgroup\$ – FlipTack Dec 24 '16 at 19:40
  • \$\begingroup\$ Thanks @Flp.Tkc. It was typed in directly on my handy hense the typo. \$\endgroup\$ – ElPedro Dec 24 '16 at 19:44

R, 44 42 bytes

Straightforward for-loop, there's likely a golfier way. (Also, crossed-out 44 is still regular 44...)

for(i in 20:36*2)cat(i,"\n",Sys.sleep(.5))

F#, 60 bytes

async{for i in 40..2..72 do printfn"%d"i;do!Async.Sleep 500}

This is an async expression, in order to run it pass it into Async.Start or Async.RunSynchronously.


Noodel, noncompeting 10 bytes

Cannot compete because Noodel was born after the challenge was created:(


Try it:)

How it works

40         # Creates the literal number 40 and places it into the pipe.
  Ḷ16      # Loop the following code 16 times.
     ñ     # Print what is in the front of the pipe with a new line.
      ++   # Increment what is in the pipe by two.
        ḍh # Delay for a half a second (500ms).

There is not a version of Noodel that supports the syntax used in this answer. Here is a version that is correct:


<div id="noodel" code="kȥḶ16ñ⁺2ḍh" input="" cols="10" rows="17"></div>

<script src="https://tkellehe.github.io/noodel/noodel-latest.js"></script>
<script src="https://tkellehe.github.io/noodel/ppcg.min.js"></script>


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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