56
\$\begingroup\$

In as few bytes as possible, your job is to write a program that outputs:

3.14

In celebration of a late Pi day of course! :)

Rules

You can do it anyway you like, but there are some restrictions.

  • You may not use arithmetic operations anywhere in your program. This includes +, -, *, /, %, ^ (exponentiation), etc... This also includes incrementing (usually ++), decrementing (--), bitwise operations, and any built in functions that can be used as a replacement such as sum(), prod(), mod(), double(), pow(), sqrt(), inc(), dec(), etc... (Author's discretion)
  • The digits 3, 1, and 4 may not appear anywhere in your code.
  • You may not use any predefined variables/constants that your language may have as a replacement for 3, 1, and 4. (Author's discretion)
  • You may also not use any trigonometric functions such as sin(), cos(), tan(), arcsin(), arccos(), arctan(), sinh(), cosh(), tanh(), etc... (Author's discretion)
  • You may not use built-in or predefined values of Pi (or 3.14). No web requests.
  • Your program cannot require input of any kind (besides running it).
  • 3.14 is the only thing that you may output, it cannot be part of some longer/larger output..

Winner

The answer with the least amount of bytes on April 18th wins. Good luck!

Looking forward to clever answers from clever minds! Malbolge anyone? :P

\$\endgroup\$
  • 3
    \$\begingroup\$ You may want to clarify that ^ is the exponentiation operator, not bitwise XOR operator. \$\endgroup\$ – user12205 Apr 10 '14 at 16:05
  • 2
    \$\begingroup\$ Are bitwise operators allowed? \$\endgroup\$ – ProgramFOX Apr 10 '14 at 16:07
  • 1
    \$\begingroup\$ @ProgramFOX Well, they can be used as a replacement for normal operations, so, no. Not allowed. I'll edit the post. \$\endgroup\$ – kukac67 Apr 10 '14 at 16:09
  • 1
    \$\begingroup\$ Web requests allowed? \$\endgroup\$ – swish Apr 10 '14 at 16:35
  • 7
    \$\begingroup\$ @swish: I wouldn't use web requests, because that belongs to the list of Standard "loopholes" which are no longer funny \$\endgroup\$ – ProgramFOX Apr 10 '14 at 16:38

63 Answers 63

2
\$\begingroup\$

Perl, 22 bytes

print pack N,858665268
|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

Pure bash, 22 bytes

a=.$[0xE];echo ${#a}$a

Output:

$ a=.$[0xE];echo ${#a}$a
3.14
$

$[0xE] is just a base conversion with no actual arithmetic explicitly performed, so I assume this is legal.

|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

Bash, 53 (using seq)

Does seq count as arithmetic?

Reuses bits of my other answer. Based on string length - it generates a string which is 314 characters long.

m=`seq -8 99|wc -c`
false
o=$?
echo ${m:0:o}.${m:o:2}

Line 1 generates a sequence of integers between -8 and 99 using seq and sends the result to wc -c which counts the number of bytes in its input. The result is stored in m.

After this point, it's the same as my other answer:

m should now be 314. Now I want to insert a decimal point after the first character... but I'd need the digit 1 to do that!

Lines 3 and 4 circumvent that by taking the exit status of false and storing it in a variable. The exit status of false isn't 1 on some systems, so this isn't very portable, but this is after all!

Line 5 concatenates the first character of m, a decimal point and the next two characters of m, and prints the result to standard output.

Output: 3.14.

|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

BF,45 chars(without \n)

How About BF

 >+++++++[<+++++++>-]<++.
 >++[<-->-]<-.
 +++.+++.

thanks for pointing out that it only needs 3.14

|improve this answer|||||
\$\endgroup\$
  • 12
    \$\begingroup\$ Hm... aren't all those + and - signs incrementing and decrementing? \$\endgroup\$ – kukac67 Apr 11 '14 at 0:45
  • \$\begingroup\$ Yeah, it's impossible to write a nontrivial BF program that satisfies the guidelines. \$\endgroup\$ – David Z Apr 11 '14 at 2:02
  • \$\begingroup\$ I think that outputs 3.41592 rather than just 3.14 as required... (bf interpreter on Ubuntu 13.10) \$\endgroup\$ – user16402 Apr 11 '14 at 14:17
  • \$\begingroup\$ You can write ++++++++++[>+++++<-]>+.-----.+++.+++. and save 8 chars :P \$\endgroup\$ – Vereos Apr 14 '14 at 8:33
2
\$\begingroup\$

Python, 49

a=str(range(298,500,2)[8]);print a[0]+'.'+a[5<6:]

Explanation

  • range(298,500,2)[8]-Clever way to get 314
  • a=str(314) - '314'
  • a[0]-3
  • 5<6-Shorter than True which means 1
  • a[5<6:] - a[1:] - '14'
  • print a[0]+'.'+a[5<6:] - Putting the . and printing. The +s are string-concatenators.

Python (abusing the rules unless OP abuses their discretion)52 43

from cmath import*
print round(phase(-2),2)
|improve this answer|||||
\$\endgroup\$
  • 3
    \$\begingroup\$ Title:"Output Pi without math". First line:from cmath import :P. \$\endgroup\$ – Blackhole Apr 10 '14 at 17:31
  • 1
    \$\begingroup\$ @Blackhole But it's not an explicit bullet-point in the rules. \$\endgroup\$ – user80551 Apr 10 '14 at 17:31
  • \$\begingroup\$ Yeah... phase disqualifies this. \$\endgroup\$ – kukac67 Apr 10 '14 at 19:17
  • \$\begingroup\$ @kukac67 Is the other answer acceptable? \$\endgroup\$ – user80551 Apr 11 '14 at 7:03
  • \$\begingroup\$ If it were valid, though, -2+0j would save 6 characters. \$\endgroup\$ – Ry- Apr 11 '14 at 14:14
2
\$\begingroup\$

JavaScript, 22

Just a modification of ComFreek's idea

atob(atob('TXk0eE5B'))

JavaScript, 150

A different way just for fun

while(!m||a[0]>=(0+a)[a.length]){a=(Math.random()+"").replace(/(.)(.)(.*)(.)(..)/,"$2.$5");
m=a.match(/([^0-25-9]).[^02-9][^0-25-9]/)}m[0]

The idea was to get a random numbers until it is the desired one. Challenge was not to use the forbidden digits :) The two regexes should be possible to combine into one but I'm too tired now :)

|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

Matlab - 39 characters with a bit of magic

39 characters:

x=magic(6);fprintf('%d.%d\n',x([2,29]))

output:

3.14

magic(6) produces a magic square of size 6x6. It happens to provide the same square every time, which allows us to cherry-pick numbers. Matlab R2011b is used here.

|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

PowerShell - 47 24 20

Update: after seeing @grax's answer, use a single [char], and use format string.

'{0:#\.##}'-f+"ĺ"[0]  
|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

Bash, 72

I would use base64... if the digit 4 didn't appear in it!!

I might have used tr but that's already been done...

So instead I'm going to misuse chmod, which is by no means the shortest solution. What this script does is set its own permissions to the octal mode 314, then insert a decimal point.

chmod u=wx,o=r,g=x $0
m=`stat -c%a $0`
false
o=$?
echo ${m:0:o}.${m:o:2}

The first line sets the script file's permissions to the equivalent of octal mode 314 (--wx--xr--).

The second line uses stat and its --format option (shortened to -c) to get the file's octal mode only, represented by %a. The result is saved to a variable m.

After the second line, m should be 314. Now I want to insert a decimal point after the first character... but I'd need the digit 1 to do that!

Lines 3 and 4 circumvent that by taking the exit status of false and storing it in a variable. The exit status of false isn't 1 on some systems, so this isn't very portable, but this is after all!

Line 5 concatenates the first character of m, a decimal point and the next two characters of m, and prints the result to standard output.

Output: 3.14.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ This is just pure evil. \$\endgroup\$ – AJMansfield Apr 15 '14 at 22:43
1
\$\begingroup\$

PHP (30 bytes)

Longer than most here, but uses only very dirty tricks:

<?=ceil(2.5).'.'.(!0).chr(52);

Another version (29 bytes), if error reporting is disabled, otherwise outputs a notice:

<?=ceil(2.5).'.'.hexdec(E);?>
|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

C, 58

main(){printf("%d.%d%c",(int)ceil(2.9),(int)ceil(.8),52);}

C, 43

With a little cheating. Constants for 14 were not forbidden.

main(){printf("%d.%d",(int)ceil(2.9),0xe);}
|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

VB.NET - 0

After failing to write anything under 16 bytes, I decided to just make a joke answer. A PictureBox holds a saved screenshot of the "3.14" from the original post, instead of actual digits, so if you're looking for output in text format, I have failed.

But hey, I didn't have to write any code at all! And technically it shows exactly what the original post says to output...

My Pi Program

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ I think if you check the source of Form1.designer.vb you will see 3.14 in your code. \$\endgroup\$ – nderscore Apr 15 '14 at 5:58
  • \$\begingroup\$ No, there is no 3.14 in the designer code. I can tweak the size and location of the form and picturebox so that there are no 3's, no 1's, and no 4's in the designer code. But of course, if you count the designer code, it's a whole lot more than 0 bytes. I was merely joking that I could display 3.14 in a program without writing a single line of code myself. \$\endgroup\$ – Lucy Lauser Apr 15 '14 at 20:59
  • \$\begingroup\$ Ah I'm stupid for not reading that it was a picture box. \$\endgroup\$ – nderscore Apr 15 '14 at 21:01
1
\$\begingroup\$

Ruby - 78

Long one, but it can be easily extended to print more digits.

a="How I wish".split(' ')
print "#{a.shift.length}." 
a.each{|w|print w.length}

And the output: 3.14

Longer(194) version for more digits:

a="How I wish I could enumerate pi easily since all these bullshit mnemonics prevent recalling any of the sequence more simply".split(' ')
print "#{a.shift.length}."
a.each{|w|print w.length}

and output: 3.14159265358979323846.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ +1 Did you figure out the longer version all by yourself without using any program? \$\endgroup\$ – user80551 Apr 11 '14 at 10:51
  • \$\begingroup\$ It's from wiki - en.wikipedia.org/wiki/Piphilology :) \$\endgroup\$ – cyriel Apr 11 '14 at 11:45
1
\$\begingroup\$

Oracle SQL,56

select to_char(to_date('70907','YMMDD'),'Q.WD')from dual

Output:

3.14
|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

Java, 65

System.out.println("abc".length()+"."+"abcdefghijklmn".length());
|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ clever​​​​​​​​​! \$\endgroup\$ – Mhmd Apr 16 '14 at 12:02
  • \$\begingroup\$ You could cut this down a bit more: new int[3].length+"."+new int[14].length \$\endgroup\$ – elimirks Apr 16 '14 at 15:41
  • \$\begingroup\$ How'z it getting 65?? I am not getting this!! \$\endgroup\$ – Mudit Agarwal Apr 16 '14 at 17:59
  • \$\begingroup\$ @elimirks I cant as its mentioned in wuestion that I cannot use '1','3' and '4' \$\endgroup\$ – Mudit Agarwal Apr 22 '14 at 11:23
1
\$\begingroup\$

BASH

Not the shortest of the bunch, but it doesn't contain any numbers so I thought it was kind of cool:

29 bytes

wc<<<'a

'|sed 's/ /./;s/ //'

Output:

3.14
|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

C++, 214 202

Only works for little-endian processors... Big-endian version would be shorter.

#include<algorithm>
#include<iostream>
#include<iterator>
union u{int i;char c[];};struct s{u a,b;};int main(){s x;x.a.i=858665268;std::reverse_copy(x.a.c,x.b.c,std::ostream_iterator<char>(std::cout));}
|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

Java, 106 95

class A{public static void main(String[]a){System.out.print((""+(int)'ཊ').replace('9','.'));}}
|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ You can shorten this by 10: class A{public static void main(String[]a){System.out.print((""+(int)'ཊ').replace('9','.'));}} \$\endgroup\$ – kukac67 Apr 12 '14 at 23:00
0
\$\begingroup\$

JavaScript - 46 43

Not very original, but who cares :)

(a="a+b").length+(b=".")+b.length+(a+b).length

And after some help from nderscore:

(a="a+b")[L="length"]+(b=".")+b[L]+(a+b)[L]

(Note: all occurrences of + are string concatenations).

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ You could save 3 bytes by caching the name of the length property: (a="a+b")[L="length"]+(b=".")+b[L]+(a+b)[L] \$\endgroup\$ – nderscore Apr 14 '14 at 20:49
  • \$\begingroup\$ Cool, didn't know that trick. Thanks @nderscore! \$\endgroup\$ – CompuChip Apr 15 '14 at 6:43
0
\$\begingroup\$

APL (with lambdas), 21 character (byte count depend on encoding)

APL capable font needed to see this.

{⍴⍵,⍎⍵}'⍞←⌽".",⍕⍴⍕⍳2'

Here explained

{⍴⍵,⍎⍵}'⍞←⌽".",⍕⍴⍕⍳2'           
⍴'⍞←⌽".",⍕⍴⍕⍳2',⍎'⍞←⌽".",⍕⍴⍕⍳2' # lambda applied
⍴'⍞←⌽".",⍕⍴⍕⍳2',⍞←⌽".",⍕⍴⍕⍳2    # string is being evaluated as expression
⍴'⍞←⌽".",⍕⍴⍕⍳2',⍞←⌽".",⍕⍴⍕1 2   # ⍳2 expanded to 1 2
⍴'⍞←⌽".",⍕⍴⍕⍳2',⍞←⌽".",⍕⍴'1 2'  # 1 2 stringized
⍴'⍞←⌽".",⍕⍴⍕⍳2',⍞←⌽".",⍕3       # got dimension of '1 2'
⍴'⍞←⌽".",⍕⍴⍕⍳2',⍞←⌽".",'3'      # 3 stringized
⍴'⍞←⌽".",⍕⍴⍕⍳2',⍞←⌽'.3'         # '.' and '3' concatenated
⍴'⍞←⌽".",⍕⍴⍕⍳2',⍞←'3.'          # '.3' reversed
⍴'⍞←⌽".",⍕⍴⍕⍳2','3.'            # '3.' printed
⍴'⍞←⌽".",⍕⍴⍕⍳23.'               # '⍞←⌽".",⍕⍴⍕⍳2' and '3.' concatenated
14                              # got dimension of '⍞←⌽".",⍕⍴⍕⍳23.'
                                # finally, '14' printed
|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

PHP, 22

<?=ceil(M_E),'.',0xE?>

3,1,4 does not appear in the code and M_E is none of them

Perl, 29

printf "%d.%d",(-2..5)[5],0xE

Perl, 25

print((-2..5)[5],".",0xE)

Awk 54

END{split(systime(),a,"");printf a[2]"."a[7-6]"%c",52}

Awk (Bonus)

END{O=""=="";X=O""O;X+=O+=O+O;print O"."X;}

I know it uses arithmetics but at least there are no numbers at all! XOXOXOX

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

C 71

int main(){printf("%d.%d%d",strlen("***"),strlen("*"),strlen("****"));}
|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

Java 41 / 83 characters

System.out.println((int)''+"."+(int)'');

Unfortunately copy pasting directly into the IDE from here might not work. The characters inside the '' don't show correctly here, but they are essentially variations on the space ASCII character with the decimal values 3 and 14. Below a full compilable version;

class C{public static void main(String[]a){System.out.println((int)''+"."+(int)'');}}
|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

PowerShell, 19 bytes

+''[0],0xe-join'.'

The third character is the non-printable control char ETX, ascii code 3. Hex dump:

Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000  2B 27 03 27 5B 30 5D 2C 30 78 65 2D 6A 6F 69 6E  +'.'[0],0xe-join
00000010  27 2E 27                                         '.'

This feels like cheating. I did have to use a '3' after all in the hex editor. Personally, I don't think an answer requiring the use of a hex editor should be allowed. If your language supports escaping non-printable chars, fine, but if it can't be copy/pasted from here, I don't think it should be allowed, JMO.


PowerShell, 20 bytes

+'ಎ'[0]-replace2,'.'

PowerShell, 21 bytes

(5..2)[2],0xe-join'.'

PowerShell, 22 bytes

(-6..20)[9,20]-join'.'
  • Array from -6 to 20
  • Indexes 9 and 20 grab 3 and 14
  • Join on dot (.)

PowerShell, 24 bytes

[int]'ಎ'[0]-replace2,'.'
  • 'ಎ' is a string with the unicode char 3214
  • 'ಎ'[0] gets the char
  • [int]'ಎ'[0] casts to an int with value 3214
  • -replace converts 3214 to a string and swaps the 2 for a dot (.)
|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

ksh 19

echo ${#0}.$((0xe))
3.14
|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

Brainfuck - 39

++++++++++[>+++++<-]>+.-----.+++.+++.

Note that + and - are not arithmetic operators.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ + and - increment and decrement. \$\endgroup\$ – L3viathan Apr 2 '17 at 13:44
  • \$\begingroup\$ Hmm, you have a point there. I didn't think of that when writing the answer. \$\endgroup\$ – nyuszika7h Apr 6 '17 at 12:59
0
\$\begingroup\$

Python 3, 45 bytes

a=str(ord("ĺ"))
print("%s.%s"%(a[0],a[True:]))

(Had to use True to get around the restriction on the digit 1...)

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ You can use 5<6 or any other Boolean operandi instead of True. (Yes the 5<6 was shamelessly stolen from the other Python answer) \$\endgroup\$ – caird coinheringaahing Apr 2 '17 at 12:26
0
\$\begingroup\$

Python 2, 40

Doesn't bend the rules at all.

print('%i\b.%i'%(ord(' '),ord('î'))[:-1]

Extended ASCII ftw. Shame I couldn't put \b at the end of my string and remove the ()[:-1]...

~-~!, also 40

'=~~,~~~~~,~~~~~:@'+~:@'-~~~~:@'-~:@'+~~
|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

Object disoriented - 72 characters

dmain.ozozososozozososozozosozosososozozozososozozozosozozososozosozozzz

Boring answer, but the most compact I've achieved.

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

T-SQL, 36

This entry assumes CHECKSUM() is allowed.

PRINT STUFF(CHECKSUM('2~2'),2,2,'.')

Try the SELECT version in SQL Server 2012 here.

|improve this answer|||||
\$\endgroup\$

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