Timeline for Print number triangle
Current License: CC BY-SA 3.0
19 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 17, 2020 at 9:04 | history | edited | CommunityBot |
Commonmark migration
|
|
May 31, 2017 at 16:56 | history | edited | Taylor Raine | CC BY-SA 3.0 |
formatting
|
Apr 13, 2017 at 12:39 | history | edited | CommunityBot |
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
|
|
Mar 15, 2015 at 21:21 | comment | added | avall |
@Austin this can be done by changing @$i++= to @++$i<= so only one character must be added.
|
|
Mar 15, 2015 at 21:18 | comment | added | avall |
You can save 3 bytes removing unnecessary $n= in loop condition.
|
|
Mar 15, 2015 at 6:13 | comment | added | Austin |
@BenoitEsnard You have to do $argv[1]*1 or $argv[1]+0 , otherwise it will print 1 if you give it 0 when it is supposed to print nothing. At least, that's what happens in PHP 5.5.
|
|
Mar 15, 2015 at 1:55 | comment | added | Ismael Miguel |
I have a shorter one for you, but only for PHP 4: for($a=1;@$i++<$n=$N;$a.=" ".($i+print"$a\n")); , pass the URL parameter N=x . This works only on PHP<4.2 because of the directive register_globals (php.net/manual/en/ini.core.php#ini.register-globals) which automatically registers the variables in $_POST , $_GET and so on to the current code automatically. $_GET['Z'] will be registed as the variable $Z . This value defaults to on on those old versions. To work for PHP<5.3, you have to create a php.ini file with register_globals=on
|
|
Mar 14, 2015 at 22:56 | comment | added | Benoit Esnard |
@IsmaelMiguel: I've edited the answer with your idea. Using $argv[1] is better for the no-error version. Too bad we can't use $argc directly.
|
|
Mar 14, 2015 at 22:50 | history | edited | Benoit Esnard | CC BY-SA 3.0 |
added 424 characters in body
|
Mar 14, 2015 at 22:32 | comment | added | Ismael Miguel |
for($a=1;$i++<$n=$_GET[n];$a.=" ".($i+print"$a\n")); --> try this (full code, using url parameter n with the number)
|
|
Mar 13, 2015 at 23:59 | history | edited | Benoit Esnard | CC BY-SA 3.0 |
added 375 characters in body
|
Mar 13, 2015 at 23:53 | history | edited | Benoit Esnard | CC BY-SA 3.0 |
added 375 characters in body
|
Mar 13, 2015 at 20:10 | comment | added | Austin | Sure, go for it. | |
Mar 13, 2015 at 10:24 | comment | added | Benoit Esnard | Indeed. Are you OK if I edit my answer to add your solution? | |
Mar 13, 2015 at 10:19 | comment | added | Austin |
Ah ok, then I suppose you would do function f($n){for($a=1;@$i++<$n;$a.=" ".($i+print"$a\n"));} , which is 60 bytes.
|
|
Mar 13, 2015 at 9:29 | comment | added | Benoit Esnard |
@Austin: I've read in a comment that the code must be either a full program reading from input, or a function. Very nice trick, it can be improved by a bit / byte: for($a=1;@$i++<$n;$a.=" ".($i+print"$a\n")); (44 bytes)
|
|
Mar 13, 2015 at 8:14 | comment | added | Austin |
45 bytes: for($a=1;@$i<$n;$a.=" ".(@++$i+print"$a\n"));
|
|
Mar 12, 2015 at 14:59 | review | First posts | |||
Mar 12, 2015 at 15:54 | |||||
Mar 12, 2015 at 14:49 | history | answered | Benoit Esnard | CC BY-SA 3.0 |