6
\$\begingroup\$

In this challenge you have to make an ascii pulsing heart with rhythm problems (Heart arrhythmia) and then measure the pulse.Don't worry it's easy!

Making the heart

The heart alternates between these 2 states:
state 1

    ,d88b.d88b,
    88888888888
    `Y8888888Y'
      `Y888Y'
        `Y'

state 2

     d8b d8b
    888888888
    `Y88888P'     
     `Y888P'      
      `Y8P'
       `Y'

each step has X seconds delay
where X is a Random (Real) number between 0.3 and 1.4 (0.3<=X<=1.4)

Measuring the Pulse

When your arrhythmia-heart starts beating, you have to measure the pulse.
We want to know the heartbeats/min.
But (like many doctors do) you only have to count the heartbeats for 15 sec and then multiply by 4

Final output

Given no input, your code must run for 15 seconds (displaying the beating heart) and then print the heart rate.

Your output should look exactly like this!
(I will run my code 2 times for you to see the different results)

First example run:

enter image description here

Second example run:

enter image description here

you must output one heart
Good Luck!

this is code-golf
shortest answer in bytes wins!

\$\endgroup\$
  • 1
    \$\begingroup\$ Could you replace the two hearts with just 1? It makes the post more confusing \$\endgroup\$ – caird coinheringaahing Jul 16 '17 at 23:35
  • \$\begingroup\$ Should the output rate be computed from the pause times or from the actual running time (which will be slightly greater than the sum of pause times)? \$\endgroup\$ – Luis Mendo Jul 16 '17 at 23:50
  • \$\begingroup\$ @cairdcoinheringaahing I've separated the figures to make it clear they are two independent runs \$\endgroup\$ – Luis Mendo Jul 16 '17 at 23:52
  • 2
    \$\begingroup\$ @LuisMendo Sorry I was afk.15 sec is the actual running time.Thanks for editing. I wanted to make sure that there is not a unique result. \$\endgroup\$ – user72269 Jul 17 '17 at 0:47
0
\$\begingroup\$

Mathematica, 212 bytes

g=",d88b.d88b,
88888888888
`Y8888888Y'
  `Y888Y'
    `Y'";h=" d8b d8b
888888888
`Y88888P'
 `Y888P'
  `Y8P'
   `Y'";t=1;TimeConstrained[Monitor[While[1<2,If[OddQ@t,b=g,b=h];Pause@RandomReal@{.3,1.4};t++],b],15];4t
|improve this answer|||||
\$\endgroup\$
3
\$\begingroup\$

Python [on Windows], 262 bytes

from time import*
import os,random
t,i=time(),0
while time()-t<15:print([""",d88b.d88b,
88888888888
`Y8888888Y'
  `Y888Y'
    `Y'""",""" d8b d8b
888888888
`Y88888P'
 `Y888P'
  `Y8P'
   `Y'"""][i%2]);i+=1;sleep(random.randint(3,14)/10);os.system('cls')
print(i*4)

For linux and macOS use os.system('clear') for 2 more bytes.

|improve this answer|||||
\$\endgroup\$
  • 1
    \$\begingroup\$ You can xor i to save 2 bytes [i%2];i+=1 becomes [i];i^=1 \$\endgroup\$ – caird coinheringaahing Jul 17 '17 at 0:28
  • \$\begingroup\$ you have extra spaces after your second heart, i got it down to 262 bytes by removing them \$\endgroup\$ – Felipe Nardi Batista Jul 17 '17 at 11:04
  • \$\begingroup\$ @cairdcoinheringaahing I need i for print(i*4) \$\endgroup\$ – Uriel Jul 17 '17 at 11:09
  • \$\begingroup\$ @micsthepick its missing some spaces, it results in one byte more actually \$\endgroup\$ – Uriel Jul 17 '17 at 11:10
  • \$\begingroup\$ @FelipeNardiBatista thanks! fixed \$\endgroup\$ – Uriel Jul 17 '17 at 11:10
0
\$\begingroup\$

Java, 374 bytes

class G{public static void main(String[]a)throws Exception{long t=System.currentTimeMillis(),i=0;while(System.currentTimeMillis()<15000+t){p(",d88b.d88b,\n88888888888\n`Y8888888Y'\n  `Y888Y'\n    `Y'\n");Thread.sleep((long)(300+(Math.random()*1100)));i++;p(" d8b d8b\n888888888\n`Y88888P'\n `Y888P'\n  `Y8P'\n   `Y'\n");}p(i*4);}static<T>void p(T s){System.out.println(s);}}

Ungolfed:

public class Golf {
    public static void main(String[]a)throws Exception {
        long t=System.currentTimeMillis(),i=0;
        while(System.currentTimeMillis()<15000+t) {
            p(",d88b.d88b,\n88888888888\n`Y8888888Y'\n  `Y888Y'\n    `Y'\n");
            Thread.sleep((long)(300+(Math.random()*1100)));
            i++;
            p(" d8b d8b\n888888888\n`Y88888P'\n `Y888P'\n  `Y8P'\n   `Y'\n");
        }
        p(i*4);
    }
    static<T>void p(T s){System.out.println(s);}
}
|improve this answer|||||
\$\endgroup\$

Your Answer

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