Output Pi without math

56

13

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

kukac67

Posted 2014-04-10T15:55:00.920

Reputation: 2 159

Question was closed 2017-12-27T20:46:04.280

Ask questions in the comments if anything is unclear. – kukac67 – 2014-04-10T15:55:23.877

3You may want to clarify that ^ is the exponentiation operator, not bitwise XOR operator. – user12205 – 2014-04-10T16:05:14.143

2Are bitwise operators allowed? – ProgramFOX – 2014-04-10T16:07:09.450

1@ProgramFOX Well, they can be used as a replacement for normal operations, so, no. Not allowed. I'll edit the post. – kukac67 – 2014-04-10T16:09:27.823

1Web requests allowed? – swish – 2014-04-10T16:35:27.657

7

@swish: I wouldn't use web requests, because that belongs to the list of Standard "loopholes" which are no longer funny

– ProgramFOX – 2014-04-10T16:38:08.130

1@swish I agree with ProgramFox. No web requests. I'll add it to the post. – kukac67 – 2014-04-10T16:39:44.853

1Can I use - to indicate negative numbers like -2.0 ? – user80551 – 2014-04-10T17:19:15.223

@user80551 yes you can – kukac67 – 2014-04-10T19:31:12.907

1Somehow I think this would have been interesting with more digits (like 3.14159265 or whatever), because just 3.14 makes me sad. – Pierre Arlaud – 2014-04-11T12:43:38.490

@kukac67 Can you clarify No web requests? I think the point is that information requested from the internet is not allowed. To me web implies just http and https. What about e.g. ftp? What about this answer which sends an ICMP request, but does not require any response for it to work?

– Digital Trauma – 2014-04-11T17:21:30.450

1@DigitalTrauma The answer you linked to is fine. It's not really getting anything from the web. I just wanted to prevent linking to file on the web that contains 3.14 and outputting that. – kukac67 – 2014-04-11T18:16:13.080

1too bad modulus counts as arithmetic, otherwise 9%5.86 (e.g. in bc) would have been unbeatable – jaap – 2014-04-11T23:05:44.690

Piet might almost count. No visible arithmetic unless you decode it ;) – Izkata – 2014-04-14T18:06:50.763

I expect a Perl one with only keywords (or maybe quoteless string literals). http://www.perlmonks.org/?node_id=290607

– Ming-Tang – 2014-04-15T21:04:03.427

Even though I have more than 10 reputation, I cannot seem to add an answer. I definitely think you should have allowed more digits. credit for more digits offset against characters for the code.

Also, I think you should allow leading zeros In octave: datestr(581540,'mm.dd') (23 bytes) yields: 03.14 – Dov – 2014-04-17T02:34:54.757

/me writes programming language where ⌘ outputs 3.14 – Kaz Wolfe – 2014-04-19T21:17:47.770

Does the program have to have the same output no matter which day it runs? For example, can I just output the current date in an M.dd format, and insist that you run my program on 14 March? – Dawood says reinstate Monica – 2014-04-20T04:23:53.650

Answers

25

CJam - 8 6

S`,'.E

CJam is a new language I am developing, similar to GolfScript - http://sf.net/p/cjam.
Here is the explanation:

S is a variable preinitialized to space (" ")
` generates the string representation of the last value - which is exactly " " (3 characters)
, calculates the string length (3)
'. is the dot character
E is a variable preinitialized to 14; 3, 1 and 4 are not allowed but it doesn't say anything about 14 :)

Credits to Doorknob for the backtick idea

aditsu quit because SE is EVIL

Posted 2014-04-10T15:55:00.920

Reputation: 22 326

14 is a direct source of 1 and 4, so I wouldn't consider your use of the E constant valid. – Brilliand – 2014-04-10T20:12:40.933

1@Brilliand I would accept the use of E. – kukac67 – 2014-04-10T20:18:45.247

But I will probably not choose this answer because it is a language that you are making, and it feels like cheating others... – kukac67 – 2014-04-10T20:19:30.833

6@kukac67 While I haven't made an official release yet (coming today), I have already made the current CJam code available via hg. If you get the CJam code as of 1 day before you posted the question, it will run my program correctly (so I haven't made changes for solving this problem). But I won't really mind anyway. – aditsu quit because SE is EVIL – 2014-04-10T20:23:10.420

33time to develop HQ9+π... – Nzall – 2014-04-11T11:34:22.850

@aditsu It wasn't because I thought you would have changed the CJam specification to help you in this question... But anyway, if this ends up being the shortest program (probably :D), I will choose it as the winner. I now realize there is no reason for CJam to be disqualified. I don't know what I was thinking... Hope you win! :) – kukac67 – 2014-04-14T20:08:15.550

You win! There was a 4-char answer, but I think it breaks the "no predefined values" rule by requiring the file-name to be 3.14. I really like that backtick thing btw. – kukac67 – 2014-04-18T18:00:20.420

Why isn't this the most voted answer? – Anonymous Pi – 2014-04-21T00:18:34.697

2@AnonymousPi Everybody is free to vote for the answers they choose. Maybe they're more impressed with other answers even if they're not as short. – aditsu quit because SE is EVIL – 2014-04-21T00:53:03.707

2Why do you have a variable preinitialized to 14? – user2357112 supports Monica – 2014-05-20T02:54:41.283

1@user2357112 to help with golfing :) I have variables for 10, 11, ..., 20 (A, B, ..., K) – aditsu quit because SE is EVIL – 2014-05-20T03:18:27.560

113

PHP - 22 bytes

<?=date('n.j',8899e5);

Pi Day in year 1998 was really cool!

Blackhole

Posted 2014-04-10T15:55:00.920

Reputation: 2 362

How is 8899e5 March 14th? – kukac67 – 2014-04-10T17:40:11.437

13@kukac67: n.j is the format, and 8899e5 is the Unix timestamp of March 14th in 1998. – ProgramFOX – 2014-04-10T17:43:03.893

7That is so clever. – Amal Murali – 2014-04-12T14:00:46.873

7You can save 7 characters by removing ,8899e5. It will be correct once a year. – dkasipovic – 2014-04-15T10:44:12.887

Does not need that semicolon! – Brandon Wamboldt – 2014-04-15T14:57:08.653

Actually you can make it a digit shorter by using this timestamp if I'm not mistaken: 623e4 – Timo – 2014-04-16T09:02:50.233

@BrandonWamboldt Better a semicolon than a closing tag!

– Blackhole – 2014-04-16T10:30:42.553

1@Timo You're right, but it contains the illegal digit "3" ;). – Blackhole – 2014-04-16T10:31:03.133

@Blackhole Neither are needed, no semicolon and no closing tag is still a perfectly valid PHP file, give it a try :) – Brandon Wamboldt – 2014-04-16T12:00:11.243

@BrandonWamboldt you are mistaken. Unless the final syntax character is a right brace (from a class or function definition, for example), either a semicolon or closing tag is required. – primo – 2014-04-17T08:30:33.367

18@Blackhole 20 bytes: <?=date('w.W',78e5); April 1, 1970 was a Wednesday in week 14. – primo – 2014-04-17T08:53:11.300

92

C, 39

Assumes the machine is little-endian and uses IEEE floating-point standard.

main(){printf("%.2f",*(float*)"P@I@");}

The fun fact is that "P@I@" is actually not related to PI but is equivalent to 0x40494050 which is the representation of 3.144550323486328

http://ideone.com/uXVEtl

Michael M.

Posted 2014-04-10T15:55:00.920

Reputation: 12 173

3That's pretty awesome. – wchargin – 2014-04-13T03:05:40.270

1Your code assumes type-punning on a little-endian machine. – Nayuki – 2014-04-14T19:31:36.200

@NayukiMinase, yes you're right, it worth pointing it out. And it also assumes the use of IEEE floating-point standard. – Michael M. – 2014-04-14T22:03:19.580

And it contains undefined behavior (implicit declaration of variadic function) – rubenvb – 2014-04-15T14:35:32.673

5This code actually assumes that the machine is Michael's machine :-). – Konrad Borowski – 2014-04-15T15:52:01.840

As undefined behavior and comments like "it only works on full moon" or only working with one specific version of a really obscure compiler are sometimes acceptable at IOCCC, I guess it can also be acceptable here. – vsz – 2014-04-17T06:07:09.970

50

dc, 11 9 bytes

zE[.]znPp
  • z Push current stack depth (0) onto the stack
  • E Push E16 (==1410)
  • [.] Push the string "."
  • z Push current stack depth (3) onto the stack
  • n Pop 3 and print as number
  • P Pop "." and print as char
  • p Pop 14 and print as number with newline

Output:

$ dc <<< zE[.]znPp
3.14
$ 

Digital Trauma

Posted 2014-04-10T15:55:00.920

Reputation: 64 644

So "use input base" is an operator? It sort of smells like an arithmetic operation, but probably still valid. – Brilliand – 2014-04-10T20:18:39.040

@Brilliand There's nothing I see in the question that bans base conversions. In fact the OP appears to be encouraging base conversions in a comment here http://codegolf.stackexchange.com/a/25681/11259

– Digital Trauma – 2014-04-10T20:27:14.477

I do agree that it's valid; I'm just thinking that when the base conversion is an operator rather than part of the number syntax, it blurs the line between inline data and an arithmetic operation. – Brilliand – 2014-04-10T20:54:11.800

I think this should be 15 bytes? – Registered User – 2014-04-11T13:21:44.317

9@AdityaPatil Why? dc is a language and interpreter, just like all the other languages here. dc -e is just the invocation of that interpreter. I could have just as easily saved the 9-byte program in a file and run dc pi.dc. If these bytes need to be counted, then the same would have to apply to all other languages. e.g. include python in all python entries or ruby golfscript.rb in all golfscript entries. I believe the agreed convention here is not to include these, unless special options need to be passed. – Digital Trauma – 2014-04-11T14:33:59.883

42

JavaScript (ES5) 20 bytes

A variation of m.buettner's JS solution.

(x='.'+0xE).length+x

Edit: JavaScript (ES5) 18 bytes

A variation of ComFreek's idea of using the base64 decode function.

atob('Mw')+'.'+0xE

Edit: Javascript (ES5) 16 bytes

If the unary + operator is allowed to cast a string to a number, it can be reduced to:

+atob('MDMuMTQ')

nderscore

Posted 2014-04-10T15:55:00.920

Reputation: 4 912

WOW! That is really clever! – kukac67 – 2014-04-10T16:38:16.010

9@NateEldredge This is string concatenation, not arithmetic. – tomsmeding – 2014-04-10T17:48:46.513

is the use of + accepted here? – phuclv – 2014-04-12T06:46:48.463

You can shorten this to 13 bytes using bitwise XOR: (5^6)+'.'+0xE – jackcogdill – 2014-04-14T16:32:43.560

He explicitly stated that the use of +,-,x,/,= are not allowed... – Dozer789 – 2014-04-14T19:36:32.857

@yentup based on the rules, it's not allowed to use bitwise operations – nderscore – 2014-04-14T19:42:09.137

@nderscore oh ok I didn't catch that – jackcogdill – 2014-04-14T20:01:37.557

MDN says the unary operator is an arithmetic operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators

– George Reith – 2014-04-15T19:47:00.127

@GeorgeReith Good point. I've updated my answer to point this out. It's not explicitly stated in the rules for this question, so I'll leave it for now. – nderscore – 2014-04-15T19:58:45.363

@GeorgeReith Thanks for making me question my solution. Because of this, I just found a way to remove the need for the unary + operator and reduced the solution by 1 byte :) – nderscore – 2014-04-15T20:03:25.897

1I find the Javascript solution to be the most elegant and I was about to post mine until I noticed it had a '4' in it: atob('My4xNA=='), lol. – Matt – 2014-04-15T22:16:13.083

@MattBorja Yeah, that's why I had to add a non-printing character to the beginning to get rid of the 4 :) – nderscore – 2014-04-15T22:42:51.507

The backspace may be unprintable, but it's still there. atob('CDMuMTQ').length gives 5. – Dennis – 2014-04-16T13:23:25.863

1@Dennis you're right, it's still there. It's even there if I copy+paste the result from console. I'm not happy with it so I'll revert to the 16 byte solution. – nderscore – 2014-04-16T20:25:24.900

How 'about this one :) atob('MwAuMTQ') (15 bytes) or even atob('ADMuMTQ') – Matt – 2014-04-17T17:59:10.137

@MattBorja It's the same problem as my version using \b. It's not exactly the right output even if the extra char is not visible. Ex: atob('MwAuMTQ').length = 5 – nderscore – 2014-04-17T18:46:03.897

39

Haskell, 41 bytes

When is pi day in Australia?

p=(\(a:n:y:t:i:m:e:_)->[m,a,t,e])['.'..]

Edited to add: like the other Haskell answer, that outputs a string, so has quotes. You can score 33, and be strictly within the rules, but it's less fun:

p=putStr$map([','..]!!)[7,2,5,8]

bazzargh

Posted 2014-04-10T15:55:00.920

Reputation: 2 476

Haha, wow. This is good! – Ry- – 2014-04-11T14:17:12.133

Can you explain why this works? – yhager – 2014-04-16T00:33:36.647

5I like this one a lot, +1. But I think technically ".." is invoking the increment operator, which was forbidden. (Actually upvoting also invokes an increment operation, so it should be forbidden as well;-) – Marc van Leeuwen – 2014-04-16T12:35:19.440

I actually did think about that - I had an even shorter answer: p=[2.9,2.92..]!!([0,6..]!!2)...and in this one .. does look wrong. But Haskell is strongly typed, and the increment in the answer I gave is of Char not Num and isn't arithmetic-the thing that's actually banned. I'd need a fromEnum to convert the chars back to numbers to use them that way. Anyway, my conscience is clear :) – bazzargh – 2014-04-16T14:10:07.317

6@yhager: ['.'..] is the char sequence "./0123456..." (etc). (a:n:y:t:i:m:e:_) is a pattern match pulling out the first 7 characters, [m,a,t,e] reorders 4 of them into "3.14". Knowing that this is what you want to do, it's a matter of searching the dictionary to find words with the right structure. Which I did...eg another pair was "ugliest suit". Then you come up with a joke :) – bazzargh – 2014-04-16T14:18:09.510

An Australian would say Pi Day is 22/7, not 3/14 ... – Ross Presser – 2014-04-22T19:35:13.743

32

Morse Code, 33 Bytes

morse -d ...-- .-.-.- .---- ....-

Technically speaking, the information only takes 21 bytes.

Ken A

Posted 2014-04-10T15:55:00.920

Reputation: 585

11We definitely need more golf solutions in morse code here... – ceased to turn counterclockwis – 2014-04-11T14:19:37.323

26Technically speaking, I'd say 21 bits, not bytes – Michael M. – 2014-04-11T19:17:15.893

14@Michael since Morse code can be either a dot, dash, or space, wouldn't it require more than 1 bit to store 1 operation? – smcg – 2014-04-11T19:42:59.913

@smcg, you're right, each Morse unit stores a trit, so 21 Morse units is a little over 33 bits. – Joe – 2014-04-11T21:25:28.913

5@smcg ButSpacesAreForWeakPeopleWhoCan'tReadThingsLikeThis – Cole Johnson – 2014-04-13T00:26:19.917

2@ColeJohnson: But then spaces are part of the coding. E.g. ...... -> Is that III or SS or EEEEEE or EIS or IES or .... When I remember my time at the Marine, you even need long spaces and short spaces to differ between letters and words. So you always need two bits_2 per letter – phresnel – 2014-04-14T07:31:06.470

8As much as I like morse code (and hence this solution) - but isn't that against rule 3: "You may not use any predefined variables/constants that your language may have as a replacement for 3, 1, and 4." or even rule 2: "The digits 3, 1, and 4 may not appear anywhere in your code."? – kratenko – 2014-04-14T16:17:52.560

@kratenko: I agree. – phresnel – 2014-04-16T12:19:48.440

@phresnel You don't always need 2 bits, because we only need 3 values. Suppose dot, dash, space are 00, 01, 10 respectively. Since 11 is never used, we can safely replace one of these with a single 1 bit without causing any ambiguity. If we use the single bit for the most common value (dot), the information can be stored in 37 bits. – nmclean – 2014-04-16T17:34:23.993

@nmclean: Hmm, yeah, and long spaces for word separation can be replaced by two consecutive short spaces. I thought about a variable length encoding, too. – phresnel – 2014-04-17T07:37:22.263

@phresnel 10 is a long space in this case. No need to encode short spaces at all since dot and dash are already distinct. – nmclean – 2014-04-17T12:01:12.627

@nmclean: Hmm, yeah. I dunno what made me that high. It's a total facepalm. – phresnel – 2014-04-17T12:43:43.553

One could define a subset of Morse Code that only contains the characters necessary to send the message. In this case, the message is "3.14", so two bits could suffice: .. = "3" .- = "." -. = "1" -- = "4" Spaces are not even necessary. Thus, the message is sent in 8 bits, "...--.--". Represented as a byte, the message is now 0x1B or 0xE4 depending on bit polarity. – Ken A – 2014-04-17T14:26:02.170

1@KenA Or you could define “3.14 Code”, where the only valid message is an empty one (0 bits) and the output is always “3.14”. But doing things like these is not interesting. – svick – 2014-04-19T20:46:50.400

@phresnel Or you can use ternary and store a Morse code character in log_2(3) bits (1.58496...). Then, if you want to store 1000 characters, you don't need 2000 bits, but only 1585. If you want to find a modern ternary computer.

– Cole Johnson – 2014-04-24T06:13:18.613

@svick Have you ever heard of Golfscript :P – Cole Johnson – 2014-04-24T06:13:57.917

@ColeJohnson: Interesting :D – phresnel – 2014-04-24T14:55:04.007

27

J - 15 11 10 char

Made it shorter, using the fantastic i:.

6{i:6.28j8

Explained:

  • 6.28j8 - The complex number 6.28 + 8i.
  • i: - This is where the magic happens. i: on a complex number A+Bi, B≠0 takes B+1 equally spaced points from the interval [-A,A].
  • 6{ - Take element at index 6, which just so happens to be 3.14.

Previously, we had the following nonsense:

|.'.'2}":22b8d5

Explained by explosion:

         22b8d5  NB. 8d5 in base 22 = 4163
       ":        NB. convert to string
  '.'2}          NB. change character at index 2 to '.'
|.               NB. reverse to make '3.14'

algorithmshark

Posted 2014-04-10T15:55:00.920

Reputation: 8 144

Instead of |.'.'2}":22b8d5, you can save 2 characters by picking a number that doesn't require reversal: '.'1}":16bbc6 – rationalis – 2014-04-15T02:16:36.030

3@epicwisdom The digits 3, 1, and 4 are banned. I have to use a number in the form 41X3 because I am only allowed to modify the characters at indices 0 and 2. – algorithmshark – 2014-04-15T02:39:10.033

20

Linux command line, 35 bytes

This one is nowhere near winning, but here it is for the fun of it:

ping -w2 67502862|grep -oP '.\..\d'

Output (after 2 seconds):

$ ping -w2 67502862|grep -oP '.\..\d'
3.14
$

Digital Trauma

Posted 2014-04-10T15:55:00.920

Reputation: 64 644

Quote from the question: "No web requests." – Doorknob – 2014-04-11T03:02:40.907

9@Doorknob ICMP echo request != web request. Regardless, the ping is to 4.6.3.14, from which I get no reply, so its not like I'm getting any useful information back from the internet – Digital Trauma – 2014-04-11T03:39:49.927

10@Doorknob But if this still bothers you, we can do this :;ping -t${#?} -qc2 67502862|grep -oP '.\..\d'. This sets the TTL to 1, so the outgoing ICMP echo is dropped by your router before it ever gets anywhere near the internet – Digital Trauma – 2014-04-11T04:22:45.423

1You can save 9 s by using ping -w2 67502862. (Ninja edit because before i was advising w1, almost broke the rules.) – lolesque – 2014-04-17T13:10:40.970

@lolesque Thanks. Doesn't improve the golf score though ;-) – Digital Trauma – 2014-04-17T14:22:26.593

16

GolfScript, 18 13 12

'.'.`,\.,n`,

Old version:

'...','.'.,'....',

It's very artistic, only 3 unique characters! ;)

How it works:

# cmd   # stack
'...',  # 3
'.'.    # 3 '.' '.'
,       # 3 '.' 1
'....', # 3 '.' 1 4

Here's an explanation of the 12-char version (much more interesting, IMO):

'.' # '.'
.`, # '.' 3
\.  # 3 '.' '.'
,   # 3 '.' 1
n`, # 3 '.' 1 4

It works because n`, is 4, since n` is '"\n"'. Same logic for '.'`,. It also swaps instead of creating a new string to save a char (thanks @algorithmshark).

Alternate version:

'pi ','.'.,'day!',

or

'Hi ','.'.,'PPCG',

Or anything in those strings, really. :P

Doorknob

Posted 2014-04-10T15:55:00.920

Reputation: 68 138

Only 3 different characters, cool :) – aditsu quit because SE is EVIL – 2014-04-10T19:17:30.583

Would '.'.`,\.,n`, work to save a char? Reusing the '.' by duplicating and swapping. – algorithmshark – 2014-04-10T19:33:21.607

@algorithmshark Yep, thanks! – Doorknob – 2014-04-10T23:52:16.793

This is very clever! +1 – VisioN – 2014-04-14T13:20:22.977

this does look like the morse code version – pwned – 2014-04-18T07:13:26.803

14

OP's answer.

Mathematica, 21 20 18

This feels cheap...

Range[2,5,.06][[20]]

or

Range[2,5,.02][[58]]

Figured out how to make it 18:

Range[-.86,5][[5]]

Haskell, 49 48 12

(48 includes the new line character)

p=[-6..]
r=concat$show(p!!9):".":(show$p!!20):[]

Run it by calling the r function.

Using the method as with Mathematica above, you can type this into GHCi:

[-2.86..]!!6

Java, 87 86

class P{public static void main(String[]a){System.out.print("tri".length()+"."+0xe);}}

Scala, 27

Translated from Java as suggested by Score_Under. (I don't really know Scala)

print("tri".length+"."+0xe)

kukac67

Posted 2014-04-10T15:55:00.920

Reputation: 2 159

Oh, 0xe is clever. Do you mind if I improve my JS answer with that? ;) – Martin Ender – 2014-04-10T16:21:24.970

Most java can be directly converted to scala, which is usually shorter if you really want to save on the bytes - if you're using it as a script, the entire thing is just: print("tri".length+"."+0xe) – Score_Under – 2014-04-10T20:25:20.777

Yeah I thought of the same thing, which is shorter in Julia as [-.86:5][5] for 11, but figured it didn't count since ranges are just math. – gggg – 2014-04-16T23:53:31.647

12

Bash, 50

Help/error messages aren't external resources, they're a command's output!

If anything is rule abuse, this is it. It uses the coincidence that the help message given to STDERR by the exact command

ping6

is 314 characters long (at least on Ubuntu 13.10 with iputils-121221). EDIT: I appreciate that this is much less portable than I expected...

m=`ping6|&wc -c`
false
o=$?
echo ${m:0:o}.${m:o:2}

The first line takes the character length of the help message and stores it in a variable.

As in my other answers, the next few lines obtain the number 1 by taking the exit status of false (not very portable but this is after all!), then use that value to insert a decimal point in the last line

Output: 3.14

user16402

Posted 2014-04-10T15:55:00.920

Reputation:

you sir are genius – Joshua – 2014-04-11T12:52:54.483

1Uh oh, "2.81" on Ubuntu 12.04 (iputils-101006). +1 all the same ;-) – Digital Trauma – 2014-04-12T01:29:38.473

@DigitalTrauma according to info ping6 I have iputils-121221 – None – 2014-04-13T06:26:01.300

also check out my chmod-abusing answer to this question at http://codegolf.stackexchange.com/a/25724/16402

– None – 2014-04-14T16:48:51.180

How about ping6|&wc -c|sed 's/^./&./'? – gniourf_gniourf – 2014-04-19T13:31:06.743

@gniourf_gniourf I have no idea how to use sed... thanks – None – 2014-04-19T16:10:31.573

2even shorter: ping6|&wc -c|sed 's/./&./' – malkaroee – 2014-10-19T10:01:31.430

11

Bash+TeX 28 bytes

If you have TeX installed:

tex -v|head -c8|cut -d\  -f2

The version number of TeX asymptotically approaches pi as the software improves. So, as time goes on, you can use this (nonconforming) implementation to print more and more digits!

tex -v|cut -d\  -f2 | head -n1

This printed 3.1415926 back in 2011; as of January 2014, it will print 3.14159265.

nneonneo

Posted 2014-04-10T15:55:00.920

Reputation: 11 445

I love this one! – gniourf_gniourf – 2014-04-19T15:09:31.153

You can use tex -v|grep -oP '.\..\d' to save 4 bytes. (Regex stolen from DigitalTrauma's answer.) Anyway, +1 because I just thought of the same answer.

– user12205 – 2014-04-19T22:26:36.583

10

JavaScript, 20 bytes

'...'.length+'.'+0xe

Use it in a console, so that the result is directly printed. Otherwise, alert(...) will add another 7 characters.

Same as my other answer, I just noticed it's a lot shorter in JS.

The idea of using 0xe for 14 is taken from the OP's submission with the OP's kind permission.

Martin Ender

Posted 2014-04-10T15:55:00.920

Reputation: 184 808

1Its fine, you can use it :) – kukac67 – 2014-04-10T16:30:26.050

1Alternative 20 byte solution: (x='.'+0xE).length+x – nderscore – 2014-04-10T16:35:50.773

@nderscore that's a pretty neat idea. If you post that as another answer, you'll get my upovote ;) – Martin Ender – 2014-04-10T16:36:48.693

10

GNU date, 17 bytes

date -d2/5 +%u.%y

This one only guaranteed to work this year, but I don't see any limitation in the rules about this ;-)

The + is simply indicates the start of the format specifier for date and is not an arithmetic addition. Same with the -, indicating input date.

Output:

$ date -d2/5 +%u.%y
3.14
$

Digital Trauma

Posted 2014-04-10T15:55:00.920

Reputation: 64 644

only guaranteed to work this year It's fine.. :) – kukac67 – 2014-04-10T19:33:07.483

10

Bash, 17 bytes

tr 0 .<<<$[62#MC]

Dash, 41 bytes

perl -pechomp,s/./$./<<$


..










.

Dennis

Posted 2014-04-10T15:55:00.920

Reputation: 196 637

Bash would complain loudly about the missing ending marker while Dash doesn't, so a Bash solution without error messages would require two extra bytes. – Dennis – 2014-04-11T00:21:01.867

+1 as well. I guess @TheDoctor forgot to click the upvote button? – Digital Trauma – 2014-04-11T04:28:52.413

@DigitalTrauma oops... fixed – TheDoctor – 2014-04-11T14:11:27.900

7

Bash 23 22

seq 2 .02 5|sed -n 58p

Shell (without history expansion) 20

seq 2 .02 5|sed 58!d

user80551

Posted 2014-04-10T15:55:00.920

Reputation: 2 520

seq 2 .06 5|sed -n 20p also works as given in OP's Mathematica answer. – user80551 – 2014-04-11T14:55:55.223

sed 58!d is slightly shorter. – Dennis – 2014-04-11T18:30:37.237

@Dennis Weird, gnome-terminal substitutes !d with dpkg ... which was the last command that I ran that began with d. Works fine in ksh but zsh says zsh: event not found: d so that's definitely getting substituted for something. – user80551 – 2014-04-11T18:44:15.920

That's because of Bash's history expansion. It's disabled by default for scripts, so if you save the same command in pi.sh and execute bash pi.sh, it will work fine.

– Dennis – 2014-04-11T18:46:24.410

6

Python, 39 or 28 47 or 34

(Thank you Score_Under for golfing it down so much)

print"%s.%s%c"%(len('aaa'),len('a'),52)

+ here is the string concatenation operator, not addition.

Copying the 0xe trick from the OP, here's 28 chars with help from @psal

print('%X.%s'%(675,0xE))[2:]

Old versions:

print str(len('aaa'))+'.'+str(len('a'))+chr(52)

print str(len('aaa'))+'.'+str(0xe)

print"%s.%s"%(len('aaa'),0xe)

user12205

Posted 2014-04-10T15:55:00.920

Reputation: 8 752

The second one can be shortened by removing the space after the print and using a "%s" format instead of str(). c.f. print"%s.%s"%(len('aaa'),0xe) at 29 bytes. You can do the same to the first one too: print"%s.%s%c"%(len('aaa'),len('a'),52) at 39 bytes. – Score_Under – 2014-04-10T20:31:20.473

@Score_Under Oh, I thought using %s still requires str. Thanks for the tip :) – user12205 – 2014-04-10T20:50:49.220

1another 29 bytes solution : print('%s,%s'%(0xE9,0xE))[2:] – onionpsy – 2014-04-17T07:05:54.273

1... and in 28 bytes : print('%X.%s'%(675,0xE))[2:] – onionpsy – 2014-04-17T07:28:13.440

5

GolfScript, 8 bytes

'??.'(\(

This program contains non-printable ASCII characters, so it cannot be directly pasted here. Instead, the question marks in the code above should be replaced with the bytes 03 and 0E in hexadecimal.

For convenience, here's a hex dump of the actual program. Unix / Linux users can run this hex dump through xxd -r to reconstruct the program:

0000000: 2703 0e2e 2728 5c28                      '...'(\(

Explanation:

  • The first five bytes of the program form a single-quoted string literal encoding the three characters with the ASCII codes 3, 14 and 46 (= ASCII period).

  • ( chops the first character off the string and pushes its ASCII code (3) on the stack. \ swaps the top two items on the stack, pulling the string back to the top, and the second ( chops another character off the string, again pushing its ASCII code (14) on the stack.

At the end of the program, the stack (excluding the empty input string) therefore looks like this:

3 "." 14

At the end of the program, the default behavior of the GolfScript interpreter is to stringify and print everything on the stack, yielding the desired output.

Ilmari Karonen

Posted 2014-04-10T15:55:00.920

Reputation: 19 513

1

Snap! I had exactly the same idea, just 12 hours too late. I guess I should read page 2 before posting... Oh well, rolling back, +1 to you.

– Dennis – 2014-04-12T04:14:18.047

5

bash -- 39

We all know that the first few digits of Pi can be computed from the following statement:

May I have a large container of coffee

We need only 2 decimal places, right?

m=May
i=I
h=have
echo ${#m}.${#i}${#h}

devnull

Posted 2014-04-10T15:55:00.920

Reputation: 1 591

4

Perl, 15 20 bytes

print 05706=~s/0/./r
print 0xbc6=~s/0/./r

mob

Posted 2014-04-10T15:55:00.920

Reputation: 2 506

Isn't PI__ something of a constant related to Pi? – Llamageddon – 2014-04-10T16:51:12.463

It's not a constant. It's two strings being XOR-ed. – nderscore – 2014-04-10T16:55:52.917

Bitwise operators aren't allowed. – kukac67 – 2014-04-10T16:56:37.750

Oh, they're not. Well, there goes my hypothetical solution. That said, if bitwise operators aren't allowed, is there even much else to do than count lengths of strings? – Llamageddon – 2014-04-10T16:57:55.803

There are several answers that use numbers in different bases. – kukac67 – 2014-04-10T16:58:48.983

You could use say instead of print. – simbabque – 2014-04-15T17:08:56.353

Yeah, but use feature 'say' adds a lot more bytes. – mob – 2014-04-15T17:27:12.370

You could explicitly state that you're using Perl 6. – nyuszika7h – 2014-04-21T12:24:49.297

4

Mathematica - 78

DateList["March"<>ToString@FromDigits@"E"]~DateString~{"MonthShort",".","Day"}

swish

Posted 2014-04-10T15:55:00.920

Reputation: 7 484

In the spirit of Pi Day! :D – kukac67 – 2014-04-10T17:01:52.633

4

tr + Bash, 17 bytes

tr a-j 0-9<<<d.be

The - chars here are not arithmetic subtraction operators. They indicate range.

Output:

$ tr a-j 0-9<<<d.be
3.14
$

Digital Trauma

Posted 2014-04-10T15:55:00.920

Reputation: 64 644

Clever, although a character translation is really hidden arithmetics. – Pierre Arlaud – 2014-04-11T12:41:36.683

@ArlaudPierre True, though I would contend that pretty much all solutions here have hidden arithmetic one way or another. If you look at the actual machine instructions executed for any of these answers, I would think all have some bitwise or arithmetic instructions, which are banned from explicit use by the question. – Digital Trauma – 2014-04-11T17:09:49.217

@ArlaudPierre The question requires the string "3.14" to be output. Regardless of the language, somewhere under the hood, this will degenerate to a write() call or similar. There will necessarily be some arithmetic under the covers to ensure the correct number of bytes is written, if nowhere else. I think the point of the question is to hide the necessary arithmetic/bitwise computations. – Digital Trauma – 2014-04-11T17:14:17.180

4

BASH, 57

This is longer than most answers, but there is nothing bad in trying.

f=`echo aaaaaaaaaaaaa|wc -c`;e=`echo aa|wc -c`;echo $e.$f

gives

3.14

Registered User

Posted 2014-04-10T15:55:00.920

Reputation: 297

3Sorry for re-golfing everyone's answers :P, In the same vein as this I found: c=wc\ -c;echo \$c<<<..`.`$c<<<''``$c<<<...`` – Score_Under – 2014-04-12T00:07:22.497

4

C, 36

main(){printf("%d\b.%o\b",' ','`');}

user19057

Posted 2014-04-10T15:55:00.920

Reputation: 311

1If we combine it with my answer, we can save 2 bytes to get a score of 34 : main(){printf("%d\b.%d",' ',0xe);} – vsz – 2014-04-11T19:28:23.030

3

JavaScript - 23 bytes

atob('Mw')+atob('LjE0')

Thanks to nderscore (see his comments)!

ComFreek

Posted 2014-04-10T15:55:00.920

Reputation: 376

Nice :D I didn't even know about this – kukac67 – 2014-04-10T16:46:31.917

It contains 4 though ;) – nderscore – 2014-04-10T16:48:57.713

@nderscore Ah! You're right! Would btoa() work to get 3.14 somehow? – kukac67 – 2014-04-10T16:52:38.307

@kukac67 The base64 character set doesn't contain a period :( – nderscore – 2014-04-10T16:54:33.970

@nderscore Oh, that's too bad. The ascii codes for '4' also include '4' :( Let me think of other solutions...

– ComFreek – 2014-04-10T17:21:41.560

atob('IDMuMTQ=') if the asker allows a leading space, atob('IDMuMTQ=').substring(1), if they do not. EDIT: Doh! a 1! atob("ICAzLjE0").substring(2). – aebabis – 2014-04-10T17:34:44.697

@acbabis slice is shorter than substring: atob('IDMuMTQ=').slice(1) – nderscore – 2014-04-10T17:35:52.470

@nderscore Neat – aebabis – 2014-04-10T17:37:57.750

323 byte "legal" version: atob('Mw')+atob('LjE0') and 14 byte "illegal" version: atob("My4xNA") – nderscore – 2014-04-10T17:41:16.550

@nderscore Thanks for the suggestion. I've just found atob('Mw')+'.'+0xE, however, I also just saw your edit ;) I'm not sure whether I may incorporate your comment into my answer. – ComFreek – 2014-04-10T18:23:06.467

Go ahead, it was your idea originally :) – nderscore – 2014-04-10T18:23:57.370

No + allowed, if I interpret the rules correctly :( – aebabis – 2014-04-11T16:56:08.360

@acbabis No arithmetic operations (e.g. using '+') are allowed, however, '+' represents string concatenation in this case. – ComFreek – 2014-04-11T16:57:19.453

Aight, just making sure. – aebabis – 2014-04-11T16:59:47.063

3

GolfScript, 13 10

{xy}.*'.'\

Thanks to Ilmari Karonen for the improved version!

x and y are non-printable characters (see http://www.asciitable.com/ for more info), respectively ETX and SO, which decode to 3 and 14.

What this code does should be pretty clear.

Note: The following rule

You may not use any predefined variables/constants that your language may have as a replacement for 3, 1, and 4. (Author's discretion)

is not broken, since ASCII characters are neither variables, nor constants.

Vereos

Posted 2014-04-10T15:55:00.920

Reputation: 4 079

The digits 3, 1, and 4 may not appear anywhere in your code. , Your program cannot require input of any kind (besides running it). – user80551 – 2014-04-11T10:41:16.147

The digits do not appear anywhere. There's no input. – Vereos – 2014-04-11T10:41:38.473

And your final code is...? – user80551 – 2014-04-11T10:42:08.420

{}.*.{}.*, and inside the brackets there are 2 non-printable characters, respectively (http://www.asciitable.com/) ETX and SO – Vereos – 2014-04-11T10:43:52.703

Oh, I think it's ok then but you should rephrase the answer to mention ETX and SO instead of just 3 and 14 in ASCII which can be ambiguous. – user80551 – 2014-04-11T10:49:00.560

Yeah, you're right. Better now? – Vereos – 2014-04-11T10:51:49.897

2

You could shorten this to {xy}.*'.'\ (10 chars). Mine's still shorter, though. ;-) But +1 for teaching me about { }.* (and { }.%), I'll have to keep that trick in mind.

– Ilmari Karonen – 2014-04-11T17:51:17.617

Brilliant! :D Thank you :) – Vereos – 2014-04-14T07:09:44.360

3

C#

 ((int)'ĺ').ToString("#\\.##");

ĺ is character 314, not a pre-defined variable or constant. the .ToString formats the output into a digit, a period, and then 2 more digits.

Grax32

Posted 2014-04-10T15:55:00.920

Reputation: 1 282

Nice, but it currently doesn't output, and it's not compilable. – Rudi Kershaw – 2014-04-16T09:27:31.583

Console.Write(((int)'ĺ').ToString("#\.##")); – Grax32 – 2014-04-16T11:24:35.440

3

New to the site and can't write comments yet, so I'll post it here. Just wondering about this Javascript solution:

'...'.length+'.'+0xe

and this rule:

3.14 is the only thing that you may output, it cannot be part of some longer/larger output..

If I run this code in my browser console, I get:

"3.14"

or using Node at the command line:

'3.14'

but if I run this code:

parseFloat('...'.length+'.'+0xe)

I get:

3.14

Using Node.js to run a .js file, I can write:

console.log('...'.length+'.'+0xe)

and get:

3.14

Robert Munn

Posted 2014-04-10T15:55:00.920

Reputation: 131

1There was never a limitation on what type the resulting value can be. So, string or number doesn't matter. The quotes around the string are not considered part of the output. – nderscore – 2014-04-14T19:53:08.700

Welcome to CodeGolf and Programming Puzzles @RobertMunn! This answer is valid as it obeys all the rules... Bear in mind that console tends to wrap strings in quotes when displaying them... You have used + but not arithmetically, it's being used as a concatenator, so that's valid... Also you could have made this smaller using alert rather than console.log... But otherwise, great effort. We hope you like it here... – WallyWest – 2014-04-15T02:58:32.697

That's pretty nice! You should consider adding the name of the language and byte count (e.g. Javascript, 20) – Vereos – 2014-04-15T07:32:53.260

1Thanks Ace, I'm just learning the rules here. I couldn't leave a comment so I posted separately, I guess this was more of a clarification on the rules kind of post, which nderscore and WallyWest clarified for me. I appreciate everyone's patience with a newb. – Robert Munn – 2014-04-15T18:43:35.557

2

Mathematica, 56 bytes

(l=ToString@StringLength@#&)@"..."<>"."<>l@"."<>l@"...."

Not much to say. I'm generating the digits as string lengths and concatenate them.

Martin Ender

Posted 2014-04-10T15:55:00.920

Reputation: 184 808

2

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)

user80551

Posted 2014-04-10T15:55:00.920

Reputation: 2 520

3Title:"Output Pi without math". First line:from cmath import :P. – Blackhole – 2014-04-10T17:31:07.170

1@Blackhole But it's not an explicit bullet-point in the rules. – user80551 – 2014-04-10T17:31:58.730

Yeah... phase disqualifies this. – kukac67 – 2014-04-10T19:17:48.980

@kukac67 Is the other answer acceptable? – user80551 – 2014-04-11T07:03:29.680

If it were valid, though, -2+0j would save 6 characters. – Ry- – 2014-04-11T14:14:11.767

@minitech Even shorter – user80551 – 2014-04-11T14:47:07.743

@user80551 Yes the other answer is valid, I used ranges myself in my Mathematica answer. :) – kukac67 – 2014-04-11T14:50:34.707

2

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.

Digital Trauma

Posted 2014-04-10T15:55:00.920

Reputation: 64 644

2

Perl, 22 bytes

print pack N,858665268

Heiko Oberdiek

Posted 2014-04-10T15:55:00.920

Reputation: 3 841

2

BF,45 chars(without \n)

How About BF

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

thanks for pointing out that it only needs 3.14

YukiNyaa

Posted 2014-04-10T15:55:00.920

Reputation: 21

12Hm... aren't all those + and - signs incrementing and decrementing? – kukac67 – 2014-04-11T00:45:06.517

Yeah, it's impossible to write a nontrivial BF program that satisfies the guidelines. – David Z – 2014-04-11T02:02:14.423

I think that outputs 3.41592 rather than just 3.14 as required... (bf interpreter on Ubuntu 13.10) – None – 2014-04-11T14:17:46.253

You can write ++++++++++[>+++++<-]>+.-----.+++.+++. and save 8 chars :P – Vereos – 2014-04-14T08:33:47.687

2

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.

user16402

Posted 2014-04-10T15:55:00.920

Reputation:

There is a much shorter answer using seq http://codegolf.stackexchange.com/a/25732/8766

– user80551 – 2014-04-11T11:23:59.663

2

PowerShell - 47 24 20

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

'{0:#\.##}'-f+"ĺ"[0]  

Rynant

Posted 2014-04-10T15:55:00.920

Reputation: 2 353

2

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

premek.v

Posted 2014-04-10T15:55:00.920

Reputation: 23

2

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.

Abulafia

Posted 2014-04-10T15:55:00.920

Reputation: 141

1

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.

user16402

Posted 2014-04-10T15:55:00.920

Reputation:

This is just pure evil. – AJMansfield – 2014-04-15T22:43:18.577

1

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.

cyriel

Posted 2014-04-10T15:55:00.920

Reputation: 431

+1 Did you figure out the longer version all by yourself without using any program? – user80551 – 2014-04-11T10:51:18.970

It's from wiki - http://en.wikipedia.org/wiki/Piphilology :)

– cyriel – 2014-04-11T11:45:42.753

1

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

NorthBridge

Posted 2014-04-10T15:55:00.920

Reputation: 191

1

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

vsz

Posted 2014-04-10T15:55:00.920

Reputation: 7 963

1

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

Lucy Lauser

Posted 2014-04-10T15:55:00.920

Reputation: 19

I think if you check the source of Form1.designer.vb you will see 3.14 in your code. – nderscore – 2014-04-15T05:58:25.617

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. – Lucy Lauser – 2014-04-15T20:59:08.090

Ah I'm stupid for not reading that it was a picture box. – nderscore – 2014-04-15T21:01:38.557

1

Oracle SQL,56

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

Output:

3.14

Toni Toni Chopper

Posted 2014-04-10T15:55:00.920

Reputation: 131

1

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

elimirks

Posted 2014-04-10T15:55:00.920

Reputation: 111

1

Java, 65

System.out.println("abc".length()+"."+"abcdefghijklmn".length());

Mudit Agarwal

Posted 2014-04-10T15:55:00.920

Reputation: 19

clever​​​​​​​​​! – Mhmd – 2014-04-16T12:02:22.617

You could cut this down a bit more: new int[3].length+"."+new int[14].length – elimirks – 2014-04-16T15:41:15.287

How'z it getting 65?? I am not getting this!! – Mudit Agarwal – 2014-04-16T17:59:00.080

@elimirks I cant as its mentioned in wuestion that I cannot use '1','3' and '4' – Mudit Agarwal – 2014-04-22T11:23:43.743

0

Tcl, 28

puts [scan ^C %c].[scan ^N %c]

^C and ^N are one byte. Each one is obtained by pressing Alt+03 and Alt+014. They correspond to ASCII control chars ♥ and ♫

sergiol

Posted 2014-04-10T15:55:00.920

Reputation: 3 055

0

JavaScript, 32 bytes

'3.14'.normalize('NFKD')

Not sure if it is valid, and it also not the shortest. But post this just for fun since did not find a similar one.

tsh

Posted 2014-04-10T15:55:00.920

Reputation: 13 072

0

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

mattnewport

Posted 2014-04-10T15:55:00.920

Reputation: 1 579

0

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

CompuChip

Posted 2014-04-10T15:55:00.920

Reputation: 439

You could save 3 bytes by caching the name of the length property: (a="a+b")[L="length"]+(b=".")+b[L]+(a+b)[L] – nderscore – 2014-04-14T20:49:29.580

Cool, didn't know that trick. Thanks @nderscore! – CompuChip – 2014-04-15T06:43:00.157

0

Java, 106 95

class A{public static void main(String[]a){System.out.print((""+(int)'ཊ').replace('9','.'));}}

user902383

Posted 2014-04-10T15:55:00.920

Reputation: 1 360

You can shorten this by 10: class A{public static void main(String[]a){System.out.print((""+(int)'ཊ').replace('9','.'));}} – kukac67 – 2014-04-12T23:00:10.663

0

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

Dharman

Posted 2014-04-10T15:55:00.920

Reputation: 101

0

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

Vovanium

Posted 2014-04-10T15:55:00.920

Reputation: 286

0

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

skataben

Posted 2014-04-10T15:55:00.920

Reputation: 101

0

C 71

int main(){printf("%d.%d%d",strlen("***"),strlen("*"),strlen("****"));}

bacchusbeale

Posted 2014-04-10T15:55:00.920

Reputation: 1 235

0

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)'');}}

Rudi Kershaw

Posted 2014-04-10T15:55:00.920

Reputation: 121

0

ksh 19

echo ${#0}.$((0xe))
3.14

F. Hauri

Posted 2014-04-10T15:55:00.920

Reputation: 2 654

0

Brainfuck - 39

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

Note that + and - are not arithmetic operators.

nyuszika7h

Posted 2014-04-10T15:55:00.920

Reputation: 1 624

+ and - increment and decrement. – L3viathan – 2017-04-02T13:44:32.940

Hmm, you have a point there. I didn't think of that when writing the answer. – nyuszika7h – 2017-04-06T12:59:10.997

0

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

daviewales

Posted 2014-04-10T15:55:00.920

Reputation: 271

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) – caird coinheringaahing – 2017-04-02T12:26:30.137

0

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

'=~~,~~~~~,~~~~~:@'+~:@'-~~~~:@'-~:@'+~~

cjfaure

Posted 2014-04-10T15:55:00.920

Reputation: 4 213

0

Object disoriented - 72 characters

dmain.ozozososozozososozozosozosososozozozososozozozosozozososozosozozzz

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

Oberon

Posted 2014-04-10T15:55:00.920

Reputation: 2 881

0

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.

Muqo

Posted 2014-04-10T15:55:00.920

Reputation: 499

0

TinyMUSH, 16

This entry assumes decrypt() is allowed.

\decrypt(A<?B,.)

Muqo

Posted 2014-04-10T15:55:00.920

Reputation: 499