title: Bringing Down the Building

text:
# Question
Title: Bringing Down the Building
We are going to bring down an imaginary building with a series of explosions. Our building is a 5x5 matrix of integers ranging 1-9, each representing a single brick.

The challenge is to set of a series of explosions to bring down our building as much as we can, why not! Each brick that is connected (horizontally, vertically, diagonally) to a copy of itself will represent a payload that is going to explode in the next detonation. The bricks above those that are blown to bits will fall down. We will continue these steps untill we cannot demolish the building any further:

Look at the 'building' to find connected copies of integers for an explosion, set of the explosion to let bricks above the explosion fall down to create a new *array of digits*. If an explosion occured make sure to backfill your 'building' with a zero to represent rising smoke from the ashes. Though, extra imaginary digital kudos if you used actual clouds, e.g:

\>  \>  \>

Your final output, the result of this challenge, should represent the ruins after the last possible detonation with the aforementioned smoke rising from the ashes.

In the case of no possible explosions, sadly output == input. In the occurence of a single big explosion (or multiple explosions for that matter) to bring the whole building down, the result is simply an array of clouds.

**Samples:**

\>

\>

\>

\>

\>

# Answer
> 7 votes
# MATL, 31 bytes

```
12:"9:"t@=t3Y6Z+*~*]tg&S5:q5*+)

```

Input and output are 2D numerical arrays, with `0` for smoke in the output.

Try it online! Or verify all test cases.

### How it works

You can see a convolution coming, can't you?

```
12:"     % For each n in [1 2 ... 12]. 12 is a bound on the number of explosions
  9:"    %   For each k in [1 2 ... 9]
    t    %     Duplicate the numerical 2D array (A). Triggers implicit input the
          %    first time
    @=   %     Compare element-wise with k. Gives a zero-one 2D array (B)
    t    %     Duplicate
    3Y6  %     Push [1 1 1; 1 0 1; 1 1 1]. This defines the neighbourhood
    Z+   %     2D convolution, maintaining size. This counts, for each entry in
         %     (B), how many ones there are in its neighbourhood
    *    %     Multiply, element-wise. This counts, only for each entry in (B)
         %     equal to one, how many ones it has around
    ~    %     Negate. This gives zero for entries that are going to disappear,
         %     one otherwise
    *    %     Multiply by (A), element-wise. This sets the required entries to
         %     zero
  ]      %   End
  tg     %   Duplicate. Convert to logical: non-zero values become one
  &S     %   Sort each column, and output the indices that correspond to the
         %   sorting. Gives a 2D array containing a permutation of [1 2 ... 5]
         %   in each column (C). This sorting corresponds to sending the zeros
         %   to the top of each column
  5:     %   Push [1 2 ... 5]
  q5*    %   Subtract 1, multiply element-wise by 5. Gives [0 5 10 15 20]
  +      %   Add to (C) with implicit expansion. This gives the linear indices
         %   that will send zeros to the top of each column
  )      %   Reference indexing
         % End (implicit)
         % Display (implicit)

```

# Answer
> 5 votes
# 05AB1E, ~~52~~ 48 bytes

```
Δ9EDNQ©˜ƶ5äΔ2Fø0δ.ø}2Fø€ü3}®*€€à}Ð˜s¢2@*_*}ø0δ†ø

```

Uses `0` for smoke.

Try it online or verify all test cases.

**Explanation:**

```
Δ               # Loop until the result no longer changes:
 9E             #  Loop `N` in the range [1,9]:
   D            #   Duplicate the current matrix
                #   (which will be the implicit input-matrix in the first iteration)
    NQ          #   Check which values are equal to `N` in the copy
      ©         #   Store this matrix of 1s/0s in variable `®` (without popping)
       ˜        #   Flatten it to a list
        ƶ       #   Multiply each value by its 1-based index
         5ä     #   Convert the list back to a 5x5 matrix
   Δ            #   Loop until it no longer changes to flood-fill the positive values:
    2Fø0δ.ø}    #    Add a border of 0s around the matrix:
    2F     }    #     Loop 2 times:
      ø         #      Zip/transpose; swapping rows/columns
        δ       #      Map over each row:
       0 .ø     #       Add a leading/trailing 0
    2Fø€ü3}     #    Convert it into overlapping 3x3 blocks:
    2F    }     #     Loop 2 times again:
      ø         #      Zip/transpose; swapping rows/columns
       €        #      Map over each inner list:
        ü3      #       Convert it to a list of overlapping triplets
    ®*          #    Multiply each 3x3 block by the value in matrix `®`
                #    (so the 0s remain 0s)
    €€à         #    Keep the largest value from each 3x3 block:
    €€          #     Nested map over each 3x3 block:
      à         #       Pop and push its flattened maximum
   }            #   Close the flood-fill loop
    Ð˜s¢2@*_*   #   Remove all islands of 2 or more cells from the matrix:
    Ð           #    Triplicate the resulting matrix of 0s and positive islands
     ˜          #    Flatten the top copy
      s         #    Swap so the other copy of the matrix is at the top
       ¢        #    For each value in the matrix, count its occurrences in the list
        2@      #    Check for each count whether it's >= 2
          *     #    Multiply these checks to the matrix of 0s and positive islands
           _    #    Check for each value whether it's equal to 0
                #    (the falsey results are the islands we'll remove)
            *   #    Multiply it to the values of the matrix to 'explode' the islands
  }             #  Close the [1,9]-loop
   ø0δ†ø        #  Collapse the bricks of the building down after the explosions:
   ø            #   Zip the matrix; swapping rows/columns
     δ          #   Map over each inner list (each column):
    0 †         #    Filter all 0s to the front
       ø        #   Zip/transpose it back
                # (after which the result is output implicitly)

```

# Answer
> 5 votes
# JavaScript (ES7), 167 bytes

Expects a matrix of integers. Returns another matrix of integers, with `0` for smoke.

```
f=(m,V=[],X,Y)=>~m.map((r,y)=>r.map((v,x)=>X+1?6>>(X-x)**2+(Y-y)**2&V==v?V='':0:V[x]=f(m,v,x,y)+[V[x]]))/X?V:m+''==(V.map((s,j)=>m.map((r,i)=>r[j]=~~s[4-i])),m)?m:f(m)

```

Try it online!

## How?

We use the same recursive function to process two distinct steps:

1. Fill an array of strings representing the updated columns of the matrix without removed cells. Then convert this array back to a matrix.
2. Test whether a given cell should be removed.

### Step 1

The variable \\$V\\$ is initially set to an empty array and the variables \\$X\\$ and \\$Y\\$ are undefined.

For each cell at \\$(x,y)\\$ with value \\$v\\$, we insert the result of the second step at the beginning of \\$V\[x\]\\$ (coerced to an empty string if it's still undefined):

```
V[x] = f(m, v, x, y) + [V[x]]

```

Once all cells have been processed, we transpose the strings stored in \\$V\\$ to build the new matrix with each column filled with leading 0's wherever needed:

```
V.map((s, j) =>
  m.map((r, i) => r[j] = ~~s[4 - i])
)

```

If the matrix is unchanged, we stop and return it. Otherwise, we do a recursive call at step 1.

### Step 2

The variable \\$V\\$ is set to the value of the cell being tested and the variables \\$X\\$ and \\$Y\\$ hold its coordinates.

We walk through each cell at \\$(x,y)\\$ and set \\$V\\$ to an empty string as soon as a neighbor cell with the same value \\$v\\$ is detected. A neighbor cell is a cell whose squared Euclidean distance with the reference cell is either \\$1\\$ or \\$2\\$. This is tested with a bitmask:

```
6 >> (X - x) ** 2 + (Y - y) ** 2 & V == v

```

NB: Because the matrix is \\$5\times5\\$, the maximum squared Euclidean distance is \\$32\\$, in which case the shift amount will wrap to \\$0\\$. Fortunately, this will still work as expected.

Once all cells have been processed, we simply return \\$V\\$.

# Answer
> 3 votes
# Charcoal, 55 bytes

```
Ｅ⁵ＳＷ¬⁼υθ«≔υθ≔Ｅ⁵⟦⟧υＦ⁵Ｆ⁵«Ｊκ⁻⁴λ¿¬№ＫＭＫＫ⊞§υκＫＫ»⎚ＧT⁵☁↑Ｅυ⪫κω

```

Try it online! Link is to verbose version of code. Explanation:

```
Ｅ⁵Ｓ

```

Copy the input to the canvas.

```
Ｗ¬⁼υθ«

```

Repeat until two iterations produce the same result.

```
≔υθ

```

Save the result of the previous iteration.

```
≔Ｅ⁵⟦⟧υ

```

Start collecting lonely bricks for this iteration.

```
Ｆ⁵Ｆ⁵«Ｊκ⁻⁴λ

```

Loop over the columns from left to right and the rows from bottom to top.

```
¿¬№ＫＭＫＫ⊞§υκＫＫ

```

If this brick is lonely then collect it.

```
»⎚

```

Clear the canvas.

```
ＧT⁵☁

```

Output a background of clouds, leaving the cursor at the bottom left.

```
↑Ｅυ⪫κω

```

Output the lonely bricks from left to right and bottom to top.

# Answer
> 2 votes
# Julia 1.8, 144 bytes

```
!o=(k=keys(o)).|>_->(o.=[(2>count(o[i].==get.([o],i-k[7].+k[1:3,1:3],0)))o[i] for i=k];[o[j,i]<1&&(o[j-1:j,i]=o[[j,j-1],i]) for i=1:5,j=5:-1:2])

```

Try it online!

mutates the input. uses zeros for ashes

# Answer
> 2 votes
# Python3, 507 bytes:

```
E=enumerate
def S(b):
 q=[*b]
 while q:
  Q=[q.pop(0)];R=[Q[0]]
  while Q:
   x,y=Q.pop(0)
   F=1
   for X,Y in[(1,0),(0,1),(0,-1),(-1,0),(-1,-1),(1,-1),(-1,1),(1,1)]:
    C=(x+X,y+Y)
    if C in b and b[C]==b[(x,y)] and C not in R:Q+=[C];F=0;R+=[C];q.remove(C)
   if F and len(R)>1:yield R
def f(b):
 while 1:
  F=1
  for i in S({(x,y):v for x,r in E(b)for y,v in E(r)if v}):
   F=0
   for x,y in i:b[x][y]=0
  if F:return b
  b=[*map(list,zip(*[[j for j in i if 0==j]+[*filter(None,i)]for i in zip(*b)]))]

```

Try it online!

# Answer
> 1 votes
# Python 3.8, ~~231~~ 227 bytes

```
def f(a,X=range(5)):
 while(b:=[[(i:=a[r][c])-i*any(all([r-2<R<r+2,c-2<C<c+2,(r,c)!=(R,C),a[R][C]==i])for R in X for C in X)for c in X]for r in X])!=a:a=[[([0]*5+[R[c]for R in b if R[c]])[-5:][r]for c in X]for r in X]
 return a

```

Try it online!

## Ungolfed and commented

```
def f(a):
 for _ in range(25):a=h(g(a))
 return a

# Replace connected integers with 0s
def g(a):
 b=[[*i]for i in a]
 for r in range(5):
  for c in range(5):
   i=a[r][c]
   if I(a,r,c,i):b[r][c]=0
   else:b[r][c]=i
 return b

# Check surrounding cells
def I(a,r,c,i):
 for R in range(5):
  for C in range(5):
   if r-2<R<r+2and c-2<C<c+2and(r,c)!=(R,C)and a[R][C]==i:return 1
 return 0

# Drop numbers down based on positions of 0
def h(a):
 b=[[0]*5for i in a]
 for c in range(5):
  C=([0]*5+[R[c]for R in a if R[c]])[-5:]
  for r in range(5):b[r][c]=C[r]
 return b

```

Try it online!

# Answer
> 1 votes
# Jelly, ~~27~~ 24 bytes

```
ŻṖ;"⁺Ḋ)Zð⁺ċ""Ị×ZṠÞ€Zµ$ƬṪ

```

Try it online!

*-2 with `¬¬$` -\> , -1 with dyadic chaining via extreme chain separator abuse*

The neighborhood logic feels a bit... unhinged, but I'm not mentally present enough to devise or steal anything better at the moment.

```
      )                     For each row:
ŻṖ                          Prepend 0 and remove the last element,
  ;"                        concatenate with corresponding original elements,
    ⁺                       and do the same
     Ḋ                      with the first element removed.
       Z                    Transpose,
        ð⁺                  and do it again.
          ċ""               How many times is the middle in each neighborhood?
             Ị×             Zero out elements with counts greater than 1.
               Z  €Z        For each column,
                 Þ          sort its elements by
                Ṡ           their signs.
                    µ$ƬṪ    Repeat all of that while unique.

```

---
Tags: code-golf
---


title: Write a typeracer

text:
# Question
Title: Write a typeracer
# Description

a typeracer is an apps where user could type and evaluate their typing speed and accuracy.

# Criteria

* User could type "A quick brown fox jumps over the lazy dog."
* A visual indicator of each wrong character typed.
* A visual indicator of what characters to type.
* A visual indicator of what has been typed
* A visual indicator of what hasn't been typed.
* After the last character is typed, shows time it took, WPM, and accuracy.
    + Time it took: since first character typed till the last character typed
    + WPM: round(right character typed/5)
    + Accuracy: right characters / all characters

# Answer
> 0 votes
I'm quite new to code golf forum. I've written a type racer with criteria above.

https://ramsicandra.com/type-racer.html

https://github.com/ramsicandra/simple-type-racer

---
Tags: popularity-contest
---


# Question
Title: Draw the Ionising Radiation Hazard Symbol
Draw the ionising-radiation-hazard-symbol in an arbitrary colour on a distinctly coloured background. The specific proportions were published in the June 27th 1974 issue of the Federal Register of the US Government.

### Details

* As output, writing to a file (raster and vector formats are permitted) or displaying on the screen are both allowed.
* You can draw just the border or the filled shape.
* If you use raster images, you should take a parameter (or two) as input that lets you adjust the resolution of the output (e.g. width/height).
* The background must at least have the size of the bounding box of the symbol but may be larger.
* Outputting the unicode symbol ☢ is not sufficient.
* The exact ratios of the used distances are given in following diagram (which was originally from here):

Related: Draw the ☣ (Biohazard Symbol)

# Answer
> 41 votes
# BBC BASIC, 200 bytes

```
f=500
g=1/SQR(3)
CIRCLE FILLf,f,f
GCOL15
MOVE-100,f
MOVEf,f
PLOT85,f*(1-g),0
MOVE1100,f
MOVEf,f
PLOT85,f*(1+g),0
MOVEf*(1-g),2*f
MOVEf,f
PLOT85,f*(1+g),2*f
CIRCLE FILLf,f,150
GCOL0
CIRCLE FILLf,f,100

```

Somehow outgolfing Python, this works by drawing a large black circle, filling in the white triangular sections, drawing a central white circle and finally drawing the central black circle.

# Answer
> 20 votes
# MATL, ~~46~~ ~~44~~ 41 bytes

```
:t_0vSt!Yy1MZ;3*YP/koyG.3*>*yG<*wG5/<=3YG

```

Given an input `n`, the image has width `2*n+1` in pixels.

Try it at MATL Online!

### Explanation

```
:       % Implicit input n. Range [1 ... n]
t_      % Duplicate, negate. Gives [-1 ... -n]
0       % Push 0
v       % Concatenate stack as a column vector: [1; ...; n; -1; ...; -n; 0]
S       % Sort. Gives [-n; -n+1; ... n]
t!      % Duplicate, transpose. Gives the row vector [-n -n+1 ... n]
Yy      % Hypotenuse, with implicit expansion. Gives a matrix containing radius
        % for all points in a grid from -n to -n
1M      % Push the two inputs of the last function, again
Z;      % atan2, with implicit expansion. Gives a matrix containing angle between
        % -pi and pi, where 0 is real positive semiaxis
3*YP/k  % Multiply by 3, divide by pi, round down. Gives an integer for each sextant
o       % Parity. This assigns 0 and 1 alternately to points in different sextants.
        % See this partial result as IMAGE 1 below.
y       % Duplicate from below: pushes the matrix of radii again
G.3*>   % Greater than 0.3*n?, element-wise. Gives 0 or 1 for each entry. This
        % realizes the "1.5R" circle from the specification. See IMAGE 2
*       % Multiply, element-wise. See IMAGE 3
y       % Duplicate from below: pushes the matrix of radii again
G<      % Less than n?, element-wise. Gives 0 or 1 for each entry. This realizes
        % the "5R" circle from the specification. See IMAGE 4
*       % Multiply, element-wise. See IMAGE 5
w       % Swap: pushes the original matrix of radii to the top
G5/<    % Mess than 0.2*n? This realizes the "R" circle in the spec. See IMAGE 6
=       % Equal?, element-wise. This combines the two matrices so far to produce
        % the final result, with 0 for foreground pixels and 1 for background pixels.
        % See IMAGE 7
3YG     % Show image. 0 is displayed as black, 1 as white

```

Intermediate results. 0 is shown as black, 1 as white:

* Image 1:

* Image 2:

* Image 3:

* Image 4:

* Image 5:

* Image 6:

* Image 7 (final result):

# Answer
> 18 votes
## SVG(HTML5), 175 bytes

```
<svg viewBox=-24,-24,48,48><circle r=4 /><path id=b d=M3,-5.2A6,6,0,0,1,6,0H20A20,20,0,0,0,10,-17.32z /><use href=#b transform=rotate(120) /><use href=#b transform=rotate(240)
```

Originally based on @Arnauld's answer, but removes unnecessary characters, scales the numbers by 80% to make them golfier, and draws the curved section's lines in a different order so that I can use an `H` instead of an `L`.

# Answer
> 18 votes
# SVG(HTML5), ~~128~~ ~~126~~ ~~124~~ 120 bytes

(Thanks *Wheat Wizard* for saving 2 bytes by using `.2` rather than `0.2`)
(Drawing triangles from right to left saves 2 bytes)
(Thanks *Grimmy* for saving 2 bytes by using a modified path)
(And reduced another 2 bytes by using a different starting point on the path)

```
 <svg viewbox=-2,-2,4,4>
  <circle r=1 />
  <circle r=.3 fill=#FFF />
  <path d=m2,3.4V0h-4v3.4l4,-6.8h-4 fill=#FFF />
  <circle r=.2

```

```
<svg viewbox=-2,-2,4,4><circle r=1 /><circle r=.3 fill=#FFF /><path d=m2,3.4V0h-4v3.4l4,-6.8h-4 fill=#FFF /><circle r=.2
```

Rather than basing the SVG on wikipedia's vector image - which is drawn in a reasonable way, this solution draws:

1. A black large circle `<circle r=1 />`
2. A smaller white circle `<circle r=.3 fill=#FFF />`
3. Three white triangles as a single continuous path `<path d=m2,3.4V0h-4v3.4l4,-6.8h-4 fill=#FFF />`
4. And a small black circle `<circle r=.2`

Taking advantage of modern browsers forgiving interpretation which ignores unclosed tags (saved the final 9 bytes of  `/></svg>` )

### This is the result:

And this is the same code with the path in yellow to demonstrate what's going on:

# Answer
> 17 votes
# Jelly, 42 bytes

```
÷ÆṬ÷ØPḂ×3ḞḂ
æịA©>5,1.5aç^/o®Ị¤
×5ŒR÷µçþAZY

```

Try it online!

A full program that takes an integer n that determines the radius of the central circle and implicitly outputs to STDOUT a \\$10n+1\\$ square with the desired image encoded as `1` for black and `0` for white.

Per @flawr, this is a permitted output format. Note also that this is effectively a PBM file without the header. Adding `P1 L L` to the start (where L is replaced by \\$10n+1\\$) would make it a valid PBM file. Ta

## Explanation

### Helper link 2

Dyadic link taking y coordinate as left and x as right argument; returns whether the angle is within the filled outer area

```
÷           | Divide (y by x)
 ÆṬ         | Arc-tangent
   ÷ØP      | Divide by pi
      Ḃ     | Mod 2
       ×3   | Times 3
         Ḟ  | Floor
          Ḃ | Mod 2

```

### Helper link 1

Dyadic link taking y coordinate as left and x as right argument

```
æị                 | Convert to complex
  A                | Absolute (i.e. distance from origin)
   ©               | Copy to register
    >5,1.5         | Greater than 5,1.5 (vectorises, so will give two booleans)
          a        | Logical and with:
           ç       | - Result of helper link 2 applied to the input of this link
            ^/     | Reduce using exclusive or
              o  ¤ | Or following as a nilad:
               ®   | Value in register
                Ị  | Absolute of this <= 1

```

### Main link

```
×5         | Times 5
  ŒR       | Range from -this to +this
    ÷      | Divide by input
     µ     | Start a new monadic chain
      çþ   | Outer table using helper link 1 and:
        A  | - Absolute of the range as the right argument
         Z | Transpose rows and columns

```

Sample image for `n=5`

# Answer
> 14 votes
# JavaScript (ES7),  ~~118 113 98~~  93 bytes

*Saved 15 bytes thanks to @tsh!*

Takes a parameter \\$w\\$ as input and draws an ASCII art of width \\$2w-1\\$ and height \\$2w\\$, using `0` and `1` for the 'pixels'.

```
f=(x,w=y=x)=>y+w?(--x+w?(r=x*x+y*y,4*x*x>r^y<0?1019:3)>>r**.5/w*10&1:(x=w,y--,`
`))+f(x,w):''

```

Try it online!

### How?

We compute the squared distance from the center:

$$r=x^2+y^2$$

We use \\$\sqrt{r}\\$ to quantize the distance from the center into 10 bins of width \\$w\\$:

$$\left\lfloor\frac{10\sqrt{r}}{w}\right\rfloor$$

We use \\$r\\$, \\$x\\$ and \\$y\\$ to determine in which kind of sector we are:

$$(4x^2\>r)\text{ xor }(y\<0)$$

See this graph!

We turn the above result into a drawing bit-mask, as summarized in the following schema:

Hence the value of the pixel at \\$(x,y)\\$:

```
(
  r = x * x + y * y,
  4 * x * x > r ^ y < 0 ?
    1019
  :
    3
)
>> r ** 0.5 / w * 10
& 1

```

# Answer
> 14 votes
# Google Sheets, 277 bytes

```
=ARRAYFORMULA((POW(COLUMN(A1:CV99)-5*A1,2)+POW(ROW(A1:CV99)-5*A1,2)<A1*A1)+(POW(COLUMN(A1:CV99)-5*A1,2)+POW(ROW(A1:CV99)-5*A1,2)>9/4*A1*A1)*(POW(COLUMN(A1:CV99)-5*A1,2)+POW(ROW(A1:CV99)-5*A1,2)<25*A1*A1)*IFERROR((MOD(3*ATAN2(COLUMN(A1:CV99)-5*A1,ROW(A1:CV99)-5*A1)/PI(),2)<1),0

```

Creates a grid of `1`s and `0`s which can be coloured using a conditional format. It takes input in cell A1 as the value of R.

Here's a link.

# Answer
> 9 votes
# HTML / SVG,  ~~201~~  189 bytes

A revamped version of this file from Wikimedia Commons.

```
<svg viewBox=-30,-30,60,60><circle r=5 /><path id=b d=M7.5,0A7.5,7.5,0,0,0,3.7,-6.5L12.5,-21.6A25,25,0,0,1,25,0z /><use href=#b transform=rotate(120) /><use href=#b transform=rotate(240) />
```

# Answer
> 8 votes
# C (gcc) (MinGW), ~~245~~ ~~244~~ ~~242~~ ~~236~~ ~~223~~ 221 bytes

-6 bytes thanks to ceilingcat.

Added `-lm` on TiO so that it works there. MinGW does not require it.

Outputs a 3-shade PGM file to STDOUT. Takes width (height is the same) of image as a command line argument.

```
main(q,v,r,c,m)char**v;{*v=calloc(q+1,q=atoi(v[1]));float R=q/10.1,d;for(r=m=q/2;r--+m;)for(c=m;c--+m;m[*v+(r+m)*q+c]=d<R*5&&d<=R|d>=1.5*R&asin(r/d)+1.5707>(r>0?5:1)*0.5235?:2)d=hypot(c,r);printf("P5 %d %d 2 %s",q,q,*v);}

```

Try it online!

# Answer
> 8 votes
# Haskell (code.world dialect), ~~108~~ 86 bytes

```
drawingOf(c(2)&colored(c(3),white)&0%1&2%3&4%5)
c=solidCircle
a%b=sector(a*60,b*60,10)

```

Run on code.world!

# Answer
> 8 votes
# Runic Enchantments, 216 bytes

```
D::i</~1-:0)?;{:}ak$2?X2    8?1]$#'~~\1?7 c?1$ '~~\?3  L
R:0)?/1-:̹{2,::}}-S{-2pS2p+'qA:{5,:}≮?/:}3,2*S:}S≯?/5,)?/]:̹{2,:}-S{-:̹'-A}'-A0)3*?P2?Z0]{{S:0)a*?:0(4*?~~10,'|A'aA{0)?S-:0≮4*?P2*+3*2P*%P)4*?'#2?' $]

```

Try it online!

*Dear god. Why.
So much went wrong.
It makes me cry.*

Several major impediments that ended up making this both (a) a nearly unreadable mess and (b) *frustratingly difficult.*

The first problem was the fact that Runic doesn't have `atan2(x,y)`, so I had to *heckin' work that out myself*. And oh yeah, make sure its reasonably golfed, it had to be dropped into an existing program with no alterations, so in-line conditional logic was preferable.

The *second* problem was that I had a weird issue where I'd multiply the tangent value by 3, modulo to 2pi and get...nonsense. What even is that? Why is it not using angular values? Turned out I had a stray extra value at the bottom of the stack that was throwing the math off. Whoops.

*THEN*
***AND THEN***
The program would just suddenly die after the first four bytes of the outer wedges. Oh my, what fun we had. Lets simplify, shall we? Lets just isolate the inputs at that point and... oh. It works fine.

I.

Uh.

Hmm.

When in doubt, check the source code. Can you spot the difference?

Yep. Integer values are *totes* allowed to divide by zero (and return infinity) and doubles aren't. Oh and that's not even true in the original Unity C# code (which I use as a graphical debugger) as it was an *intentional design decision* to terminate on div-by-zero.

Wot. Also, conversion to float instead of double for no reason. Just sittin' there.

(╯°Д°)╯︵┻━┻

### Explanation

I need a drink first.
That's better.

```
D::i<                     Set up the stack, we need a current position (X,Y) and total size. Init all to read value, counting down is easier than counting up.
                          The D here, and the R below it, constitute the main loop entry
R:0)?\1-                  Compare current X against zero, else decrement
     \~1-:0)?;{:}ak$      if zero, decrement Y. If Y is zero, terminate, else return to the D on the first line (there's a lot of skip-over-logic)
:̹ {2,::}}-S{-             dupe the entire stack, then translate origin by 1/2 width
2pS2p+'qA                 square root (x*x+y*y)
:{5,:}≮?\:}3,2*S:}S≯?\    compare that against 1/20th the width and 1.5/20th the width (R and 1.5R)
  ]$#'~~L       $ '~~L    Print # or <space> for the inner circle (and return to D) skip-bypasses omitted
5,)?/                     Compare against 1/10th the width (5R), print a space and return to D

]:̹ {2,:}-S{-:̹ '-A}'-A0)3*?P2?Z0]{{S:0)a*?:0(4*?~~10,'|A'aA{0)?S-    Dupe the entire stack and compute atan2(x,y)

:0≮4*?P2*+                       Convert negative values to values greater than pi up to 2 pi
          3*2P*%P)4*?'#2?' $]    Multiply by 3, modulo 2pi, compare against pi. Less: print # else print space. Return to R.

```

Be wary of improperly stacking unicode combining characters. The little `̹` makes the command apply to the stack-of-stacks and `̸` is boolean-not; eg.  is "not less than (aka greater-equals)." Looks like it costs bytes, but because of the upper line, there's a byte savings in that line being shorter, which pays for the +1 byte cost for an extended character in the lower line (typically assuming that the lower line could be `?!/` instead of `?/`).

# Answer
> 7 votes
# TikZ, 170 bytes

```
\documentclass[tikz]{standalone}\begin{document}\tikz{\fill circle(10);\foreach\a in{0,120,240}{\fill[white]circle(3)--(\a-60:13)--(\a:13);}\fill circle(2)}\end{document}

```

# Answer
> 7 votes
## Logo, 96 bytes

```
circle 16
rt 90
repeat 3[arc 80 60
arc 24 60
pu
repeat 2[fw 24
pd
fw 56
pu
backward 80
rt 60]pd]

```

Try it online! Draws just the border.

# Answer
> 7 votes
# Desmos/Cartesian Plane, 103 97 86 84 bytes

## (23 arithmetic and comparison operators)

`(abs(mod(arctan(x,-y)/\pi*6,4)-2)-1)*max(0,182-abs(x^2+y^2-218))+max(0,16-x^2-y^2)>0`

https://www.desmos.com/calculator/hadw7gayfn

# Answer
> 6 votes
# Mathematica, 93 88 85 76 74 70 bytes

```
RegionPlot[1.5<#<5&&Sin[3#2]>0||#<1&@@AbsArg[x+I y],{x,-5,5},{y,-5,5}]

```

-4 bytes thanks to Roman.

It is not clear from the description whether it is required to get rid of the outline and make it black on white, but I think the submission looks best and is shortest like this.

# Answer
> 6 votes
## Mathematica (Wolfram Language) ~~76~~ 71 Bytes

This solution draws the radiation symbol using only the `Disk[]` primitive, which allows for arcs.

By default a `Graphics` object in Mathematica has a White background and objects are Black unless otherwise specified. So we first draw three black disk sectors, then a small white disk and finally a smaller inner black disk. Unlike @Mario Carneiro's solution (which is a nice use of RegionPlot), this comes without axes and without the artifacts produced by the inner workings of RegionPlot.

Saved a byte by letting R=2

```
Graphics@{(d={0,0}~Disk~##&)[10,{#,#+1}Pi/3]&/@{0,2,4},{White,d@3},d@2}

```

# Answer
> 5 votes
## Python 3.8, 129 124 122 120 119

```
def f(N):[print((abs(a:=(i%N+i//N*1j)*2/N-1-1j)<.2)+((a**3).imag<0<.3<abs(a)<1),end=(-i%N==1)*"\n")for i in range(N*N)]

```

Output (N=20):

```
00000000000000000000
00000000000000000000
00000100000000010000
00011100000000011100
00011110000000111100
00111111000001111110
01111111000001111111
01111111100011111111
01111111000001111111
01111111011101111111
00000000011100000000
00000000011100000000
00000000000000000000
00000000010100000000
00000000111110000000
00000000111110000000
00000001111111000000
00000011111111100000
00000011111111100000
00000011111111100000

```

The idea is to represent each point in the plane by a complex number \\$x\\$. Let the radius of the innermost circle be \\$2\\$. Then \\$x\\$ is inside the inner circle if \\$|x|\<2\\$.

The outer parts are a bit more involved. To lie in one of the outer parts, we have to have \\$3=1.5\cdot 2\< |x| \< 5\cdot 2 = 10\\$ so that the distance is neither too small nor too large. We also have an angle restriction: the polar angle of \\$x\\$ has to lie between \\$60^\circ\\$ and \\$120^\circ\\$, when taken mod \\$120^\circ\\$. But if we instead look at \\$x^3\\$, the angle is multiplied by three, so that the polar angle of \\$x^3\\$ has to lie between \\$180^\circ\\$ and \\$360^\circ\\$ (mod \\$360^\circ\\$). This is just equivalent to \\$\Im(x^3)\<0\\$.

To put it all together, we have to have \\$|x|\<2\\$ or both of \\$3\<|x|\<10\\$ and \\$\Im(x^3)\<0\\$ for \\$x\\$ to be inside the image. As both conditions are mutually exclusive, their truth values can just be added together.

# Answer
> 5 votes
# PostScript, ~~183~~ 175 bytes

Code (compressed version):

```
20 20 scale 9 6 translate<</f{closepath fill}/c{0 360 arc f}/l{10 0 lineto -60 rotate}>>begin 0 0 5 c 1 setgray 3{0 0 moveto l l f} repeat 0 0 1.5 c 0 setgray 0 0 1 c showpage

```

Code (uncompressed version):

```
20 20 scale           % over-all scale
9 6 translate         % over-all shift

% define some short-named procedures for later use
<<
  /f { closepath fill }
  /c { 0 360 arc f }  % filled circle (x, y, radius are taken from stack)
  /l { 10 0 lineto
       -60 rotate }   % long line + rotate by 60°
>> begin

0 0 5 c               % big black circle
1 setgray             % set white color
3 {
  0 0 moveto l l f    % white triangle + rotate by 120°
} repeat
0 0 1.5 c             % white circle
0 setgray             % set black color
0 0 1 c               % small black circle
showpage

```

Result (as animation to see how it is drawn):

# Answer
> 4 votes
# python 3.8, 220

```

from PIL import Image as I
from math import*
d=300
h=d//2
r0=d/10
g=range(-h,h)
i=I.frombytes('L',(d,d),bytes([255,0][1.5<(r:=(x*x+y*y)**.5)/r0<5 and(atan2(x,y)/pi+7/6)*1.5%1.>.5 or r<r0]for y in g for x in g))
i.show()

```

The idea behind is very simple: we count `(x,y)` from the center of image and `r=(x*x+y*y)**.5` is the distance between point and the center.
The point is black if either `r<r0` where `r0` is `1/5` distance from center to a side
or if `5*r0<r<1.5*r0` (see the diagram in the question) and the angle from center to the point (computed with `math.atan2`) is in selected ranges. `1.5` and `7/6` there were obtained almost empirically, but could be reasoned too.
The other (most) part is a wrap-in.

# Answer
> 4 votes
# Red, ~~237~~ 218 bytes

```
Red[needs: 'View]
g: func[n][a: compose[arc(s: n / 2.0 * 50x50)(s)60 60 closed
rotate 120(s)]view compose/deep[base(s * 2)draw[(f: 'fill-pen)black(a)(a)(a)
pen gray line-width(0.1 * s/1)(f)black circle(s)(s/1 / 4.0)]]]

```

Takes a parameter `n` \- the width/height in multiples of 50.

# Answer
> 4 votes
**TikZ, 93 bytes**

The last comma `;` at the end of the code can be missed.

```
\foreach\i in{0,120,240}\fill[rotate=\i](60:3)arc(60:0:3)--(0:10)arc(0:60:10);\fill circle(2)

```

**TikZ, 164 bytes**

```
\documentclass[tikz]{standalone}\begin{document}\tikz{\foreach\i in{0,120,240}\fill[rotate=\i](60:3)arc(60:0:3)--(0:10)arc(0:60:10);\fill circle(2)}\end{document}

```

**Asymptote 109 bytes**

```
// Run on http://asymptote.ualberta.ca/
for(int i=0;i<3;++i)fill(rotate(i*120)*(arc((0,0),3,60,0)--arc((0,0),10,0,60)--cycle));fill(circle((0,0),2));

```

**Asymptote 117 bytes**

```
// Run on http://asymptote.ualberta.ca/
for(int i: new int[]{0,120,240})fill(rotate(i)*(arc((0,0),3,60,0)--arc((0,0),10,0,60)--cycle));fill(circle((0,0),2));

```

# Answer
> 4 votes
# Desmos, 3+~~70~~ 64=~~73~~ 67 bytes

After seeing Will Chen's answer and seeing that the online link no longer seemed to work, I figured I'd start at it from scratch, and ended up with 11 fewer bytes.

```
r<2
max(0,mod(-sign(x)arctan(y/x),120)-60)(x^2+y^2-9)(x^2+y^2-100)<0

```

View it online

Edit: realized `max` is unnecessary for the latter two functions. It's required for the first function to zero out a lot of areas, but this might be able to be improved. This makes this the shortest answer in a non-golfing language, beating out Mathematica, with some potential for improvement.

This originally used a bunch of piecewise conditionals, which simply evaluate to 1 if true and undefined if false, making them handy for this purpose. However, by just multiplying them through and comparing to 0, we can check for polarity in a shorter way. The reason we do `<0` at the end instead of `>0` like you may expect is that the last block, checking if r\>10, needs to evaluate to false (negative). The only other notable thing is the polarity check in the first part because `arctan(y/x)` doesn't necessarily work as well for angle-finding as you might hope.

# Answer
> 3 votes
# Ruby, ~~91~~ 100 bytes

```
->s{(w=-(s/=2)..s).map{|x|w.map{|r|a=x*x+r*=r;' O'[a<(b=s*s)/25||a>b/11&&a<b&&x*(r*4-a)<0?1:0]}*''}}

```

Try it online!

Accepting 1 parameter (size of the image).

Example output for s=40:

```
          O                   O
         OO                   OO
       OOOOO                 OOOOO
      OOOOOO                 OOOOOO
     OOOOOOOO               OOOOOOOO
     OOOOOOOOO             OOOOOOOOO
    OOOOOOOOOO             OOOOOOOOOO
   OOOOOOOOOOOO           OOOOOOOOOOOO
   OOOOOOOOOOOO           OOOOOOOOOOOO
  OOOOOOOOOOOOOO         OOOOOOOOOOOOOO
  OOOOOOOOOOOOOO         OOOOOOOOOOOOOO
 OOOOOOOOOOOOOOOO       OOOOOOOOOOOOOOOO
 OOOOOOOOOOOOOOOO       OOOOOOOOOOOOOOOO
 OOOOOOOOOOOOOOO         OOOOOOOOOOOOOOO
 OOOOOOOOOOOOOO   OOOOO   OOOOOOOOOOOOOO
 OOOOOOOOOOOOOO  OOOOOOO  OOOOOOOOOOOOOO
 OOOOOOOOOOOOOO  OOOOOOO  OOOOOOOOOOOOOO
                 OOOOOOO
                 OOOOOOO
                 OOOOOOO
                  OOOOO

                 OOO OOO
                OOOOOOOOO
                OOOOOOOOO
               OOOOOOOOOOO
               OOOOOOOOOOO
              OOOOOOOOOOOOO
              OOOOOOOOOOOOO
             OOOOOOOOOOOOOOO
            OOOOOOOOOOOOOOOOO
            OOOOOOOOOOOOOOOOO
           OOOOOOOOOOOOOOOOOOO
           OOOOOOOOOOOOOOOOOOO
            OOOOOOOOOOOOOOOOO
              OOOOOOOOOOOOO

```

# Answer
> 3 votes
# OpenSCAD, 153 bytes

```
module a(){polygon([[0,0],[5,0],[5,10]]);}module b(){a();rotate(120)a();rotate(240)a();}circle();intersection(){difference(){circle(5);circle(1.5);}b();}

```

Uncompressed:

```
module triangle()
{
    polygon(points=[[0,0],[5,0],[5,10]]);
}

module triangles() {
    triangle();
    rotate(120) triangle();
    rotate(240) triangle();
}

module radiation()
{
    circle($fn = 100);
    intersection() {
        difference() {
            circle(5, $fn = 100);
            circle(1.5, $fn = 100);
        }
        triangles();
    }
}

radiation();

```

Notice the extra `$fn = 100` in the circles, which are used to make them higher-resolution polygon. We could add `$fs=.1;` at the beginning of the file, which would also improve the resolution.

# Answer
> 3 votes
# SVG(HTML5), 114 bytes

```
<svg viewBox=-1,-1,2,2><circle r=.65 fill=none stroke=#000 stroke-width=.7 stroke-dasharray=0,.68,0 /><circle r=.2
```

An alternative solution to the other SVG answers. Uses the stroke dash property to create the 'wings'.

The value of the `.68` should be equal to `0.65 / 3 * PI`, or `0.680678408...` to be more accurate.

If incorrect rotation is allowed, this can be reduced to 110 bytes:

```
<svg viewBox=-1,-1,2,2><circle r=.65 fill=none stroke=#000 stroke-width=.7 stroke-dasharray=.68 /><circle r=.2
```

# Answer
> 2 votes
# GLSL / Shadertoy, 181 bytes

```
void mainImage(out vec4 o,vec2 c)
{
    vec2 p=(c-iResolution.xy/2.)/iResolution.y;
    float k=length(p),h=acos(-1.)/3.;
    o=step(0.,min(k-.1,max(k-.5,.15-k)*step(mod(atan(p.y,p.x),h+h),h)))-o;
}

```

Copy and paste this code into the editor then press the play button to run the shader.

The shader uses the signed distance of the shapes to be able to use the union and intersection operations to generate the symbol.

# Answer
> 2 votes
# TI-BASIC (TI-84+), 1042 bytes

```
"000000000000000000000000000000000000000000000000000000000000000300000000000000780000006000001FC000000F800003FC000001FC00007FE000001FE0000FFE000003FF0001FFF000003FF8003FFF000007FFC003FFF80000FFFC007FFFC0000FFFE00FFFFC0001FFFF00FFFFE0001FFFF01FFFFE0003FFFF81FFFFF0007FFFF83FFFFF8007FFFFC3FFFFF800FFFFFC3FFFFFC00FFFFFC7FFFFFC01FFFFFE7FFFFFC01FFFFFE7FFFFF801FFFFFE7FFFFF0F0FFFFFEFFFFFE3FC7FFFFFFFFFFE7FE7FFFFFFFFFFC7FE3FFFFFFFFFFCFFF3FFFFFFFFFFCFFF3FFFFF000000FFF3FFFFF000000FFF0000000000007FE0000000000007FE0000000000003FC0000000000000F0000000000000000000000000000604000000000000FFE000000000001FFE000000000001FFF000000000003FFF800000000007FFF800000000007FFFC0000000000FFFFC0000000000FFFFE0000000001FFFFF0000000003FFFFF0000000003FFFFF8000000007FFFFF8000000007FFFFFC00000000FFFFFFC00000001FFFFFFE00000001FFFFFFF00000003FFFFFFF00000001FFFFFFF80000000FFFFFFF000000003FFFFFC0000000007FFFE000000000007FE000000→Str1
AxesOff
15→N
4→dim(∟A
For(I,1,60N
sub(Str1,I,1
inString("0123456789ABCDEF",Ans)-1→D
For(B,4,1,-1
D≥2(B-1→∟A(B
If ∟A(B
D-2^(B-1→D
End
For(E,1,4
If ∟A(5-E
Pxl-On(iPart(I/N),E+4remainder(I,N
End
End

```

Oh man, this one was rough. The TI series of calculators do have shading functionality between functions, but that just don't cut it.
Furthermore, I was limited to 60x60 pixels, since drawing on the 62nd row or lower would result in **ERR: ARGUMENT** error being thrown and 60 fits the radii ratios mentioned in the challenge perfectly: $$ R = 12 \\ 1.5R = 18 \\ 5R = 60$$

So, I opted to convert a string of hexadecimal characters to pixels.

The pixels drawn to the screen will look like this:

The *very* long string you see on the first line of the program looks like this when formatted:

```
000000000000000
000000000000000
000000000000000
000000000000000
000300000000000
000780000006000
001FC000000F800
003FC000001FC00
007FE000001FE00
00FFE000003FF00
01FFF000003FF80
03FFF000007FFC0
03FFF80000FFFC0
07FFFC0000FFFE0
0FFFFC0001FFFF0
0FFFFE0001FFFF0
1FFFFE0003FFFF8
1FFFFF0007FFFF8
3FFFFF8007FFFFC
3FFFFF800FFFFFC
3FFFFFC00FFFFFC
7FFFFFC01FFFFFE
7FFFFFC01FFFFFE
7FFFFF801FFFFFE
7FFFFF0F0FFFFFE
FFFFFE3FC7FFFFF
FFFFFE7FE7FFFFF
FFFFFC7FE3FFFFF
FFFFFCFFF3FFFFF
FFFFFCFFF3FFFFF
000000FFF3FFFFF
000000FFF000000
0000007FE000000
0000007FE000000
0000003FC000000
0000000F0000000
000000000000000
000000604000000
000000FFE000000
000001FFE000000
000001FFF000000
000003FFF800000
000007FFF800000
000007FFFC00000
00000FFFFC00000
00000FFFFE00000
00001FFFFF00000
00003FFFFF00000
00003FFFFF80000
00007FFFFF80000
00007FFFFFC0000
0000FFFFFFC0000
0001FFFFFFE0000
0001FFFFFFF0000
0003FFFFFFF0000
0001FFFFFFF8000
0000FFFFFFF0000
00003FFFFFC0000
000007FFFE00000
0000007FE000000

```

Each hexadecimal digit encodes to a series of 4 pixels drawn to the screen. For each bit set in the digit, a pixel will be drawn.

**Explanation:**

```
"000 ... 000→Str1                       ;set the digit string to convert
AxesOff                                 ;get rid of the axes on the graph since
                                        ;  it'll be in the way
15→N                                    ;set N to 15 in order to save a few bytes
4→dim(∟A                                ;set the length of the list A to 4 elements
For(I,1,60N                             ;loop 900 times.  There are 60 lines to draw
                                        ;  and 15 digits per line to convert
sub(Str1,I,1                            ;get the current hexadecimal digit
inString("0123456789ABCDEF",Ans)-1→D    ;convert it to base 10, store the result in D
For(B,4,1,-1                            ;convert number to its binary representation
D≥2(B-1→∟A(B
If ∟A(B
D-2^(B-1→D
End
For(E,1,4                               ;loop over each bit in said representation
If ∟A(5-E                               ;and only draw the pixel if this bit is set
                                        ; (bit order is reversed)
Pxl-On(iPart(I/N),E+4remainder(I,N      ;pixel row (Y) is I/N, pixel column (X) is
                                        ; 4*(I%N)+E
End
End

```

---

**Note:** TI-BASIC is a tokenized language. Character count does *not* equal byte count.

# Answer
> 2 votes
# T-SQL, 185 bytes

```
DECLARE @ GEOMETRY='POINT(6 6)',@b GEOMETRY='POLYGON((12 6,9 0,3 12,9 12,3 0,0 6,12 6))'SELECT @.STBuffer(5).STDifference(@b.MakeValid().STUnion(@.STBuffer(1.5))).STUnion(@.STBuffer(1))

```

I shifted the center from (0,0) to (6,6) to reduce the number of negative numbers needed; this saves a byte or two.

This code isn't quite long enough to benefit from the `REPLACE()` trick that was needed for the Biohazard symbol.

This was done using SQL geo-spatial features introduced in SQL 2008.

Visual of output, with annotated code:

For more T-SQL drawing, see my Biohazard symbol and my Easter Bunny.

# Answer
> 2 votes
# Desmos, 60 bytes

```
w=hsv(0,0,1)
r<5\{[0,3,6]40<\theta<[1,3,5]60\}
xx+yy<9/4
r<1

```

Try it on Desmos

This is the version without scaling, now the shortest Desmos answer.

# Desmos, ~~178~~ ~~161~~ ~~153~~ ~~126~~ ~~119~~ ~~72~~ ~~68~~ 67 bytes

```
R=1
w=hsv(0,0,1)
r<5R\{[0,3,6]40<\theta<[1,3,5]60\}
xx+yy<9RR/4
r<R

```

Try it on Desmos

-12 bytes thanks to @Steffan

-27 bytes by switching to degrees and extracting the "arms" to a function

-55 bytes and fix thanks to @Aiden Chow

-1 byte thanks to emanresu A

~~By far the longest Desmos answer yet,~~ this is now the second shortest answer. Oh, and mine is scalable, just move the \\$R\\$ slider.

# Answer
> 1 votes
# Processing, 172 bytes

```
noStroke();background(255);fill(0);for(float i=-60;i<=300;i+=120)arc(50,50,100,100,radians(i),radians(i+60),PIE);fill(255);circle(50,50,30);fill(0);circle(50,50,20);

```

Un-minified code:

```
noStroke();
background(255);
fill(0);
for(float i=-60;i<=300;i+=120)arc(50,50,100,100,radians(i),radians(i+60),PIE);
fill(255);
circle(50,50,30);
fill(0);
circle(50,50,20);

```

## Output

# Answer
> 1 votes
# C (GCC), 176 bytes

```
main(r,w,j){scanf("%d",&r);w=r*6;float d,h,i=-w;for(printf("P5\n%d %d\n1\n",2*w,2*w);++i<w;)for(j=-w;j<w;)d=(i*i+j*j)/r/r,h=i/abs(j++),putchar(d>1&(2.25>d|d>25|h<-2|h>0&h<2));}
```

Attempt This Online!

Intended version:

```
main(r,w,j){
    scanf("%d",&r);
    w=r*6;
    float d,h,i=-w;

    for(printf("P5\n%d %d\n1\n",2*w,2*w);++i<w;)
        for(j=-w;j<w;)
            d=(i*i+j*j)/r/r,
            h=i/abs(j++),
            putchar(d>1&(2.25>d|d>25|h<-2|h>0&h<2));
}

```

Outputs a binary (black and white) PGM image.

With the following changes (and ~20 bytes **less**), it can output an ASCII image:

* remove the `printf` call and add `puts("")` after `++i<w;`
* add a ternary operator (or some arithmetical hacks) in the last line to replace the boolean value with two printable chars

# Answer
> 1 votes
# QBasic, 176 bytes

```
INPUT r
SCREEN 11
a=1.047
CIRCLE(r,r),r/5
FOR i=0TO 5
j=1AND i
k=i-j
CIRCLE(r,r),r-j*r*.7,,k*a,k*a+a
x=COS(i*a)
y=SIN(i*a)
LINE(r+r*x,r+r*y)-(r+r*x*.3,r+r*y*.3)
NEXT

```

Takes the radius of the figure (i.e. \\$5R\\$ in the diagram) as input.

You can try it at Archive.org; here's what the output looks like for an input of 100:

### Explanation

```
INPUT r

```

Input the radius.

```
SCREEN 11

```

Clear the screen and put it in graphics mode. Normally, I use `SCREEN 9`, but it doesn't seem to draw very circular circles, so the arcs didn't line up with the lines. `SCREEN 11` did the trick for +1 byte.

```
a=1.047

```

Save \\$\pi/3\\$ in a variable.

```
CIRCLE(r,r),r/5

```

Draw the central circle, centered at \\$(r,r)\\$, with a radius of \\$r/5\\$.

```
FOR i=0TO 5

```

Loop six times. Each time through the loop, we're going to draw one arc and one line segment.

```
j=1AND i
k=i-j

```

Set `j` to `i` mod 2 using bitwise AND. Then set `k` to the value of `i`, "rounded down" to the nearest even number.

```
 i | j | k
---|---|---
 0 | 0 | 0
 1 | 1 | 0
 2 | 0 | 2
 3 | 1 | 2
 4 | 0 | 4
 5 | 1 | 4

```

We use `k` to calculate the starting angle of each arc, and `j` to determine its radius:

```
CIRCLE(r,r),r-j*r*.7,,k*a,k*a+a

```

The `CIRCLE` command can take extra arguments indicating the starting and ending angles in radians. Here, we draw an arc centered at \\$(r,r)\\$, with a radius of \\$r-j \cdot r \cdot \frac7{10}\\$: that is, \\$r\\$ when `j` is 0, and \\$\frac3{10}r\\$ when `j` is 1. The starting angle is \\$k \cdot a\\$ and the ending angle is \\$k \cdot a + a\\$ (so \\$0\\$ to \\$\frac\pi3\\$ on the first two iterations, \\$\frac{2\pi}3\\$ to \\$\pi\\$ on the next two, and \\$\frac{4\pi}3\\$ to \\$\frac{5\pi}3\\$ on the last two).

```
x=COS(i*a)
y=SIN(i*a)

```

To draw the line segments, we'll need to calculate their endpoints. First we calculate the `x` and `y` coordinates of a point on the unit circle at each of our six angles.

```
LINE(r+r*x,r+r*y)-(r+r*x*.3,r+r*y*.3)

```

Then we scale each point by \\$r\\$ and \\$\frac3{10}r\\$, translate both of those points by \\$r\\$, and draw a line between them.

```
NEXT

```

And continue to the next value of `i`.

# Answer
> 1 votes
## PostScript, ~~83~~ ~~81~~ ~~43~~ 41 bytes

```
00000000: 2f61 7b92 9b30 8768 0192 0592 a77d 9233  /a{..0.h.....}.3
00000010: 347b 3730 7d92 8335 880a 615b 3334 5d30  4{70}..5..a[34]0
00000020: 9294 3332 2e35 8823 61                   ..32.5.#a

```

Before tokenization (78 bytes):

```
/a{setlinewidth 0 360 arc stroke}def
4{70}repeat
5 10 a[34]0 setdash
32.5 35 a

```

Just two stroked circles, the larger one with a very thick dashed stroke. The dash width 34 seems close enough to the "correct" value of \\$32.5\pi/3=34.033...\\$ to make no visual difference.

# Answer
> 1 votes
# Pikchr, 153 bytes

```
color=-1
define${go 2heading 30*}
define@{
line from 0,0$$1$$2close fill white}
define o{
circle at 0,0fill}
o 0ht 2o white ht.6@(1,9)@(3,7)@(9,5)o 0ht.4

```

## Output

Requires the browser to be in light mode.

```
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 580.32 503.151">
<circle cx="290" cy="251" r="144" style="fill:rgb(0,0,0);"></circle>
<circle cx="290" cy="251" r="43.2" style="fill:rgb(255,255,255);"></circle>
<path d="M290,251L434,2L146,2Z" style="fill:rgb(255,255,255);"></path>
<path d="M290,251L578,251L434,500Z" style="fill:rgb(255,255,255);"></path>
<path d="M290,251L2,251L146,500Z" style="fill:rgb(255,255,255);"></path>
<circle cx="290" cy="251" r="28.8" style="fill:rgb(0,0,0);"></circle>
</svg>
```

# Answer
> 0 votes
# Scratch, ~~262 238~~ 232 bytes

Try it online!

For the method being used, I feel that this is quite optimal. The size, albeit small, is as large as possible without adding bytes. Alternatively, 21 blocks.

```
define(a)(b
set pen color to(a
set pen size to(b
pen down
when gf clicked
repeat(2
point in direction(30
erase all
repeat(3
repeat(60
set pen size to(1
turn cw(1)degrees
move(15)steps
go to x()y(
end
turn cw(60)degrees
[#fff][9
[][6

```

## Explanation

```
define(a)(b             Draws circle of color (a) and diameter (b)
set pen color to(a      sets the circle color
set pen size to(b       sets the circle diameter
pen down                Draws the circle
when gf clicked         Syntax
repeat(2                Loops code twice - removes need to reset position
point in direction(30   Resets angle
erase all               Clears the stage
repeat(3                Loops code for each 'leaf'
repeat(60               Loops code for each degree in a 'leaf'
set pen size to(1       Sets pen diameter to 1
turn cw(1)degrees       Rotates 1 degree
move(15)steps           Draws ray
go to x()y(             Resets to the origin
end                     Syntax
turn cw(60)degrees      Rotates to position of next 'leaf'
[#fff][9                Draws white circle of diameter 9
[][6                    Draws black (default undefined color) circle of diameter 6

```

# Answer
> 0 votes
# JavaScript, 53 bytes

```
s=>(x,y,r=(x*x+y*y)/s)=>r<4|r>9&r<100&(4*x*x/s<r^y<0)

```

A function taking a scale `s` as input, and outputs a pixel shader taking `x` and `y` between `-s/2` and `s/2`.

I took inspiration from Arnauld's answer.

```
shader =
s=>(x,y,r=(x*x+y*y)/s)=>r<4|r>9&r<100&(4*x*x/s<r^y<0)

const scale = 400;

const canvas = document.getElementById('canvas');
canvas.width = canvas.height = scale;
const ctx = canvas.getContext('2d');

let x, y;
for (x = 0; x < scale; x++) for (y = 0; y < scale; y++) {
  ctx.fillStyle = shader(scale)(x - scale / 2, y - scale / 2) ? 'black' : 'yellow';
  ctx.fillRect(x, y, 1, 1);
}
```

```
<canvas id="canvas"/>
```

# Answer
> 0 votes
# Desmos, 95 bytes

```
b<=25
polygon((6,0),(3,-6),(-3,6),(3,6),(-3,-6),(-6,0),(6,0))
b<=2.25
b<=1
c=hsv(0,0,1)
b=xx+yy

```

Try it on Desmos!

Unsure if `c=hsv(0,0,1)` needs to be included in the byte count, but included it just to be safe.

This does steal the `polygon` from the SQL answer.

---
Tags: code-golf, kolmogorov-complexity, graphical-output, geometry
---


# Question
Title: Write the smallest possible code in x86-64 to implement the "<=>" operator
Languages, such as C++, have introduced a new comparison operator: `<=>`.

This operator returns -1, 0, or 1 when comparing two items together:

* −1 means the left-hand side is smaller,
* 0 when both values are equal,
* +1 means the right-hand side is smaller.

Here is what I have been coming up with in x86-64:

```
556:    48 8b 15 d3 04 00 00    mov    0x4d3(%rip),%rdx        # 0xa30 (left handside)
55d:    33 c0                   xor    %eax,%eax
55f:    48 3b 15 9a 04 00 00    cmp    0x49a(%rip),%rdx        # 0xa00 (right handside)
566:    74 08                   je     0x570
568:    0f 9f c0                setg   %al
56b:    d1 e0                   shl    %eax
56d:    48 ff c8                dec    %rax
570:    48 89 45 90             mov    %rax,-0x70(%rbp)        # output

```

The `mov` and `cmp` instructions are not important here since these could as well all be registers. At some point, though, you would have had to load those registers. They are there to show all the details. So my code uses five instructions at the moment.

The final result is expected to be a 64 bits integer.

Two challenges:

* Reduce the number of instructions
* Avoid the need for a branch without increasing the number of instructions

The top winner is the one with the smallest number of instructions. Eliminating the branch adds a bonus point. So two answers with the same number of instructions, the one without a branch wins.

---

: The C++ and possibly other implementations of `<=>` do not mandate specific values, but refer to the sign. The C++ implementation of `<=>` returns *any* negative value, a (mathematically speaking) sign-less value (i. e. `0` \[zero\]), or *any* positive value.

# Answer
> 2 votes
Assuming I can use non-instruction data for free, this can be done in 3 extra instructions:

```
    xor %rax,%rax
    cmp %rsi,%rdi // assume this is free
    cmovl s2,%rax
    cmovg s1,%rax

// in another section
s1: .long 1, 0
s2: .long -1, -1

```

Demo on Godbolt, which has another approach that uses constant data.

# Answer
> 3 votes
If you specifically want to return -1, 0 or 1 as a 64-bit integer, then I believe you can follow your `cmp` instruction with a sequence such as this:

```
0:  0f 9f c0                setg   al
3:  0f 9c c1                setl   cl
6:  28 c8                   sub    al, cl
8:  48 0f be c0             movsx  rax, al

```

The final 64-bit value can be stored in any register, not just `rax` of course.

# Answer
> 3 votes
Comparing unsigned integers can be done in three instructions:

```
0:  0f 97 c1                seta   cl
3:  48 19 c0                sbb    rax, rax
6:  08 c8                   or     al, cl

```

# Answer
> 2 votes
```
cmp esi, edi
seta al
sbb al, 0
movsx rax, al

```

Like Neil's but I found after writing

---
Tags: code-challenge, assembly, fewest-operations
---


title: Output the Current Time

text:
# Question
Title: Output the Current Time
# Challenge

You must output the current time continuously (until cancelled by an interrupt), once every second, by any of the following means:

* It must be in 24-hour or AM/PM format.
    + If it is the former, it must be spaced out with colons (i.e. 15:47:36).
    + If it is the latter, it must be spaced out with colons and have the AM/PM following (i.e. 3:47:36 PM)
* It may be pulled from the internet.
* It may be the system time.
* It must output any naturally accessible form of output which supports text that you choose.
* Output may have extra information aside of the time in it, but you *must* guarantee one, and only one, output of time per second.
* The continuous output must be a second apart - if you choose to wait until the second changes between outputs, that is fine. If you wait a second between each output, that is perfectly acceptable, despite the eventual loss of accuracy.

Since this is a catalog, languages created after this challenge are allowed to compete. Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language. Other than that, all the standard rules of must be obeyed. Submissions in most languages will be scored in bytes in an appropriate preexisting encoding (usually UTF-8).

# Catalog

The Stack Snippet at the bottom of this post generates the catalog from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```
## Language Name, N bytes

```

where `N` is the size of your submission. If you improve your score, you *can* keep old scores in the headline, by striking them through. For instance:

```
## Ruby, <s>104</s> <s>101</s> 96 bytes

```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the *last* number in the header:

```
## Perl, 43 + 2 (-p flag) = 45 bytes

```

You can also make the language name a link which will then show up in the snippet:

```
## [><>](http://esolangs.org/wiki/Fish), 121 bytes

```

```
var QUESTION_ID=65020,OVERRIDE_USER=44713;function answersUrl(e){return"//api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"//api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
```

```
body{text-align:left!important}#answer-list,#language-list{padding:10px;float:left}table thead{font-weight:700}table td{padding:5px}
```

```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
```

# Answer
> 55 votes
# Minecraft 1.8.7, 7 + 8 = 15 blytes (bytes + blocks)

Only one command block involved:

```
xp 1 @p
```

Output goes to the client console like so:

As part of the normal output.

This is the system:

`xp` gives a specified amount of experience to a specified player with the syntax `xp <amount> <player>`. I'm pretty sure this is the smallest command that has singular output that I can get, now.

# Answer
> 19 votes
# JavaScript, 32 bytes

```
setInterval("alert(Date())",1e3)

```

Uses the fact that setInterval evaluates code. This is not recommended, but when was that a concern in code golf?

`Date()` returns the current time and date in a format like this (may vary per system).

```
 Wed Jul 28 1993 14:39:07 GMT-0600 (PDT)

```

# Answer
> 16 votes
# Snap, ~~8~~ ~~7~~ 6 blocks

(source: cubeupload.com)
(Yes, I changed it in MS Paint because I was too lazy to make another screenshot. So what? At least it's readable.)
click the script to run
24-hour clock.

# Answer
> 16 votes
## sh (+ watch), 11 bytes

Script:

```
watch -n1 .

```

(no trailing newline)

Output:

```
Every 1,0s: . (SPACES) Sat Nov 28 19:07:51 2015

```

The amount of spaces depends on the terminal width.

Tested on Debian8 and NetBSD7.

# Answer
> 11 votes
## Python 2, 47 bytes

```
from time import*
while[sleep(1)]:print ctime()

```

No online link because ideone times out (huehuehue) before printing anything.

Thanks to @xsot for the `while[sleep(1)]` trick and the `ctime` trick.

Prints out the current date and time like so: `Fri Nov 27 21:23:02 2015`

# Answer
> 9 votes
# Javascript ES6, 43 39 bytes

```
setInterval(_=>console.log(Date()),1e3)

```

Works with my current time settings (which have not been changed for some time, thank you), at least.

4 bytes saved by Conor O'Brien.

# Answer
> 8 votes
# Perl, Command Line, 24 bytes

```
sleep(say)while$_=gmtime

```

This must be run from the command line, as `perl -E'sleep(say)while$_=gmtime'` (on windows, use double quotes instead). The date will be output along with the time, which seems to be allowed.

---

## Perl, 25 bytes

```
sleep print$/.gmtime;do$0

```

In a scalar context, `gmtime` will return a string similar to `Sat Nov 28 10:23:05 2015`. The result from `print`, always 1, is used as the parameter for `sleep`. `do$0` is used to execute the script again, after the timer has finished.

# Answer
> 8 votes
# Arcyóu, 27 bytes

```
(@ t(pn(zz 1)(p(st %H:%M:%S

```

I had to kludge together two new functions for this challenge, `zz` and `st`.

`pn`: Exactly like Lisp's `progn`.

`zz`: Direct link to Python's `time.sleep`.

`st`: Direct link to Python's `time.strftime`.

Normally, quotes would be necessary around the format string, but since there are no spaces, it's parsed as a symbol. The interpreter evaluates undefined symbols as themselves, so we get a string.

# Answer
> 7 votes
# Bash, ~~51~~ ~~31~~ ~~24~~ ~~21~~  20 bytes

Thanks to @quartata for some very helpful comments. Thank you @Dennis for clarifications and for chopping off even more bytes. Thank you @VoteToClose for clarifying the rules (which apparently I am bad at reading) further reducing the bytes.

`date`  displays the the full date with a 24 hour clock. `sleep 1` sleeps for a second. `exec $0` loops the script infinitely.

```
date;sleep 1;exec $0

```

# Answer
> 6 votes
# Befunge 98, 53 bytes

```
 v
v>"EMIT"4(>H.8,':,M.8,':,S:.8,d,
>:S-    !!k^

```

Notes:

1. This program does not zero-pad the numbers it prints.
2. This program prints a space and then a backspace character after every number, as the `.` command prints an implicit space at the end.
3. The size of the stack in this program grows every second, and thus it will eventually run out of memory.
4. This program will overwrite the previous time when it prints a new one. To make it print each time on a new line, change the `d` on the first line to an `a`

# Answer
> 6 votes
## mIRC 7.49 ~~20~~ 16 Bytes

```
/timer 0 1 $time

```

# Answer
> 5 votes
# PHP, 37 bytes

```
<?=date('G:i:s');header('refresh:1');

```

Outputs the formatted server time and sets the page to refresh every second.

Of course, it depends on your internet connection and how fast-repsonding your server is :)

Demo

# Answer
> 5 votes
# Jolf, ~~14~~ ~~8~~ 7 bytes

Crossed out 14 is a striked 1? Naw, it will never catch on ;)

Try it here! Click run, do not click on anything else ^\_^ the page is highly... explosive. Yes. Fixed output system with update.

```
TaD#`~2

```

(I added some constants, and `~1` to `~4` are powers of `10`.)

## Explanation

```
setInterval("alert(Date())",1000);
     T         a      D#   ` ~2

```

# Answer
> 5 votes
## AutoHotkey, 50 bytes

```
x::Send,% a!=A_Sec? A_Hour ":" A_Min ":" a:=A_Sec:

```

Notes:

1. Requires you to hold `x` for continuous output.
2. Remove your finger from `x` to interrupt and end the output.
3. Output is in 24-hour format.

# Answer
> 5 votes
# C (on Linux x64), ~~179~~ ~~177~~ ~~175~~ ~~168~~ 159 bytes

```
#include<time.h>
#include<sys/time.h>
main(){struct timeval a;char b[9];for(;;){gettimeofday(&a,0);strftime(b,9,"%T",localtime(&a.tv_sec));puts(b);sleep(1);}}

```

Ungolfed:

```
#include <time.h>
#include <sys/time.h>
main(){
  struct timeval a;
  char b[9];
  for(;;){
    gettimeofday(&a, 0);
    strftime(b, 9, "%T",localtime(&a.tv_sec));
    puts(b);
    sleep(1);
  }
}

```

Only tested on, and likely only functions on, linux x64 (x32 might work, but other platforms probably won't).

The main difference between this program and the other posted C program is the use of linux-exclusive function calls, which, while terrible practice for real software, saves quite a few bytes...if you ignore all the compiler warnings.

# Answer
> 5 votes
# Dyalog APL, ~~27 18~~ 16 bytes

```
':',¨⎕TS⋄→≢⎕DL 1

```

Try it online!

`⎕TS` Y M D h m s t
`':',¨` prepend : to each
new statement
`⎕DL 1` wait a second and return actual waited time; 1.0something seconds
tally the actual waited time, giving 1
go to line (1 = this line)

# Answer
> 4 votes
## Powershell, 19 bytes

```
for(){date;sleep 1}

```

# Answer
> 4 votes
## Perl 6, 29 bytes

The *right* way to do this:

```
Supply.interval(1).tap: -> $ {
  say join ':',.hour,.minute,.whole-second given DateTime.now
}
await Promise.new; # halt this thread indefinitely

```

```
22:21:58
22:21:59
22:22:0
22:22:1
22:22:2
…

```

The golfed version

```
loop {sleep say join ':',now.polymod(1,60,60,24)[3…1]} # 56 bytes

```

```
3:59:26
3:59:27
3:59:28
3:59:29
…

```

Since the output doesn't have to be restricted to just the time, I can make it quite a bit shorter.

```
loop {sleep say DateTime.now} # 29 bytes

```

```
2015-11-27T22:18:10-06:00
2015-11-27T22:18:11-06:00
2015-11-27T22:18:12-06:00
2015-11-27T22:18:13-06:00
…

```

# Answer
> 4 votes
## R, 38 bytes

```
repeat{Sys.sleep(1);print(Sys.time())}

```

This outputs the current time in the following format:

```
[1] "2015-11-28 07:34:01 CET"

```

# Answer
> 4 votes
# VBA, 69 Bytes

Getting the Time is easy, `now()` Only outputting every 1 second.... MUCH more verbose.

This is the "Right" way of waiting 1 second in VBA. ***78 Bytes***

```
Sub a():Debug.Print Now():Application.Wait Now()+TimeValue("0:0:1"):a:End Sub

```

Or if you want to Cut some Corners and only being right 86% of the time is good enough ***63 Bytes***
*adding one SigFig take you to 95% accurate and a third will get you to 99.36%*

```
Sub a():Debug.Print Now():Application.Wait Now()+1e-5:a:End Sub

```

If you want to get the above method to 100% then you need ***69 Bytes*** `(1/86400)`

```
Sub a():Debug.Print Now():Application.Wait Now()+(1/86400):a:End Sub

```

All of these methods would stumble on a leap second Beacuse they do not wait for 1 second, But wait untill 1 second. At midnight when the clocks fall back an hour this clock will stop for 1 hour and then pick up where it left off.

VBA does allow for the Sleep Method but your byte couter is Ruined. ***97 Bytes***

```
Declare Sub Sleep Lib "kernel32" (ByVal k as Long)
Sub a():Debug.Print Now():Sleep(1e3):a:End Sub

```

# Answer
> 3 votes
# AppleScript, ~~51~~ 35 bytes

```
repeat
log current date
delay 1
end
```

Pretty dang obvious. Prints the current date, which contains the time, delays a second, then continues.

# Answer
> 3 votes
## Perl, 99 81 75 51 40 36 29 27 bytes

```
sleep(print gmtime.$/);do$0

```

# Answer
> 3 votes
# JavaScript, ~~47~~ ~~38~~ 35 bytes

```
for(p=1;t=Date();p=t)t!=p&&alert(t)

```

## Explanation

Continuously checks if the time has changed then `alert`s if it has.

```
for(
  p=1;
  t=Date();
  p=t
)
  t!=p
    &&alert(t)

```

# Answer
> 3 votes
# Java, ~~300~~ ~~166~~ ~~137~~ ~~125~~ 124 bytes

~~Nearly~~ More than halved thanks to VoteToClose, Paülo Ebermann and janschweizer!

```
interface A{static void main(String[]a)throws Exception{for(;;Thread.sleep(1000))System.out.println(new java.util.Date());}}

```

Ungolfed:

```
interface A {
    static void main(String[] a) throws Exception {
        for (;; Thread.sleep(1000)) System.out.println(new java.util.Date());
    }
}
```

# Answer
> 3 votes
# Japt, 8 bytes

**Japt** is a shortened version of **Ja**vaScri**pt**.

```
1e3i@OpÐ

```

Test it online!

### How it works

```
1e3i@       // Repeat this function every 1e3 milliseconds:
     OpÐ    //  Output new Date(), followed by a newline.

```

Note that this also outputs a seemingly random integer when the code is run. To get rid of this, use this code:

```
1e3i@OpÐ};P

```

On my computer, the time is formatted as `2015-11-28T16:00:18.013Z`. If you don't like that, try this code instead:

```
1e3i@OpÐ s8};P

```

Which will lovingly print your time in the format `11:00:18 AM`.

# Answer
> 3 votes
# Haskell, ~~98~~ ~~96~~ 85 bytes

```
import GHC.Conc
import Data.Time
m@main=getCurrentTime>>=print>>threadDelay(10^6)>>m

```

Alternate version using do notation:

```
main = do
  time <- getCurrentTime
  print time
  threadDelay 1000000
  main

```

Gets the current time with `getCurrentTime` from the `Data.Time` library, then pipes it into `print`, waits 1,000,000 microseconds (1 second) and calls itself.

Thanks to nimi and Mauris!

# Answer
> 3 votes
# Batch - 34 ~~40~~ bytes

I love built-in variables:

```
:A                    //Set label A
echo %time%           //Print the time in 24 hour format
timeout 1    //Wait 1 second (thanks DavidPostill)
goto A                //Jump back to A and repeat

```

There definitely needs to be some `sleep` command in Batch anytime soon.

# Answer
> 3 votes
# , 13 chars / 25 bytes

```
Ĥ⇀ôᶁ⬮+⬬),1)

```

`Try it here(Firefox only).`

This is surprisingly readable.

# Answer
> 3 votes
# Dyalog APL, 36 bytes

Not very short this time.

```
{⎕←1↓∊'⊂:⊃,ZI2'⎕FMT 3↑3↓⎕TS⋄∇⎕DL 1}1

```

This outputs 24-hour time, i.e.:

```
14:37:44
14:37:45
14:37:46
...

```

Explanation:

* `{`...`}1`: define a function and call it (the argument is ignored, but we need the function in order to call it recursively)
    + `⎕TS`: a system function that returns the current date and time, in the format *year - month - day - hour - minute - second - millisecond*. (`⎕TS` = **t**ime**s**tamp)
    + `3↑3↓`: drop the first 3 items (i.e. year - month - day) and then take the first 3 items that are left (hour - minute - second).
    + `'⊂:⊃,ZI2'⎕FMT`: format each number as a two-digit integer (`I2`) with leading zeroes (`Z`), prefixed by a colon (`⊂:⊃`). (This results in a matrix.)
    + : Get all the elements in the matrix, in row order. (This gives a vector, in this case a string.)
    + `1↓`: drop the first character (which is an extra `:`)
    + `⎕←`: output it
    + `⎕DL 1`: then wait one second (`⎕DL` = **d**e**l**ay)
    + : call the function recursively

# Answer
> 3 votes
# QBasic, 18 bytes

```
?TIME$
SLEEP 1
RUN

```

# Answer
> 3 votes
## Python 3, 99 Bytes

Apologies if it formats the code weird, doing this from an ipad. (dont ask). I know this code is big considering some of the other answers, but I didn't see a python one yet so I wanted to add it in.

```
import time
import datetime
while(True):
 print(datetime.datetime.now().time())
 time.sleep(1)

```

# Answer
> 3 votes
## Pure bash, ~~116 113~~ 96 bytes

Using bash version \>= 5.0, there is a new `EPOCHREALTIME` variable:

```
for((;;)){
IFS=. read s m<<<$EPOCHREALTIME
printf '%(%c)T\n'
sleep .$[(3000000-10#$m)%1000000]
}

```

This will output something like:

```
mar 03 jan 2023 10:28:27
mar 03 jan 2023 10:28:28
mar 03 jan 2023 10:28:29
...

```

**Note:** In order to save 3 byte, I've done something to not do: mixing `time()` (`printf '%()T'`) and `gettimeofday()` (`$EPOCHREALTIME`). See: *WARNING! About mixing $EPOCHSECONDS and $EPOCHREALTIME* (better line 3 would be: `printf '%(%c)T.%s\n' $s`)!!

## With a little more precision:

```
for((;;)){
IFS=. read s m<<<$EPOCHREALTIME
printf '%(%c)T.%s\n' $s $m
read -rn1 -t .$[(3000000-10#$m)%1000000] _
}

```

Will output something like:

```
mar 03 jan 2023 10:52:44.183297
mar 03 jan 2023 10:52:45.000324
mar 03 jan 2023 10:52:46.000424
mar 03 jan 2023 10:52:47.000300
mar 03 jan 2023 10:52:48.000341
...

```

# Answer
> 3 votes
## K, 25 24 Bytes

Removed semicolon from the end of the func!

```
      .z.ts:{-1@$18h$x}
      \t 1000
  13:11:44
  13:11:45
  13:11:46
  13:11:47
  13:11:48
  ...

.z.ts is called every 1000 milliseconds.
x is the time.
18$x casts the time to the appropriate format.
$ - strings the result.
-1@(stringed result) - prints the string to the console.

```

\*Edit Below is less but I wasn't sure whether the time format was allowed;

```
    .z.ts:{-1($x)}
    \t 1000
2016.08.01D00:35:37.392683000

```

# Answer
> 2 votes
# Pyth, ~~19~~ 16 bytes

It takes the relevant part of the datetime list and joins by colons. Then it passes till the second changes, with the entire thang wrapped in an infinite loop.

```
#j\:KP.d2WqeK.d8

```

While it obviously doesn't work online, you can check its main idea here.

# Answer
> 2 votes
## Mathematica, ~~41~~ 36 bytes

```
While[1>0,Echo@DateString[];Pause@1]

```

Works as a script.

# Answer
> 2 votes
# Matlab, ~~50~~ 42 bytes

```
while 1;pause(1);disp(datestr(now,13));end

```

# Answer
> 2 votes
# C/C++, 219 Bytes

Here is a first pass attempt. It is written in C++ but uses only C functionalities, so it could be used as C code with only changes to the include statements (I think).

```
#include<stdio.h>
#include<ctime>
time_t r;struct tm*x;int main(){char c[9],b[9];time(&r);x=localtime(&r);strftime(c,9,"%T",x);puts(c);for(;;){time(&r);x=localtime(&r);strftime(b,9,"%T",x);if(b[7]!=c[7]){break;} }main();}

```

I think everything is pretty straightforward. It takes the time at the beginning of the main function, then it continues getting time until one second has passed. It then calls itself.

Ungolfed:

```
#include<stdio.h>
#include<ctime>
time_t r;struct tm*x;
int main(){
    char c[9];char b[9];
    time(&r);
    x=localtime(&r);
    strftime(c,9,"%T",x);
    puts(c);
    for(;;){
        time(&r);
        x=localtime(&r);
        strftime(b,9,"%T",x);
        if(b[7]!=c[7]){break;} // break when the 'second' changes
    }
    main();
}

```

# Answer
> 2 votes
# Ruby, ~~25~~ 24 bytes

*Thanks @manatwork for golfing off a byte :P*

```
loop{puts`date;sleep 1`}

```

Not bad.

# Answer
> 2 votes
# Vimscript, 44 bytes

```
while 1
echo strftime("%T")
sleep 1
endwhile

```

Run like so:

```
vim -c ":so FILE"

```

# Answer
> 2 votes
# PHP, 33 bytes

```
<?for(;;)sleep(print date("r
"));

```

Output is similar to `Sat, 28 Nov 2015 11:25:16 +0700`, i.e. RFC 2822.

# Answer
> 2 votes
# Go, ~~64~~ ~~69~~ 79 bytes

Go isn't very golfy.

```
package main;import(."fmt";."time");func main(){for{Println(Now());Sleep(1e9)}}

```

You *could* try it here or on another online interpreter however, `for{}` is an infinite loop and those are disallowed for obvious reasons. ~~I haven't actually tested thisthere are no go interpreters for my android ): but it should work in theory.~~

Running it locally might cause your CPU fan to speed up, but it won't hog memory. If it crashes with some sort of OOM-error or `panic: runtime out of bound`, just change it to `for x:=0;x<9999;x++{ ... }`.

# Answer
> 2 votes
# CJam, 21 bytes

```
L{et6<':*_@={_oNo}|}h

```

Try it online! Note that the online interpreter will kill the program after one minute.

Same idea, but with pretty output:

```
L{et6<3>"%02d:"fe%sW<_@={_oNo}|}h

```

Try it online!

# Answer
> 2 votes
# SpecBAS - 45 bytes

Prints in the upper left corner for a continuously updating 24 hour clock. Pressing Esc stops it running.

```
1 TEXT AT 0,0;TIME$(TIME,"hh:mm:ss"): GO TO 1

```

# Answer
> 2 votes
## Ceylon, ~~126~~ 112 bytes

`import ceylon.time{now}void p(){for(e in{now().time().string[0:8]}.cycled.paired){if(e[0]!=e[1]){print(e[1]);}}}`

This uses the ceylon.time library for getting the current time (in the default timezone) and formatting it (the `.string` function for time outputs something like `22:33:45.234`, so I just take the first 8 characters of it).

Unfortunately, there seems to be no `sleep` function in Ceylon (because it is not easy to implement in JavaScript), therefore I'm doing a busy loop here, comparing each formatted string to the previous one and printing only when there is a change.

Here is a formatted version of the second version, which uses a for-loop over an infinite iterable:

```
// print the current time (each second).
//
// Question:  http://codegolf.stackexchange.com/q/65020/2338
// My answer: http://codegolf.stackexchange.com/a/65130/2338

import ceylon.time {
    now
}

void p() {
    for(e in { now().time().string[0:8] }.cycled.paired) {
        if(e[0]!=e[1]) {
            print(e[1]);
        }
    }
}

```

Using a `<` instead of `!=` would save a character, but then the program would stop working as soon as the clock hits midnight.

This was the original, more functional, version resulting in 112 characters:

```
import ceylon.time {
    now
}

void p() {
    { now().time().string[0:8] }
        .cycled
        .paired
        .map((e) => e[0] != e[1] then e[1])
        .coalesced
        .each(print);
}

```

# Answer
> 2 votes
## Processing, 68 bytes

```
void draw(){frameRate(1);println(hour()+":"+minute()+":"+second());}

```

Easy one I have to admit. In processing there is the `draw()` method which is called at a specific frequency that can be modified during the execution.

# Answer
> 2 votes
# Hassium, 43 Bytes

```
func main(){print(time())sleep(1000)main()}

```

See expanded here

# Answer
> 2 votes
## sh (+ top), 7 bytes

Script (Debian8):

```
top -d1

```

Script (NetBSD7):

```
top -s1

```

(both without trailing newline)

Output (1st line only, Debian8):

```
top - 16:25:15 up 3 days,  8:56,  4 users,  load average: 0,97, 1,10, 1,03

```

Output (1st line only, NetBSD7, different time zone):

```
load averages:  1.46,  1.28,  1.22; (SPACES) up 44+08:52:28 (SPACES) 15:22:06

```

The amount of spaces depends on the terminal width.

# Answer
> 2 votes
## C, ~~74~~ 73 bytes

```
#include<time.h>
main(){for(time_t t;!sleep(1);time(&t))puts(ctime(&t));}

```

The code can work even without `#include <stdio.h>` and `#include <unistd.h>`, see live code example on `ideone.com` -- note: the sleep is zero there, to generate some output before the time limit has been exceeded.

The first output line should be ignored (*"Extra output doesn't really matter, as long as the program at some point continuously outputs time."*).

# Answer
> 2 votes
## Python 3, 48 bytes

```
from time import*
while[sleep(1)]:print(ctime())

```

It is a @Mego's Python 2 solution tweaked to work on Python 3.
Here's Jupyter notebook to see the results and try it.

# Answer
> 2 votes
# PureBasic, ~~64~~ 59 bytes

Not much to say, infinite loop, output time to the debug window with a 1000 millisecond delay

```
a:
Debug FormatDate("%hh:%ii:%ss",Date())
Delay(1e3)
Goto a

```

# Answer
> 2 votes
# Prolog (SWI), 72 bytes

Formating to user\_output stops working when using sleep, so I had to save the time to a variable and print it explicitly.

**Code:**

```
p:-repeat,get_time(T),format_time(atom(X),'%T',T),write(X),sleep(1),1=0.

```

**Explained:**

```
p:-repeat,                      % loop until success
   get_time(T),                 % Get current timestamp
   format_time(atom(X),'%T',T), % Format timestamp as HH:mm:ss
   write(X),                    % Print time
   sleep(1),                    % Sleep 1 second
   1=0.                         % Fail and go back to repeat

```

# Answer
> 2 votes
# Vitsy \+ bash, ~~13~~ 11 bytes

This language feature was made after this question, but not for this question.

```
<w1Z,'date'
<           Loop leftwards in the code.
            Rest of code is written in reverse for "readability".
 'etad'     Push 'date' to the stack.
       ,    Do the shell script for what's in the stack.
        Z   Output the result.
         1w Wait a second.

```

Or, using eval...

```
<w1Zn"Date()"
<             Go leftwards through this code in order to loop infinitely.

              Rest of code is written in reverse for "readability".

 ")(etaD"     Push "Date()" to the stack.
         n    Eval through JS.
          Z   Output everything.
           1w Delay for one second.

```

Try it online!

# Answer
> 2 votes
## QBasic, 16 bytes

Shamelessly stole (and imporoved upon) Mauris' design:

```
CLS:?TIME$:RUN

```

---

Previous version: 24 bytes

EDIT: Only just saw that I don't have to SLEEP 1 if I continuously clear the screen and print the time. That's 4 bytes shorter:

```
DO:CLS:PRINT TIME$:LOOP

```

---

Previous entry (28 bytes)

```
DO:PRINT TIME$:SLEEP 1:LOOP

```

Nothing fancy, not too shabby.

# Answer
> 2 votes
# Mouse-2002, 84 bytes

Mouse is cool, but it's not the golfiest stack based language on the planet (well, not until I update it in a reimplementation -- then it will be better.)

```
0&FIX 2&WIDTH "!"(&HOUR &!DEC ":"&MIN &!DEC ":"&SEC &!DEC 8!'8!'8!'8!'8!'8!'8!'8!')$

```

The `8!'` prints the character with ASCII code 8, or `backspace`. You probably need an ANSI terminal to run this; it updates in place by backspacing over itself and writing the new time once per second.

sample use:

```
$ mouse clock2.mou

19:47:34

```

Based on this, but golfed.

# Answer
> 2 votes
# Python 2, 85 bytes

```
import time;while 1:print __import__('datetime').datetime.now().time();time.sleep(1)

```

`import time;time.sleep()` has 2 fewer bytes than `__import__('time').sleep()`, while `import datetime;datetime.datetime.now()` has 2 more bytes than `__import__('datetime').datetime.now()`.

# Answer
> 2 votes
# Emacs Lisp, 83 bytes

```
(run-with-timer 1 1(lambda()(message(format-time-string"%H:%M:%S"(current-time)))))

```

# Answer
> 2 votes
## bash, 35 bytes

Just for kicks

```
yes|mapfile -tc1 -C'date;sleep 1 #'

```

Also 35,

```
x='x[`date>&2;sleep 1`${!x}]'<${!x}

```

I think it's unlikely there's anything shorter than `exec $0`.

# Answer
> 2 votes
## Groovy, ~~40~~ 37 bytes

Not very golfable :(, thanks to FlagAsSpam for for(;;) :)

```
for(;;){print(new Date());sleep 1000}

```

# Answer
> 2 votes
## Lua, 56 bytes

Lua is pretty hard to golf...

```
v=1
while 1 do v=os.date'%c' l=v~=l and print(v)or v end

```

There are few online interpreters that allow infinite loops; one of the few I've found is this one. This repeatedly converts the current system time to a date-time string and outputs that string when it's different from the last.

Ungolfed:

```
current = 1
while 1 do
    current = os.date('%c')
    last = current ~= last and print(current) or current
end

```

# Answer
> 2 votes
# MATL, 11 bytes

```
`Z'0XOD1Y.T

```

**Try it here**.

### Explanation

```
`         % do...while loop
  Z'      %   get current date and time
  0XO     %   string representation of date and time, with format 'dd-mmm-yyyy HH:MM:SS'
  D       %   convert to string and display
  1Y.     %   pause for 1 second
  T       %   push "true" value as loop condition to create infinite loop
          % implicitly end loop

```

# Answer
> 2 votes
# Perl 6, ~~34~~ 30 bytes

Perl 6 is looooong, but I like it. Yes, all the whitespace is needed.

```
sleep 1 while say DateTime.now

```

Hooray for postfix syntax!

# Answer
> 2 votes
## F#, ~~101~~ 98 bytes

```
open System;while 1=1 do(DateTime.Now.ToString"HH:MM:ss"|>printfn"%s";Threading.Thread.Sleep 1000)

```

Pretty straightforward: print the current time in the correct format, wait a second, then repeat. Forever.

Credit to @VoteToClose and @RikerW for the help.

# Answer
> 2 votes
# Rebol, 25 bytes

```
forever[print now wait 1]

```

This prints day & time (24 hour HH:MM:SS). For an extra 5 bytes you can make it print just the time: `forever[print now/time wait 1]`

# Answer
> 2 votes
# Batch (Windows), 21 bytes

## t.bat

```
echo %time%
timeout 1
t

```

Shows the time, delays for 1 second, then recursively calls itself. This is run as `t.bat` in the same directory.

# Answer
> 2 votes
# Pascal, 144 B

This `program` requires a processor complying to the ISO standard 10206 “Extended Pascal”, e. g. the GNU Pascal Compiler (GPC). It’s doing a busy wait until the time changes. *The second* line of the entire output will probably be printed in significantly less than a 1 second interval.

```
program t(output);var t:timeStamp;s:string(8);begin s:='';repeat getTimeStamp(t);if s<>time(t)then begin s:=time(t);writeLn(s)end until 6=9 end.

```

The code does not check `timeStamp.timeValid`, so on a system *without a clock* this program will print just a single line representing midnight, `getTimeStamp`’s default value if `timeStamp.timeValid` is set to `false`.

The return value of `time` is **implementation-defined**. It may be in an AM/PM format, military time, or something else. Thus it’s not guaranteed that the challenge’s specifications are met. At any rate, *the GPC’s* implementation returns something in the style of `22:00:42`. This fits into a `string(8)`. A different Pascal implementation may require more characters in order to detect a change in time.

Also, if you don’t mind a *preceding* empty line, you can use this **134 B** `program`:

```
program t(output);var x:timeStamp;s:string(8);begin s:='';repeat getTimeStamp(x);if s<>time(x)then writeLn(s);s:=time(x)until 6=9 end.

```

# Answer
> 1 votes
## TI-BASIC, 29 bytes

```
While 1
Output(1,1,getTimeStr(24)+":
Output(1,7,sum(getTime,3
End

```

TI-BASIC has a built-in `getTimeStr`, but it doesn't display seconds! How to fix this? Just display the seconds over the empty space after the minutes. (It would be much easier if there were a way to convert numbers to strings.)

Outputs in 24-hour mode.

# Answer
> 1 votes
# C#, ~~129~~ 125 bytes

```
using System;using System.Threading;class P{static void Main(){for(;;){Console.WriteLine(DateTime.Now);Thread.Sleep(1000);}}}

```

Ungolfed:

```
using System;
using System.Threading;

class Program
{
    static void Main()
    {
        for (;;)
        {
            Console.WriteLine(DateTime.Now);
            Thread.Sleep(1000);
        }
    }
}
```

# Answer
> 1 votes
# PHP, 24 bytes

```
for(;;)echo date("\rr");

```

`\r` clears the current line before printing the date/time using the `r` flag. Therefor it doesn't have to wait or delay the output for a second. Also the cursor is always positioned behind the output, which would be different for `r\r` where it would overlay the first character of the output.

# Answer
> 1 votes
# AppleScript, ~~112~~ ~~93~~ 45 bytes

```
repeat
delay 1
log(do shell script"date")
end
```

This repeats in a loop, does the bash script `date`, gets its returned string, and outputs it to the `Messages` pane. Why I didn't do this at first, I'll never know.

### Using Node:

Let's have a ~~odd~~ useless combination, shall we?

This was inspired by my Vitsy answer, which also uses JS to get the date.

```
tell app"System Events"
tell app"Terminal"to activate
keystroke"node
"
repeat
delay 1
keystroke"Date()
"
end
end
```

What I do here is I tell the System Events application to get terminal as the front window, then enter `node` with the terminal by telling System Events to simulate keystrokes of `n`, `o`, `d`, `e`, followed by a newline. It then enters a loop in which it delays for a second, tells node to do `Date()` by the same method, then going back to the top of the loop.

This answer is mostly to demonstrate the odd things that Applescript allows you to do.

# Answer
> 1 votes
# Unix Shell + procps, 12 bytes

`procps` is a package providing CLI utils for browsing `procfs`, a virtual filesystem generated by the kernel to provide information about processes.

The `watch` command reruns a command every on an interval, that defaults to `2`. Set it to `1`, and run `.`, and voilá, `watch` suppresses stderr.

```
watch -n1 .

```

The time is in the upper right.

---

incidentally, `watch` is very handy for spying on the progress of a lengthy `dd` or `cp`.

# Answer
> 1 votes
# Jelly, 8 bytes

```
7ŒTṄœS1ß

```

Try it online!

### How it works

```
7ŒTṄœS1ß  Main link. No arguments.

7         Yield 7 (or 111 in binary).
 ŒT       Time; return hours, minutes and seconds (lower three bits).
   Ṅ      Print, followed by a linefeed.
      1   Yield 1.
    œS    Sleep for 1 second, return the time.
       ß  Call the main link recursively.

```

# Answer
> 1 votes
# Factor, 43 bytes

```
[ [ t ] [ now "%c" strftime print ] while ]

```

An anoymous function. Use it like `~quotation~ call`.

# Answer
> 1 votes
# Pylongolf, 11 bytes

```
>}~.1000w.<

```

`}~` pushes the current time into the stack and then prints it.
`.` the dots reset the stack.
`1000w` pushes 1000 into the stack and then waits that time.

# Answer
> 1 votes
# Python, 53 bytes

This one prints the date and year as well as the time, so I don't know if it's allowed.

```
import time
while 1:print(time.ctime());time.sleep(1)

```

EDIT: J.F.Sebastian made a shorter one.

# Answer
> 1 votes
# Tellurium, 8 bytes

```
[i|t^¨]

```

The code that is after the `|` and before the `]` is run forever (`i`).

It changes the value of the current cell to the current time (`t`), outputs the current cell's value using `^`, and waits for 1 second (`¨`) before continuing.

# Answer
> 1 votes
# Scratch, 15 bytes

(scoring used)
This script is essentially what it says. It joins the hour value, then a colon, then the minute value, then a colon, then the second value. The downside is that Scratch reads 01 as 1, so it might not be valid without making the script longer.

# Answer
> 1 votes
# Mathematica, ~~27~~ 21 bytes

With 2 bytes saved thanks to Xavier.

```
Dynamic@{Now,Clock[]}

```

# Answer
> 1 votes
## Lua, 51 Bytes

Since the previous owner of this answer in 56 Bytes doesn't update anymore when suggested improvments, here's a 51 Bytes solution heavily based on his:

```
v=1::a::v=os.date'%c'l=v~=l and print(v)or v goto a

```

# Answer
> 1 votes
# Nim, ~~55~~ 54 bytes

```
import os,times
while on:echo getClockStr();sleep 1000

```

`on` is an alias for `true`. Prints the result of the `times` module's `getClockStr` proc, which formats the time nicely in 24-hour format, then uses the `os` module's `sleep` proc to sleep a second.

# Answer
> 1 votes
# C#, 102 bytes

```
using System;class P{static void Main(){for(var s="";;)if(s!=(s=DateTime.Now+"\n"))Console.Write(s);}}

```

An infinite loop that prints whenever the time changes. Default precision for C# date printing is to the second, so that works out nicely.

# Answer
> 1 votes
# Fourier, ~~46~~ 20 bytes

This is a fairly simple program which loops infinitely, using the newly added **date functions**, **delay function** and **clear screen function**.

This does not show a leading zero on the minutes or the seconds value when either are less than ten.

```
(@2do58a1do58a0do1;)

```

**Try it online!**

***Note:* this program will not work on http://fourier.tryitonline.net due to differences in the way interpreters work.**

# Answer
> 1 votes
# tcl, 67

```
while 1 {puts [clock format [clock seconds] -format %T];after 1000}

```

can be tested on: http://www.tutorialspoint.com/execute\_tcl\_online.php?PID=0Bw\_CjBb95KQMUkViT2lXWDlLYlE

# Answer
> 1 votes
## Clojure, 140 bytes

```
(loop[l 0](let[c(System/nanoTime)](recur(if(>=(- c l)1e3)(do(println(.format(java.text.SimpleDateFormat."h:m:s a")(java.util.Date.)))c)l))))

```

Full program. Loops continually; keeping track of the last time it printed. If 1000ms have passed, it prints, then resets the time.

Java interop really bloats this up, but not much can be done about that.

Ungolfed:

```
(defn current-time []
  (loop [last-ns 0]
    (let [current-time (System/nanoTime)]
      (recur
        (if (>= (- current-time last-ns) 1e3)
          (do
            (println (.format (java.text.SimpleDateFormat. "h:m:s a") (java.util.Date.)))
            current-time)
          last-ns)))))

```

## Using `sleep` (which seems to be of questionable validity), 100 bytes

```
(while[](Thread/sleep 1e3)(println(.format(java.text.SimpleDateFormat."h:m:s a")(java.util.Date.))))

```

Ungolfed:

```
(defn current-time []
  (while []
    (Thread/sleep 1e3)
    (println (.format (java.text.SimpleDateFormat. "h:m:s a") (java.util.Date.)))))

```

# Answer
> 1 votes
# QBIC, 6 bytes (nc)

```
{_C?_d

```

QBIC is newer than this challenge. In fact, this challenge is the reason QBIC has a `_C` command (for `CLS` \- Clear the screen) and the `_d/_D` commands (for `TIME$` and `DATE$` resp).

## Explanation

```
{        Start infinite loop
 _C      Clear screen
   ?     PRINT
    _d   TIME$ (which holds the system's time in QBasic)

```

# Answer
> 1 votes
# MOO, 46 bytes

```
while(!suspend(!player:tell(ctime())))endwhile

```

Sleeps for one second between outputs, regardless of execution time (and it's impossible to know sub-second timings anyway

# Answer
> 1 votes
# Factor, 29 bytes

```
[ now hh:mm:ss nl ] 1e9 every

```

Normally you'd give `every` a duration for more readability: `[ ... ] 1 seconds every` but if you just give it a number, it'll interpret it as nanoseconds.

# Answer
> 0 votes
# PHP, ~~36~~ 34 bytes

```
a:echo'
'.date(r);sleep(1);goto a;

```

The line break can be \n but it's nicer to convert the script to the old Macintosh line format and make it \r, then the time is neatly updated on the same line.

Updates:

1. Removed short open tag as per this meta answer

# Answer
> 0 votes
# 05AB1E, 13 bytes

```
[žažbžc)':ý,w

```

Should work, but I don't have Python 3, so I can't test.

# Answer
> 0 votes
# Elixir, 95 bytes

```
def f, do: 1000|>Stream.interval|>Enum.each(&(&1&&DateTime.utc_now|>DateTime.to_time|>IO.puts))

```

# Answer
> 0 votes
# \*\>\<\>, 16 bytes

```
'::'hnomnosnaoaS

```

000webhostapp interpreter.

Note: it sometimes skips a second (e.g. 12:34:6 → 12:34:8), because you can't wait *exactly a second* with total accuracy. Unfortunately there isn't any way to fix this.

# Answer
> 0 votes
# VBA, 50 Bytes

Anonymous VBE immediate window function that takes no input and outputs to the VBE immdiate window

```
Do:DoEvents:?Now:Application.Wait 1/864E2+Now:Loop

```

# Answer
> 0 votes
# Phooey, 39 bytes

```
[1@_1~t/1000@/60@/60%24[_1%60$i":"&]#1]

```

Try it online!

It's not pretty. It prints the time followed by another colon, with no newline in between.

In order to see the output you probably need to use `stdbuf -i0 -o0 -e0` to set it to unbuffered, as I don't print newlines. The output is always in UTC time.

Explanation:

```
[1            // While tape value is not 1 (it will either be 0 the first time or -1 the second)
  @_1         // Push sentinel of negative 1
  ~t          // tape = millis since epoch
  /1000       // Divide tape by 1000 to get seconds
  @           // Push tape value to save the seconds
  /60         // Divide by 60 to get minutes
  @           // Push tape to save minutes
  /60         // Divide by 60 to get hours
  %24         // Modulo by 24 to hour of the day
              // Stack: -1, seconds, minutes
              // Tape: hours
  [_1         // While tape is not -1 sentinel
     %60      //   modulo tape by 60 (redundant for hours)
     $i       //   print as number
     ":"      //   print separator
     &        //   Pop to tape
  ]           // Loop if tape == tape (nop condition)
  #1          // sleep 1 second
]             // End loop

```

Note: 2:58 PM EST = 18:58 UTC

Excuse the low quality, the attachment feature has a stupid requirement of 2 MB which is not easy for GIFs to reach...

# Answer
> 0 votes
# x86-16 DOS .COM executable (FreeDOS 1.3), 40 bytes

```
00000000: b4 2c cd 21 38 f3 74 f8 88 f3 88 e8 e8 07 00 91  .,.!8.t.........
00000010: e8 03 00 88 d8 56 d4 0a 05 30 30 86 c4 cd 29 88  .....V...00...).
00000020: e0 cd 29 b0 3a cd 29 c3                          ..).:.).

```

Assembly source code:

```
    ; NASM syntax
    [org 0x100]
start:
    ; Note: The first second may be a little off due to synchronizing to the time
.loop:
    ; Int 21:2C: get time
    ; Return:
    ;    CH = hour
    ;    CL = minute
    ;    DH = second
    ;    DL = 1/100 seconds
    mov   ah, 0x2C
    int   0x21
    ; If seconds is the same as before, try again.
    cmp   bl, dh
    jz    .loop
.loop.end:
    ; Save last seconds
    mov   bl, dh
    ; Print hours
    mov   al, ch
    call  print
    ; Print minutes
    ; mov al, cl
    xchg  ax, cx
    call  print
    ; print seconds
    mov al, bl
    ; Assume SI = 0x0100, push that as a return address
    ; and fall through to loop
    push  si

    ; Converts AL to 2 digit ASCII and prints, followed by :
print:
    ; AL = AL % 10
    ; AH = AL / 10
    aam   10
    ; Convert to ASCII
    add   ax, '00' ; 0x3030
    ; Byteswap to get tens in AL, save ones in AH
    xchg  al, ah
    ; Print tens with int 29h
    int   0x29
    ; Then ones
    mov   al, ah
    int   0x29
    ; Then colon
    mov   al, ':'
    int   0x29
    ; Return from function
    ret

```

Like my other answer it isn't pretty but it does the job. It prints a `:` between each time.

Output on FreeDOS 1.3 on QEMU

# Answer
> 0 votes
## HP‑41C series, 4 Bytes

This requires an HP‑41CX or an HP‑41C/CV with a time module plugged in.

```
CLKT    2 Bytes  select time-only display for CLOCK (default)
CLOCK   2 Bytes  displays clock, refreshes every second

```

NB: `CLOCK` is effectively `OFF` if the system flag 49 (“low battery”) is set.

---
Tags: code-golf, date
---