Timeline for Giving Directions
Current License: CC BY-SA 3.0
29 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 19, 2015 at 14:43 | history | edited | jrenk | CC BY-SA 3.0 |
saved bytes
|
Aug 18, 2015 at 14:54 | comment | added | The_Basset_Hound | Nicely done! I'd help, but I don't know PHP. | |
Aug 18, 2015 at 12:59 | history | edited | jrenk | CC BY-SA 3.0 |
fixed bug
|
Aug 18, 2015 at 12:52 | history | edited | jrenk | CC BY-SA 3.0 |
fixed bug
|
Aug 18, 2015 at 11:52 | comment | added | jrenk | @axiac Thanks for the help. I just removed the last semicolon of the script. Did you mean it that way? ... I will add an example of usage for my code soon. | |
Aug 18, 2015 at 11:51 | history | edited | jrenk | CC BY-SA 3.0 |
saved 8 bytes
|
Aug 18, 2015 at 11:05 | comment | added | axiac |
Ten more bytes: 1) don't count the trailing newline (your current code has 337 bytes); 2) remove the space before as in fgets(STDIN)) as$i ; 3) remove the empty statement at the end of the program (the very last semicolon); 4-7) remove the braces from else{if($i=='|')$s=F;else{$s=($i=='\\')?L:$s;}} ; 8-10) remove if($i==' ')continue; and use strtr() to remove the whitespaces from the input instead: foraeach(str_split(strtr(fgets(STDIN),[' '=>'']))as$i) .
|
|
Aug 18, 2015 at 11:05 | comment | added | axiac |
I copy-pasted the first example and it came out with newlines. You should provide an example of usage. I run the code now using: cat 1.txt | tr '\n', ' ' | php -d error_reporting=0 script.php and it works.
|
|
Aug 18, 2015 at 10:02 | history | edited | jrenk | CC BY-SA 3.0 |
saved bytes
|
Aug 18, 2015 at 9:59 | comment | added | jrenk | @axiac If you copy paste the examples from the question it will output the expected result. If you want to try your own example you need to use white spaces instead of line breaks. | |
Aug 18, 2015 at 9:58 | comment | added | axiac |
Hmm... fgets(STDIN) reads only the first line. The program doesn't output anything.
|
|
Aug 18, 2015 at 9:57 | comment | added | Kamehameha |
You can try replacing if($i=='\\')$s=L;else $s=''; with this - $s=($i=='\\')?L:$s; . Saves 10 bytes.
|
|
Aug 18, 2015 at 9:50 | history | edited | jrenk | CC BY-SA 3.0 |
log
|
Aug 18, 2015 at 9:45 | comment | added | axiac |
You can still save a dozen of bytes or more: eliminate the intermediate variables $e and $f (they are initialized then used only once); use D (constant) instead of 'D' (string); PHP will complain about not finding the constant D and will use the string 'D' instead; you can suppress the notices by invoking PHP from the command line as php -d error_reporting=0 script.php .
|
|
Aug 18, 2015 at 9:43 | history | edited | jrenk | CC BY-SA 3.0 |
changed ungolfed version
|
Aug 18, 2015 at 9:33 | history | edited | jrenk | CC BY-SA 3.0 |
saved 1 byte
|
Aug 18, 2015 at 9:26 | history | edited | jrenk | CC BY-SA 3.0 |
changed ungolfed version
|
Aug 18, 2015 at 9:11 | comment | added | jrenk | Thanks for the tips! I changed quite a few things... I will edit the ungolfed Version soon to clear things up! | |
Aug 18, 2015 at 9:10 | history | edited | jrenk | CC BY-SA 3.0 |
saved bytes
|
Aug 18, 2015 at 8:56 | comment | added | Dom Hastings |
A couple more tips to save a few bytes, as @ProgramFox mentioned about the as in the foreach , the spaces between echo and the variable name can be removed to so you have echo$b . Also, a couple of equality tests can be shorter too, $c==0 could be !$c and if that's the case, you can initialise $c to '' with $a and $b !
|
|
Aug 18, 2015 at 8:39 | comment | added | ProgramFOX |
I don't know PHP very well, but I believe you can drop the space after "as" in your foreach (foreach($e as$i) ); I have tested that and it appears to work fine.
|
|
Aug 18, 2015 at 8:00 | history | edited | jrenk | CC BY-SA 3.0 |
saved bytes
|
Aug 18, 2015 at 7:56 | comment | added | Kamehameha |
Also, concatenation like $a=$a.'L '; can be reduced to $a.='L ' . You seem to have done that in a couple of places. That'll save around 6 bytes :)
|
|
Aug 18, 2015 at 7:55 | history | edited | jrenk | CC BY-SA 3.0 |
saved 3 bytes
|
Aug 18, 2015 at 7:53 | comment | added | Kamehameha |
You can try $a=$b=''; instead of - $a='';$b=''; Saves around 3 bytes.
|
|
Aug 18, 2015 at 7:46 | history | edited | jrenk | CC BY-SA 3.0 |
added ungolfed version
|
Aug 18, 2015 at 7:36 | comment | added | isaacg | Welcome to the site! | |
Aug 18, 2015 at 7:33 | review | First posts | |||
Aug 18, 2015 at 8:39 | |||||
Aug 18, 2015 at 7:29 | history | answered | jrenk | CC BY-SA 3.0 |