Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Code-golf is a competition to solve a particular problem in the fewest bytes of source code.
0
votes
Implement a Truth-Machine
PHP, 24 25 27 bytes
<?=do{echo$i;}while($i); // Also 24b
<?=$i;for(;$i&1;)echo$i; // 24b, added PHP's short echo, actually made it less
echo$i;for(;$i&1;)echo$i; // 25b
echo$i;while($i&1)echo$i; // 2 …
0
votes
Print the relative path
PHP, 158 151
function r($a,$b){$a=explode('/',$a);$b=explode('/',$b);foreach($a as $k=>$v){if($v==$b[$k])$b[$k]='..';else break;}unset($b[0]);echo implode('/',$b);}
Ungolfed:
function r($a,$b){
…
0
votes
Multiply all numbers in a string
PHP - 75/115 68/109
Two versions, newer php versions can do this:
echo preg_replace_callback("/\d+/",function($m){return$m[0]*$f;},$s);
Older php versions: I did not count the newline, added those …
2
votes
Retina or Trash?
PHP, 47,43,40 38 bytes
<?=sqrt($w*$w+$h*$h)/$d>300?'Retina':'Trash'?>!
<?=sqrt($w*$w+$h*$h)/$d>300?Retina:Trash?>!
<?=$w*$w+$h*$h>9e4*$d*$d?Retina:Trash?>!
<?=hypot($w,$h)/$d>300?Retina:Trash?> …
1
vote
Shortest infinite loop producing no output
PHP, 10 8 bytes
The for(;;) solution has been posted enough, Time for this one:
while(1)
while(1){}
16
votes
Play the "bzzt" game
PHP, no separator - 62, 61,59,58,52,49 47
It doesn't say there should be a space/newline/separator between them, without:
while(++$i<501)echo$i%3*!strpbrk($i,3)?$i:bzzt;
With the separator, 68,67, …
7
votes
Legen… wait for it…
PHP, 76, 70, 65, 62 51 bytes
Legen... wait for it...
<?while(+date(is));?>dary!
Previous logic (63b):
Legen... wait for it...
<?for($h=date(G);date(G)==$h;)?>dary!
This kind of coding makes you loos …
1
vote
Count up folks!
PHP, 26 23 31 bytes
<?=join(' ',range(1,$argv[1])); // 31 if using N isnt allowed
<?=join(' ',range(1,$n)); // 25 if using $n is allowed
<?=join(' ',range(1,N)); // 24 bytes, join() is an alias o …
1
vote
How much do I have to write?
PHP, 38 35 bytes
<?=strlen(join(range(0,$argv[1]))); // 35 bytes
<?=strlen(join("",range(0,$argv[1]))); // 38 bytes
Useage: php file.php 8
The join is a little used alias of implode(), and php can ea …
0
votes
Pi got your number
PHP, 27 bytes
Not a very serieus answer, it requires a change in the php.ini settings as pi() defaults to 14 digits, not 200, but for once the PHP solution is fairly elegant:
<?=strpos(pi(),$_GET[n])- …
0
votes
The shortest code to invert bit-wise a binary string
php, 41 bytes
Where $s is the string:
str_replace(array(1,0,2),array(2,1,0),$s)
This works because the str_replace() function is just a loop when given an array. This works like this:
replace al …
6
votes
Draw an ASCII Lightning Bolt
PHP - 84 79 78 bytes
<?php
define('N',3); // <- didnt count these bytes as TS said I could take var N as input
?>
<?="__
\ \
\ \ ".str_repeat("
__\ \
\ __\
\ \ ",N-1)."
\ \
\/"
View the re …
2
votes
Don't google "google"
PHP error via a warning(), 62, 52 46 bytes
I feel dirty for these, but it isn't about pretty:
function g($s){echo$s!=google?strlen($s):g();}
This will give "Warning: Missing argument 1 for g()" wh …
2
votes
I reverse the source code, you negate the output!
PHP, 10 bytes.
Not very special, but it's rare for PHP to be short :)
<?=1#1-=?<
2
votes
Create output twice the length of the code
PHP, 56-25 = 31 bytes
I wanted one where size of the code doesn't matter:
<?=str_repeat(file_get_contents(__FILE__),$n!=''?$n:2)?>
Or a more modern version:
<?=str_repeat(file_get_contents(__FILE__), …