Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

To celebrate Rounded Pi Day, you must take advantage of today's date to make a program that takes in a circle's diameter and outputs its circumference by multiplying the diameter by 3.1416, where 3.1416 must be obtained using today's date.

Input 3
Output 9.4248

Does not take the date as input. You do not have to use all components of the date but the digits of pi must come from formatting a Date object or using a date object to obtain it. The answers so far look good.

Not sure what else to specify. All the answers so far meet what I was expecting.

My constraint was that you must use components of the date to come up with Pi. You can of course use the components, multiply by 0 then add 3.1416, but that's boring and wastes precious chars!

Shortest code wins!

share|improve this question
What's so special about 14/3/16? – Neil Mar 14 at 13:01
define using today's date. I could get the date as a number, divide by itself and multiply by a predefined constant for pi – Luis Mendo Mar 14 at 13:02
@Neil: Because 3/14/16 and 31/4/16 are not valid actual dates in D/M/Y format. There aren't 14 months, and April only has 30 days. I personally think we should wait until 6/28/32 (M/D/Y) or maybe 6/2/83 (D/M/Y), but that's a whole other holy war. – Darrel Hoffman Mar 14 at 14:38
@DarrelHoffman You're a Tau man I see. – jmasterx Mar 14 at 14:46
Sadly, its only PI day in the US cultural area. Europeans, with their silly lexigraphcially-sensible date ordering, don't get to have yearly PI days. Spare a sad thought for them, as you're eating your pi(e) today. – T.E.D. Mar 14 at 18:03

37 Answers 37

up vote 8 down vote accepted

05AB1E, 16 13 bytes


Try it online.

Unfortunately a bug with floats makes this a byte longer :/

Thanks to Adnan for golfing off 3 bytes.


žfžežg         push month day year
      ¦¦       slice off the first two chars from the year (2016 -> 16)
        J      join them together into a number
         *     multiply by input
          4°/  divide by 1e4
share|improve this answer
¦¦ instead of 2000- is three bytes shorter ;) – Adnan Mar 14 at 16:11
+1 žfžežg sounds like a nice Czech word :) – yo' Mar 15 at 9:02
In UTF-8, this totals 19 bytes. – OldBunny2800 Mar 16 at 21:21
@OldBunny2800 05AB1E uses CP1252 for encoding. – quartata Mar 16 at 21:21
Bug with floats? – CalculatorFeline Apr 7 at 5:18

C, 32 bytes

#define f(d)d*time(0)/464083315.

If losing a little more accuracy is fine, I can get it down to about 29 bytes being still accurate to 4 digits past the decimal (as of the time of this posting):

#define f(d)d*time(0)/46408e4
share|improve this answer
#include<time.h>? – cat Mar 14 at 15:08
Also, where's the executable code? this is just something for the preprocessor to copy/paste; a snippet. We like runnable implementations here. – cat Mar 14 at 15:09
@tac most C compilers do not require you to #include standard library headers. Including them manually is almost always a good idea, but omitting them makes code golfing in C a lot easier. – Josh Mar 14 at 15:21
@tac the answer behaves mostly the same as a function. Several answers on here are standalone functions as well. I don't see the point in providing a sample main function to demonstrate how to call this single argument macro. – Josh Mar 14 at 15:25
@tac I think the standard [code-golf] rules is that unless forbidden functions are ok. – Mindwin Mar 14 at 19:32

AppleScript, 122 120 bytes

set a to current date
(display dialog""default answer"")'s text returned*(month of a+day of a*.01+year of a*1e-4 mod.01)

Variable a

Variable a is a date object. I call all of my date information off of it.

Month, day, and year

The month, day, and year calls actually return an object that normally returns a string. To properly use it as a number, I have surrounded it on both sides with mathematical operations to automatically cast it to a number.


1e-4 is a byte shorter than .0001.


. acts as a separator to the AppleScript autocorrect. By using this, I can use modulo and still keep it a byte for myself.

No return statement/log

The last value calculated automatically is returned by the program. I output the number calculated via the return box.

And here's a gif of it running!

pi day gif

share|improve this answer
Forget Java, this has got to be the most verbose language – Downgoat Mar 15 at 14:52
@Downgoat I guess that it's supposed to be "readable like English" or something... we use it a bit at one of my jobs and I really dislike whenever I have to make changes to such scripts. – Chris Cirefice Mar 15 at 15:49
@ChrisCirefice Yeah, no - this language has some annoying pieces to it. i.e. volume system volume. – VTCAKAVSMoACE Mar 15 at 16:00

Mathematica + coreutils, 20 bytes

<<"!date +%m.%d%y"#&

Luckily, Mathematica interprets the output of an external command as an expression. In this case the output is a valid float, so that multiplication with the function argument # is implied.

share|improve this answer
That's a combination I didn't know existed. – CalculatorFeline Apr 5 at 7:07

Lua, 30 27 Bytes


Multiply the first command-line argument by the current date in format mm.ddyy, which is actually 03.1416.

share|improve this answer

Bash + bc, 25 20 bytes

date +%m.%d%y\*$1|bc

Thanks to manatwork for saving five bytes.


$ ./ 3
share|improve this answer
That here-string notation is so long: date +%m.%d%y\*$1|bc – manatwork Mar 14 at 14:28
@manatwork you are correct! I was playing around with the same myself but couldn't figure out how to combine it. Thanks! – andlrc Mar 14 at 14:31

PowerShell v2+, 46 28 25 bytes

$args[0]*(Date -F "M.dy")

Pretty straightforward. Takes input $args[0] and multiplies it by the date formatted as M.dy (the Get- is implied). Note that this may take a long time to run on v2 as it iterates possible substitutions for Date (e.g., checking your %PATH% environment variable, etc.) before settling on Get-Date.

share|improve this answer
Can you cut the space after -f? – briantist Mar 15 at 4:02
@briantist Sadly, not here. We're abusing PowerShell's pattern recognition, since the actual flag is -Format. With flags like this, you just need to be unambiguous (for example, if you had -Debug and -Delimiter as potential options, you would need at least three letters to differentiate). Removing the space means PowerShell tries to parse the flag -F"M.dy" but can't find an argument that matches, and so throws an error. – TimmyD Mar 15 at 12:23
ahhh I see it now. That's what I get for reading this on a train after a long day. I was interpreting it as the -f operator. Makes total sense now. – briantist Mar 15 at 13:27

GNU Awk, 23 characters


Sample run:

bash-4.3$ awk '$0*=strftime("%m.%d%y")' <<< 3
share|improve this answer

R 3.2.4, 55 51 47 bytes

edit I realized I could use scan thanks @FryAmTheEggMan. Reduced 4 bytes thanks to @MickyT.


First attempt at a golf. Happy pi day!

share|improve this answer
Welcome to PPCG :) I'm no R programmer, but you don't need to supply a named function, just an expression that evaluates to a function. So I'm pretty sure you can drop the f=. – FryAmTheEggman Mar 14 at 16:11
You can go even further and do scan()*as.numeric(format(Sys.Date(),'%m.%d%y')) – MickyT Mar 14 at 16:17
as.double instead of as.numeric saves an additional byte – Flounderer Mar 15 at 4:09

Pyth, 19 bytes


Try it here!
Only works at 2016-03-14 of course.


*Qvs[.d4\..d5>2`.d3   # Q = input

     .d4              # current month
        \.            # dot between month and day
          .d5         # current day of the month
             >2`.d3   # last 2 digits of the year
   s[                 # concat everything into a string
  v                   # eval -> convert to float
*Q                    # multiply with input to get the circumference
share|improve this answer

PHP, 45 26 25 24 bytes

Uses Windows-1252 encoding


Run like this:

echo '<?=$argv[1]*date(~‘Ñ•†);' | php -- 3
  • Saved 19 bytes by using date() instead of DateTime::format
  • Saved a byte by using the echo tag
  • Saved a byte by using ISO-8859 encoding and negating the format string, so no need for double quotes. Might mess up your terminal a bit when running it from CLI, but works.
share|improve this answer
If you assume register_globals to true, you can use $n via /?n=3 in the url. – Martijn Mar 15 at 9:23
@Martijn That requires PHP 4.1 or setting it using the php.ini file. aross said before that wants to steer away from such method. – Ismael Miguel Mar 15 at 9:28

Python 2, 58 chars

import time
print float(time.strftime("%m.%d%y"))*input()

Try it!


import time                                   # Import time time module
print                                         # Print the following
      float(                                  # Cast to float
            time.strftime("%m.%d%y"))         # Format the time as MM.DDYY
                                     *input() # Multiply by input
share|improve this answer

JavaScript, 41 39 characters

This uses a proprietary Firefox-only method.

d=>new Date().toLocaleFormat`%m.%d%y`*d

Thanks to:

  • Ismael Miguel for the template string suggestion (-2 characters).

Sample run (Firefox Web Console):

> (d=>new Date().toLocaleFormat`%m.%d%y`*d)(3)

Note: this will fail in Firebug Console. Seems that Firebug performs some expansion on the template string, transforming `%m.%d%y` into `%__fb_scopedVars(m).d%y` before passing it to the code.

share|improve this answer
-2 bytes: d=>new Date().toLocaleFormat`%m.%d%y`*d – Ismael Miguel Mar 15 at 9:29
Oh. [facepalm] No idea why, I usually forget that trick. Although I use the template strings regularly. – manatwork Mar 15 at 9:33
I know. I really don't get either. What I'm trying to get is a way to remove that new from there. – Ismael Miguel Mar 15 at 9:35
I tried it on Firefox and it worked fine. I copy-pasted from the console. Since I've replaced ('...') with 2 backticks, that's 2 bytes. – Ismael Miguel Mar 15 at 9:41

Ruby, 40 bytes

share|improve this answer

Mathematica, 54

share|improve this answer

Vitsy + coreutils, 19 bytes

'y%d%.m%+ etad',W*N


'y%d%.m%+ etad',W*N
'y%d%.m%+ etad'       Push 'date +%m.%d%y' to the stack.
               ,      Execute as shell.
                W     Grab input from STDIN and eval it.
                 *    Multiply the top two items
                  N   Output as a number.

Cannot be run in safe mode, as this uses the Runtime's exec method.

share|improve this answer

SpecBAS, 39 bytes

1 INPUT n: ?n*VAL DATE$(TIME,"mm.ddyy")

Nothing out of the ordinary. Formats date as a string then multiplies the input by the VAL (value) of that string.

share|improve this answer
Interpreter / compiler link? – cat Mar 14 at 15:06 – Brian Mar 14 at 16:06
I've edited the link into your answer – cat Mar 14 at 16:07

Oracle 11g, 50 49 bytes

SELECT &n*to_char(sysdate,'MM.DDYY')FROM dual;

one less byte, thanks to @MickyT

share|improve this answer
you can drop the space before the FROM – MickyT Mar 14 at 18:05

Python 3, 74 54 bytes

using the time module instead of datetime like Loovjo's Answer

import time
lambda n:n*float(time.strftime('%m.%d%y'))

previous solution

from datetime import*
lambda n:n*float('%m.%d%y'))
share|improve this answer
@Zenadix The meta consensus is that unnamed functions are OK. – FryAmTheEggman Mar 14 at 16:09

Google Sheets, 13 bytes

Bytes are calculated with one byte per character, zero bytes per cell except for the designated input cell, two bytes. The equals sign to start a formula is not counted. (I don't know if this is standard, please correct me if I am wrong.)

Run snippet to see the code.

table {
  empty-cells: show;
td {
  border: 1px solid black;
<table border="1">
    <td style="text-align:right">3.1416</td>
    <td style="font-family:'Ubuntu Mono',monospace">=<span style="color:rgb(257,142,29)">A1</span>*<span style="color:rgb(126,55,148)">A2</span>

This works because you can define your own date formats in Google Sheets. I made it so that it is <month>.<day><year>.

share|improve this answer
You might want to ask on meta about this scoring system. ;P – VTCAKAVSMoACE Mar 16 at 21:27
Will do when I have time (maybe tonight in Maryland) – OldBunny2800 Mar 16 at 21:29

Pyke, 16 15 bytes, ASCII encoding



C867            - b,c,d = year, day, month
    wä          - a = base_96("ä") - 100
      %         - a = a%b
       J"       - a = "".join([a,c,d])
         b      - b = base(a, 10)
          T4^   - a = 10^4
             /  - a = a/b
              * - imp_print(a*eval_or_not(input))

or 11 bytes (non-competitive), (adds string singles, 2 digit year, string sumables)



C856        - a,b,c = 2d_year, day, month
    \.      - d = "."
      R3    - a,b,c = b,c,a
        s   - a = sum(a,b,c)
         b  - a = base(a, 10)
          * - imp_print(a*eval_or_not(input))
share|improve this answer
I'm guessing this is a different Pyke than ? Can you post a link to the language spec? – Robert Fraser Mar 15 at 4:08
Just wondering, what encoding does Pyke use? If it's UTF-8, this is 16 bytes. – OldBunny2800 Mar 16 at 21:30
@OldBunny2800 It doesn't matter; in this case it uses good old ascii as all code points are below 255. According to, the answer can define it's own encoding at no cost – muddyfish Mar 16 at 21:42

JavaScript ES6, 68 66 bytes

Saved 2 bytes thanks to dev-null!

x=>x*((a=new Date).getMonth()+1+"."+a.getDate()+(a.getYear()-100))

Anonymous function. Some uses:

f(1)    == 3.1416
f(5)    == 15.708
f(f(2)) == 19.73930112
share|improve this answer
You should try using with – Ismael Miguel Mar 15 at 9:36

Tcl/Tk, 58 bytes

puts [expr {[gets stdin]*[clock f [clock se] -f %N.%d%g]}]

(That's a complete program. If you want to cheat and remove the explicit puts statement then it's only 51 bytes -- you'd have to start tclsh and type/paste the following in directly, though:)

expr {[gets stdin]*[clock f [clock se] -f %N.%d%g]}
share|improve this answer

Java 114 bytes

public double p(double d){
  return (d*Double.parseDouble(new SimpleDateFormat("MM.ddyy").format(new Date())));
share|improve this answer
96 bytes: float p(float d){return d*Float.parseFloat(new SimpleDateFormat("MM.ddyy").format(new Date()));} – VTCAKAVSMoACE Mar 14 at 18:04

Racket, 112 characters

(define d(seconds->date(current-seconds)))(*(read)(+(date-month d)(*(date-day d).01)(*(-(date-year d)2e3)1e-4)))

Reads the number from input in standard reader syntax.

share|improve this answer

TI-84 Basic, 30 bytes

Works on TI-83/84 calculators; E is the scientific notation token and ~ is the negative token.

Prompt D:getDate:D(Ans(2)+E~4Ans(1)-.2+.01Ans(3

Test Case

share|improve this answer

R 48 bytes

share|improve this answer

MATL, 17 bytes


Try it online!

Z'              % get current date and time as float 
2$'mm.ddyy'XO   % format as a string with custom format 
U               % convert to number 
*               % multiply by implicit input 
share|improve this answer

TI-BASIC, 16 13 9 bytes


We round π to a number of decimal places equal to the minimum of {month,day,year}, and then multiply it by the input.

This is a function that takes input through X. Store it to one of the Y-variables, for example Y1, and then call like Y1([number]) on the homescreen.

share|improve this answer
There seems to be some disagreement that taking input via Ans is allowed. – TimmyD Mar 15 at 15:55
How is this only 13 bytes? Not counting Input A, I count 22 characters. – OldBunny2800 Mar 16 at 21:15
@OldBunny2800 TI-BASIC is token based, each atom is represented as one or two bytes. – Adám Mar 16 at 21:22
@OldBunny2800 The code page is here. – lirtosiast Mar 16 at 22:10

APL, 19 bytes


⎕TS is 2016 3 14 12 34 56 789 i.e. March 14rd, 2016 right before 12:35 pm
make into string, i.e. '2016 3 14 12 34 56 789'
8↑2↓ drop first two ('20') then take next eight ('16 3 14 ')
2⌽ rotate two characters, giving ' 3 14 16'
make into numbers (3 14 16)
reverse the list, giving 16 14 3
0.01⊥ evaluate in base ¹⁄₁₀₀, = 16 × 0.01² + 15 × 0.01¹ + 3 × 0.01⁰ = 0.0016 + 0.15 + 3 = 3.1416
⎕× multiply with input



⎕TS is 2016 3 14 12 34 56 789, i.e. March 14rd, 2016 right before 12:35 pm
make into string, i.e. '2016 3 14 12 34 56 789'
7↑2↓ drop first two ('20') then take next seven ('16 3 14')
2⌽ rotate two characters, giving ' 3 1416'
make into numbers (3 1416)
reverse the list, giving 1416 3
1E¯4⊥ evaluate in base ¹⁄₁₀₀₀₀, = 1416 × 0.01¹ + 3 × 0.01⁰ = 0.1416 + 3 = 3.1416
⎕× multiply with input

share|improve this answer
How does this work? – OldBunny2800 Mar 16 at 20:49
@OldBunny2800 Clear? – Adám Mar 16 at 21:09
Yes, thank you, but in UTF-8 this is 38 bytes. – OldBunny2800 Mar 16 at 21:14
@OldBunny2800… – Adám Mar 16 at 21:21
@OldBunny2800 APL uses its own code page -- each of these characters are one byte. (This was before ASCII mind you...) – quartata Mar 16 at 21:26

Your Answer


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

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