I'm too cold, turn up the temperature

53

7

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

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!

IMustBeSomeone

Posted 2016-12-24T02:39:00.963

Reputation: 647

3Minor 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 – 2016-12-24T02:52:59.063

Okay, I'll see what I can do, once again, I'm learning, thanks for your help :) – IMustBeSomeone – 2016-12-24T02:53:38.417

1Can you wait 500ms before showing initial output? – FlipTack – 2016-12-24T11:25:44.557

35-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) – John Dvorak – 2016-12-24T11:54:36.063

20+1 for using Fahrenheit, it has better resolution than Celsius and is just as arbitrary as anything not Kelvin or Rankine – Nick T – 2016-12-24T18:20:47.123

May we wait half a second before printing 40? – Adám – 2016-12-25T10:14:13.043

Changing the challenge spec after answers have already been posted is much frowned upon, for obvious reasons. At the very least you should have notified the authors of those answers about the change (newlines compulsory, as opposed to clearing the screen) – Luis Mendo – 2016-12-27T02:12:21.003

8@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 – phuclv – 2016-12-27T12:04:10.880

@NickT Not Reaumur either – Matthew Roh – 2017-03-25T17:47:43.637

@SIGSEGV or degrees Baume – Nick T – 2017-03-26T21:20:17.473

Answers

43

Bash + linux utilities, 19

seq 40 2 72|pv -qlL2

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

Digital Trauma

Posted 2016-12-24T02:39:00.963

Reputation: 64 644

2The output -q suppresses goes to STDERR, so I don't think you need it. – Dennis – 2016-12-24T03:54:58.230

14An excellent demonstration of "do one thing and do it well" with the right tools for the job. :) – Doorknob – 2016-12-24T04:08:29.520

2

Coming close to "anti-golfscript anti-golf" territory.

– Vi. – 2016-12-25T16:03:24.823

43

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

RUN! MINECRAFT WILL KILL YOU!

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:

MINECRAFT ABUSE

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

golfcraft

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) :-)

RudolfJelin

Posted 2016-12-24T02:39:00.963

Reputation: 853

2Wow! You used Minecraft, that is genius! +1 :) – IMustBeSomeone – 2016-12-25T17:15:13.197

1@IMustBeSomeone Wait, I found a way to golf this :) – RudolfJelin – 2016-12-25T19:51:30.060

1...your circuit blows itself up when done. – SuperJedi224 – 2016-12-27T13:13:43.203

@SuperJedi224 Yes. Is it wrong? – RudolfJelin – 2016-12-27T13:18:32.613

2@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. – SuperJedi224 – 2016-12-27T13:23:33.550

@SuperJedi224 Yeah, code golf and Minecraft shouldn't be put together :) . Thanks for noticing, though. – RudolfJelin – 2016-12-27T13:26:54.890

Golf... whole in one... hahahah nice – ranisalt – 2016-12-27T19:36:04.877

Blytes? Is that intended? – ghosts_in_the_code – 2017-02-26T15:54:26.087

@ghosts_in_the_code yep, bytes + blocks :] – RudolfJelin – 2017-02-27T09:10:39.603

18

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

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

James

Posted 2016-12-24T02:39:00.963

Reputation: 54 537

The s in ms is optional, you can remove it to save a byte :) – user41805 – 2016-12-24T09:21:41.543

@KritixiLithos I knew that! How did I overlook that? Thanks! – James – 2016-12-24T14:56:06.160

8The student has become the teacher :P – user41805 – 2016-12-24T14:58:06.083

1"I'll post a gif and an explanation later once I have access to a computer" waits half a year (not quite) – HyperNeutrino – 2017-03-05T02:56:39.863

@HyperNeutrino Hahahahaha, I completely forgot about this answer. Is that better :P – James – 2017-03-06T08:07:43.770

There we go. Thanks. :) There was an answer once, I can't remember where, that said "will post explanation later", and 6 years later it still hasn't been edited... – HyperNeutrino – 2017-03-06T13:12:08.547

10

JavaScript (ES6), 52 bytes

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

f()

ETHproductions

Posted 2016-12-24T02:39:00.963

Reputation: 47 880

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. – Ismael Miguel – 2016-12-25T19:01:14.100

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?

– R. Kap – 2017-02-26T21:52:37.690

1@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). – ETHproductions – 2017-02-27T01:53:52.403

8

Jelly, 13 12 bytes

40µṄœS.+2µ⁴¡

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.

Dennis

Posted 2016-12-24T02:39:00.963

Reputation: 196 637

Wow, is that an intended feature, being able to call other languages from Bash in tio? – miles – 2016-12-24T20:34:52.073

2Yes, that's intended. You should be able to do the same from all languages that support system calls or similar features. – Dennis – 2016-12-24T20:37:07.073

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 :) – AlexRacer – 2016-12-25T13:28:23.820

6

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*$_}

smls

Posted 2016-12-24T02:39:00.963

Reputation: 4 352

Do you need the space after 36? – NoOneIsHere – 2016-12-24T17:03:17.420

2.say&sleep(.5) for 40,42...72 29 bytes – ugexe – 2016-12-24T19:59:31.537

@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? – smls – 2016-12-27T17:25:01.617

@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. – smls – 2016-12-27T17:34:16.567

6

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

:For(A,40,72
:Pause A,.5
:End

Note that many commands are single byte tokens.

Julian Lachniet

Posted 2016-12-24T02:39:00.963

Reputation: 3 216

I see 29 bytes? Is it possible for you to show the 8 byte code? – redstarcoder – 2016-12-24T15:26:15.030

1TI-Basic has its own character set. For(, Pause, End, and the colons at the beginning of lines are all single bytes. – Julian Lachniet – 2016-12-24T16:51:05.853

Strange ... alright, it seems like other answers do that too. – redstarcoder – 2016-12-24T16:55:31.943

1Our best so far! However, I dunno if I'll count the character set kinda thing. – IMustBeSomeone – 2016-12-25T00:58:05.227

2

Relevant: http://meta.codegolf.stackexchange.com/questions/1541/how-to-score-ti-basic

– Jordan – 2016-12-25T05:02:22.750

6

Pyth - 12 bytes

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

V17+40yN.d.5

Maltysen

Posted 2016-12-24T02:39:00.963

Reputation: 25 023

Smallest so far, you're tied for first place :) – IMustBeSomeone – 2016-12-25T00:58:50.093

5

MATL, 14 bytes

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

Old version (before spec change), clearing the screen

17:E38+"5&Xx@D

Try it in MATL Online!

Luis Mendo

Posted 2016-12-24T02:39:00.963

Reputation: 87 464

You don't need to clear the screen. – Adám – 2016-12-25T10:22:18.777

@Adám Thanks. I know, but it took the same number of bytes and it looks nicer :-) – Luis Mendo – 2016-12-25T10:24:57.967

1@LuisMendo The golf challenge states something about not clearing the screen, after edits/clarifying (possibly after your post) – Thomas Ward – 2016-12-27T02:03:24.347

@ThomasWard Thanks for the heads-up! The OP really should have notified answerers about the change – Luis Mendo – 2016-12-27T02:08:34.173

4

Dyalog APL, 20 bytes

{⎕DL.5⊣⎕←⍵}¨38+2×⍳17

{ 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

twice

⍳17 the integers from 1 to 17

Adám

Posted 2016-12-24T02:39:00.963

Reputation: 37 779

4

Scratch, 5 blocks

(disk space 56.0kb)

img

(sorry for the low resolution!)

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

RudolfJelin

Posted 2016-12-24T02:39:00.963

Reputation: 853

Does this not have an increment of 4? (as opposed to 2 as request) – VisualMelon – 2017-02-27T12:53:57.447

1@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! – RudolfJelin – 2017-02-27T18:36:23.157

4

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

2 bytes saved thanks to @ranisalt

s=38;main(){for(;s<74;printf("%d\n",s+=2))usleep(500000);}

59 bytes

s=38;main(){for(;s<73;printf("%d\n",s+=2+usleep(500000)));}

62 Bytes

s=38;main(){for(;s!=72;){printf("%d\n",s+=2);usleep(500000);}}

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

Wade Tyler

Posted 2016-12-24T02:39:00.963

Reputation: 261

2Thanks 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? – isaacg – 2016-12-26T09:30:33.250

1Thanks 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. – Wade Tyler – 2016-12-26T10:04:54.160

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. – isaacg – 2016-12-26T10:07:50.703

1@isaacg Thanks a lot. It does look better now. – Wade Tyler – 2016-12-26T10:15:47.847

1Using s<72 saves another byte. – ranisalt – 2016-12-27T19:32:58.790

@ranisalt Oh yeah, how could I've missed it. Thanks – Wade Tyler – 2016-12-27T21:47:12.237

@ranisalt Though I need s<73 because it also needs to print 72 – Wade Tyler – 2016-12-27T21:49:17.267

@WadeTyler not really, in the last iteration s is 70 and prints 72 because of +=2. If you use 73, it prints up to 74 since in the last iteration s is 72 – ranisalt – 2016-12-27T21:53:56.453

You can spare extra 2 bytes using , (comma operator) between printf and usleep and omitting the braces on for. Or one more if you move usleep inside for as iteration step. – ranisalt – 2016-12-27T21:57:09.917

@ranisalt For some reason it prints up till 70 if I use s<72. – Wade Tyler – 2016-12-27T22:00:23.340

Let us continue this discussion in chat.

– Wade Tyler – 2016-12-27T22:34:49.083

3

Mathematica, 34 bytes

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

Full program. Takes no input and outputs to STDOUT.

LegionMammal978

Posted 2016-12-24T02:39:00.963

Reputation: 15 731

3

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.

Sean

Posted 2016-12-24T02:39:00.963

Reputation: 4 136

3

Python 2, 57 56 55 Bytes

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

EDIT:

-1 Byte thanks to Mega Man

-1 Byte thanks to Flp.Tkc

sonrad10

Posted 2016-12-24T02:39:00.963

Reputation: 535

1You could save one byte by using .5 instead of 0.5 – Mega Man – 2016-12-24T12:13:09.783

@MegaMan Thanks, I hadn't realised that could work – sonrad10 – 2016-12-24T16:01:06.493

Why not take off the parenthesis around the print statement and use Python 2? – FlipTack – 2016-12-24T19:41:42.237

3

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.

Billywob

Posted 2016-12-24T02:39:00.963

Reputation: 3 363

Initial x=40 does not print 40 at start. You have to start with x=38. – rnso – 2016-12-24T13:06:54.547

Funny, same idea but with a for-loop is exactly the same length. – JAD – 2016-12-24T19:42:41.363

3

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.

steenbergh

Posted 2016-12-24T02:39:00.963

Reputation: 7 772

3

Ruby 31 bytes

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

Try it online!

Jordan

Posted 2016-12-24T02:39:00.963

Reputation: 5 001

3

Ruby, 33 bytes

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

Jatin Dhankhar

Posted 2016-12-24T02:39:00.963

Reputation: 141

3

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.

Horváth Dávid

Posted 2016-12-24T02:39:00.963

Reputation: 679

3

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

(0..16).map{println(40+2*it);Thread.sleep(500)}

(47 bytes)

hotkey

Posted 2016-12-24T02:39:00.963

Reputation: 131

Your first program seems to first wait a long time, then output all the results. – devRicher – 2016-12-27T11:11:19.003

1@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. – hotkey – 2016-12-27T11:15:39.860

2

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.

nimi

Posted 2016-12-24T02:39:00.963

Reputation: 34 639

2

Common Lisp, 57 52

(loop for b from 40 while(<(print b)72)do(sleep .5))
  • Print returns its input parameter.
  • The program exits immediately after reaching 72.

Ungolfed:

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

coredump

Posted 2016-12-24T02:39:00.963

Reputation: 6 292

2

php, 38 bytes

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

uses underscore as delimiter. Run with -nr.

Titus

Posted 2016-12-24T02:39:00.963

Reputation: 13 814

2

Racket 46 bytes

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

Ungolfed:

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

Command to run: (f)

rnso

Posted 2016-12-24T02:39:00.963

Reputation: 1 635

1Remember, it doesn't have to stop at 72, it can wait another 500ms. :) – IMustBeSomeone – 2016-12-25T01:00:00.123

2

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.

Carcigenicate

Posted 2016-12-24T02:39:00.963

Reputation: 3 295

2

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!

Ungolfed

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

user41805

Posted 2016-12-24T02:39:00.963

Reputation: 16 320

2

Python 2, 57 58 Bytes

Edit

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.

ElPedro

Posted 2016-12-24T02:39:00.963

Reputation: 5 301

1This would throw a syntax error, you need a colon (not semicolon) after the range(...) – FlipTack – 2016-12-24T19:40:53.927

Thanks @Flp.Tkc. It was typed in directly on my handy hense the typo. – ElPedro – 2016-12-24T19:44:15.853

2

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

rturnbull

Posted 2016-12-24T02:39:00.963

Reputation: 3 689

2

Browser Javascript, 52 51 chars

eval(s="s=alert(x=setTimeout(s,500)*2+38)|x<69&&s")

Test with console.log instead of alert:

eval(s="s=console.log(x=setTimeout(s,500)*2+38)|x<69&&s")

Qwertiy

Posted 2016-12-24T02:39:00.963

Reputation: 2 697

Always room to improve I see :—) Nice! – RudolfJelin – 2019-03-20T16:59:20.013

2

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.

pmbanka

Posted 2016-12-24T02:39:00.963

Reputation: 171

2

Noodel, noncompeting 10 bytes

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

40Ḷ16ñ++ḍh

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:

kȥḶ16ñ⁺2ḍh

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

tkellehe

Posted 2016-12-24T02:39:00.963

Reputation: 605

2

Windows Batch - 65 62 61 bytes

btw this is my first PPCG answer

@for /l %%p in (40,2,72)do @echo %%p&@ping 1.1 -n 1 -w 10>nul

This exits when the degree reaches 72.


76 75 bytes - Does not sleep at end

@for /l %%p in (40,2,72)do @echo %%p&if %%p lss 72 @ping 1.1 -n 1 -w 10>nul

Ungolfed and explanation:

@echo off                           - Turns of the prompt(C:\Foo\Bar\Baz>)
for /l %%p in (40,2,72) do (        - For loop that loops from 40 to 72, increase 2 each
    echo %%p                        - Outputs the loop counter(which is the temp.)

if %%p lss 72 (                     - If loop counter is less than 72,
        ping -n 1 -w 10 1.1 >nul    - ping an non-existing IP to make delay

                                    - note: ping will always make 500ms delay
                                    - if waiting time is less than 500ms
    )                               - Closing bracket(if statement)

)                                   - Closing bracket(for statement)

stevefestl

Posted 2016-12-24T02:39:00.963

Reputation: 539

2

Excel VBA (32-Bit Only), 123 Bytes

Declares the windows Kernel32 Sleep(ByVal dwMilliseconds as Long) function and uses a recursive helper function. Outputs to the VBE immediate window.

Declare Sub Sleep Lib"kernel32"(ByVal t&)
Sub a(i)
Debug.?i
If i<72Then Sleep 500:DoEvents:a i+2
End Sub
Sub b:a 40:End Sub    

Usage and Ouput

as seen from an b subroutine call from the VBE immediate window

b        ''  <- Subroutine Call
 40      ''  <- Output
 42 
 44     
 46     
 48     
 50     
 52     
 54     
 56     
 58     
 60     
 62     
 64     
 66     
 68     
 70     
 72   

Taylor Scott

Posted 2016-12-24T02:39:00.963

Reputation: 6 709

2

PowerShell, 32 31 bytes

40..72|%{$_[$_%2];sleep -m 250}

Try it online!

Sleeps regardless if it's odd or even for half the time but will only output when the value is even due to out-of-bounds indexing returning nothing. Lost several bytes due to sleep defaulting to seconds and only taking ints.

Veskah

Posted 2016-12-24T02:39:00.963

Reputation: 3 580

1

*><>, 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

redstarcoder

Posted 2016-12-24T02:39:00.963

Reputation: 1 771

1

Factor, 36 bytes

20 36 [a,b] [ 2 * . 5e8 sleep ] each

Pretty simple.

cat

Posted 2016-12-24T02:39:00.963

Reputation: 4 989

1

Python 3, 61 bytes

Not a winner, but a horrible, horrible abuse of a list comprehension: two side-effects and the result isn't even used.

import time
[print(2*x+40)==time.sleep(.5)for x in range(17)]

Similar:

[time.sleep(.5)for x in map(print,range(40,74,2))]

Nick T

Posted 2016-12-24T02:39:00.963

Reputation: 3 197

I like this. It's clever. Reminds me of a time when I had to print and return something inside of a lambda so I did lambda: (print(...), ...)[1] – Quelklef – 2016-12-27T05:15:50.833

1

Python 2, 54 bytes

Thanks @xnor for cutting 2 bytes off!

import time;x=40
exec'print x;x+=2;time.sleep(.5);'*17

55 bytes

This one uses a dfferent counting approach, can probably still be golfed:

import time;x=34
while x:print 74-x;x-=2;time.sleep(.5)

FlipTack

Posted 2016-12-24T02:39:00.963

Reputation: 13 242

1Can't your exec loop do x+=2? – xnor – 2016-12-25T09:00:12.870

@xnor yep, brain derp... thanks – FlipTack – 2016-12-25T09:08:17.050

1

GNU sed, 87 + 1 = 88 bytes

+1 byte for -u flag (prevents sed from waiting until the end to flush all of the output).

Assumes it's running in an environment where the shell command sleep .5 works.

s/.*/40/
:
p
esleep .5
/72/Q
/8/bz
h
y/0246/2468/
s/.//
H
x
s/.\n//
b
:z
y/4568/5670/
b

Try it online! (Using Dennis' handy bash wrapper to timestamp each output line.)

Jordan

Posted 2016-12-24T02:39:00.963

Reputation: 5 001

1

RBX.Lua, 36 bytes

Uses UTF-8 encoding. Golfed:

for i=40,72,2 do wait(.5)print(i)end

Should be pretty obvious to people with Lua knowledge. Here's an explanation:

for i=40,72,2 do --For-loop, counting from 40 to 72 in steps of 2.
wait(.5) --RBX.Lua builtin. Waits 0.5 seconds.
print(i) --Prints current temperature.
end --End of for loop.

devRicher

Posted 2016-12-24T02:39:00.963

Reputation: 1 609

1

Java, 93 bytes

a->{for(a=38;(a+=2)<73;){System.out.println(a);try{Thread.sleep(500);}catch(Exception e){}}};

This is a java.util.function.Consumer<Integer> that makes me want to take a new NullPointerException() and use it to slap whoever who made Thread.sleep() throw a checked exception.

Identical-in-length snippet that does the exact same thing with an "everyday" method:

void a(int A)throws Exception{for(A=38;(A+=2)<73;){System.out.println(a);Thread.sleep(500);}}

user8397947

Posted 2016-12-24T02:39:00.963

Reputation: 1 242

How long would this be as a full program? – RudolfJelin – 2016-12-26T11:03:16.323

1

postgresql9.6, 162 bytes

do language plpgsql $$ declare n smallint;begin foreach n in array array(select generate_series(40,72,2))loop raise info'%',n;perform pg_sleep(.5);end loop;end;$$

formatted sql is here:

do language plpgsql $$
declare n smallint;
begin
foreach n in array array(select generate_series(40, 72, 2)) loop
    raise info '%', n;
    perform pg_sleep(.5);
end loop;
end;
$$

andryk

Posted 2016-12-24T02:39:00.963

Reputation: 81

1

ForceLang, 71 bytes

For some unknown reason, does not quite work if you run the interpreter using Eclipse, but still functions properly if you run the interpreter using your terminal directly. ¯\_(ツ)_/¯

set s 38
label 1
io.writeln set s s+2
datetime.wait 500
if -72+s
goto 1

SuperJedi224

Posted 2016-12-24T02:39:00.963

Reputation: 11 342

1

SAS, 60 bytes

Something different :)

data _null_;do i=40 to 72; put i;s=sleep(.5,1);end;run;

J_Lard

Posted 2016-12-24T02:39:00.963

Reputation: 351

1

Swift, 208 bytes

import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
func n(){if t<72{DispatchQueue.main.asyncAfter(deadline:.now()+0.5){t+=2;print(t);n()}}}
var t=40;print(t);n()

sleep() takes a UInt32 in Swift, so won't work for the 500 millisecond delay. If it was 1 second however:

import Foundation;(20...36).map{$0*2}.forEach{print($0);sleep(1)}

65 bytes (with a delay at the end)

Ashley Mills

Posted 2016-12-24T02:39:00.963

Reputation: 131

1

Python 2, 57 bytes

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

This does require an 'extra' newline to actually run, so arguably response is 58 bytes (please feel free to edit/comment if this is what the figure above should be).

Edit: Remove unecessary whitespace between : and print

Edit2: changed 0.5 to .5, saving one byte.

Edit3: failed to add/count the sleep import, which raises the score to 60 bytes.

Edit4: Saved 3 bytes by adding extra line

iwaseatenbyagrue

Posted 2016-12-24T02:39:00.963

Reputation: 231

1

101, 98 78 bytes

00001 101000 001 11 00001 01001000 00001 0001 000010 1111 00001 1001 000101 111

EDIT: The language has beed updated to support equals etc. So i managed to narrow it down a little. Note: i did not update the explaination.

developed a programming language in python over the course of the 2 last days. Its fairly simple, but is a pain to program in, as it consists only of 1's and 0's, and can only hold binary numbers with up to 6 numbers.

Explenation:

00001 101000 # declares variable 00001 to 40
00010 100010 # declares variable 00010 to 34

001 00010 # start of loop, checks if variable 00010 is over 0
00010 0011 000010 # 0011 is the function for decrementing, and i decrement by 2 (decimal)
1111 00001 # 1111 is the function for printing
00001 0001 000010 # same as above, only addition
1001 000101 # 1001 is timer, takes a whole number and divide by 10 to allow milliseconds
111 # same as end symbol in ruby

EDIT: Link to the language https://github.com/hrrs01/101 Easily tested by running the demo file by doing (if python in PATH):

101.py demo.txt

Håvard Nygård

Posted 2016-12-24T02:39:00.963

Reputation: 341

1

Common Lisp, 54 bytes (45 if trailing newline is allowed)

(dotimes(i 17)(format t"~a~&"(+(* 2 i)40))(sleep 0.5))

shorter - with trailing newline, because print adds one:

(dotimes(i 17)(print(+(* 2 i)40))(sleep 0.5))

user65167

Posted 2016-12-24T02:39:00.963

Reputation:

1

RbxLua, 36 bytes

for i=40,72,2 do print(i)Wait(.5)end

Thought I'd use RbxLua, which is a modified version of Lua 5.1 used on ROBLOX.com, as it has a built-in Wait(s) function that is one byte shorter than sleep(ms) in Lua 5.3.

Edit: Didn't see the other RbxLua solution. This solution uses a non-deprecated form of wait.

Josh

Posted 2016-12-24T02:39:00.963

Reputation: 1 021

1

dc, 50 bytes

0sm[40lm+p0se[le1+dse120000>j]dsjxlm2+dsm33>p]dspx

Well, this seems to be the first answer which does not utilize any sleep built-in as dc seemingly does not have one. Instead, this simply utilizes a macro loop which during each of 16 iterations increments 40 by 2*iteration #, outputs the sum on a new-line, and utilizes another macro loop which is iterated through 120000 times giving us our desired 500 millisecond sleep with a very slight and unnoticeable variance.

R. Kap

Posted 2016-12-24T02:39:00.963

Reputation: 4 730

1

05AB1E, 11 bytes

40žvƒ=Ì₄;.W

Try it online.

Explanation:

40           # Push 40
  žvƒ        # Loop 17 times (in the range [0,16]):
     =       #  Print the top of the stack with newline (without popping)
      Ì      #  Increase the number by 2
       ₄;    #  Push 1000 halved to 500
         .W  #  And sleep that many ms

Kevin Cruijssen

Posted 2016-12-24T02:39:00.963

Reputation: 67 575

0

Javascript (ES6), 48 bytes

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

Based on @ETHproductions answer.

arodebaugh

Posted 2016-12-24T02:39:00.963

Reputation: 577

Problem: I can stop the execution by not pressing the ok button. Tested on my Win10 64-bit, Chrome 56.0.2924.87 – stevefestl – 2017-03-26T08:22:17.210

2@SteveFest that is normal with javascript... nothing to downvote about – arodebaugh – 2017-05-25T21:14:25.777

Ok I see, btw I didn't down vote you – stevefestl – 2017-05-25T22:31:22.420

Hmm well sorry.. – arodebaugh – 2017-05-26T00:05:43.003

Never mind :) – stevefestl – 2017-05-26T09:58:15.563

so you did? Really confused now – arodebaugh – 2017-05-26T10:29:07.933

LOL I didn't downvote your – stevefestl – 2017-05-26T11:03:10.690

Let us continue this discussion in chat.

– stevefestl – 2017-05-26T11:03:21.267