Skip to main content
Code Golf

Return to Question

Commonmark migration
Source Link

I had a few discussions regarding to use or not to use STDIN in answer written in PHP. Reading from STDIN is very expensive in PHP consuming 12 bytes:

fgetc(STDIN) // single character
fgets(STDIN) // whole line

##Different wordings in requirements##

Different wordings in requirements

From Implement a Truth Machine

  • take input from STDIN or an acceptable alternative
  • If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program

My answer was discussed by Martin Büttner as I used a command line argument instead. Another answer ignored the requirements completely and the OP argued:

I went for "or an acceptable alternative". I figured it's about the technique, not forcebly use STDIN. This is one of the very few 'keep the code shorter' tricks PHP can use, especially compared to the other languages


From Write a Program that Writes a function BUT in a different language!

Write the shortest program that takes one input (n) from STDIN (or equivalent) [...]

My answer using STDIN was also discussed:

Why not just x=>x+<?=$x;? It's valid PHP4.1 and you can pass the values over POST, GET, SESSION, COOKIE, ... and it will work flawlessly. Or on PHP5.3 with register_globals=on (on your php.ini file).


##My questions##

My questions

Keeping in mind that STDIN is available in PHP.

  • Do you need to read from STDIN in requirements like from STDIN or an acceptable alternative or is any other method acceptable?
  • Is a command line argument an acceptable alternative to STDIN in?
  • Is using register_globals=on acceptable?

If the last two methods are in fact acceptable, then all PHP answers could get rid of $argsv[n] and fget[c/s](STDIN) and simply use $a ... $n based on the amount of input values.


This question is narrowed to PHP but the answers may apply for other languages as well.


###Related###

Related

I had a few discussions regarding to use or not to use STDIN in answer written in PHP. Reading from STDIN is very expensive in PHP consuming 12 bytes:

fgetc(STDIN) // single character
fgets(STDIN) // whole line

##Different wordings in requirements##

From Implement a Truth Machine

  • take input from STDIN or an acceptable alternative
  • If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program

My answer was discussed by Martin Büttner as I used a command line argument instead. Another answer ignored the requirements completely and the OP argued:

I went for "or an acceptable alternative". I figured it's about the technique, not forcebly use STDIN. This is one of the very few 'keep the code shorter' tricks PHP can use, especially compared to the other languages


From Write a Program that Writes a function BUT in a different language!

Write the shortest program that takes one input (n) from STDIN (or equivalent) [...]

My answer using STDIN was also discussed:

Why not just x=>x+<?=$x;? It's valid PHP4.1 and you can pass the values over POST, GET, SESSION, COOKIE, ... and it will work flawlessly. Or on PHP5.3 with register_globals=on (on your php.ini file).


##My questions##

Keeping in mind that STDIN is available in PHP.

  • Do you need to read from STDIN in requirements like from STDIN or an acceptable alternative or is any other method acceptable?
  • Is a command line argument an acceptable alternative to STDIN in?
  • Is using register_globals=on acceptable?

If the last two methods are in fact acceptable, then all PHP answers could get rid of $argsv[n] and fget[c/s](STDIN) and simply use $a ... $n based on the amount of input values.


This question is narrowed to PHP but the answers may apply for other languages as well.


###Related###

I had a few discussions regarding to use or not to use STDIN in answer written in PHP. Reading from STDIN is very expensive in PHP consuming 12 bytes:

fgetc(STDIN) // single character
fgets(STDIN) // whole line

Different wordings in requirements

From Implement a Truth Machine

  • take input from STDIN or an acceptable alternative
  • If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program

My answer was discussed by Martin Büttner as I used a command line argument instead. Another answer ignored the requirements completely and the OP argued:

I went for "or an acceptable alternative". I figured it's about the technique, not forcebly use STDIN. This is one of the very few 'keep the code shorter' tricks PHP can use, especially compared to the other languages


From Write a Program that Writes a function BUT in a different language!

Write the shortest program that takes one input (n) from STDIN (or equivalent) [...]

My answer using STDIN was also discussed:

Why not just x=>x+<?=$x;? It's valid PHP4.1 and you can pass the values over POST, GET, SESSION, COOKIE, ... and it will work flawlessly. Or on PHP5.3 with register_globals=on (on your php.ini file).


My questions

Keeping in mind that STDIN is available in PHP.

  • Do you need to read from STDIN in requirements like from STDIN or an acceptable alternative or is any other method acceptable?
  • Is a command line argument an acceptable alternative to STDIN in?
  • Is using register_globals=on acceptable?

If the last two methods are in fact acceptable, then all PHP answers could get rid of $argsv[n] and fget[c/s](STDIN) and simply use $a ... $n based on the amount of input values.


This question is narrowed to PHP but the answers may apply for other languages as well.


Related

replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

I had a few discussions regarding to use or not to use STDIN in answer written in PHP. Reading from STDIN is very expensive in PHP consuming 12 bytes:

fgetc(STDIN) // single character
fgets(STDIN) // whole line

##Different wordings in requirements##

From Implement a Truth Machine Implement a Truth Machine

  • take input from STDIN or an acceptable alternative
  • If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program

My answer My answer was discussed by Martin Büttner Martin Büttner as I used a command line argument instead. Another answer Another answer ignored the requirements completely and the OP argued:

I went for "or an acceptable alternative". I figured it's about the technique, not forcebly use STDIN. This is one of the very few 'keep the code shorter' tricks PHP can use, especially compared to the other languages


From Write a Program that Writes a function BUT in a different language! Write a Program that Writes a function BUT in a different language!

Write the shortest program that takes one input (n) from STDIN (or equivalent) [...]

My answer My answer using STDIN was also discussed:

Why not just x=>x+<?=$x;? It's valid PHP4.1 and you can pass the values over POST, GET, SESSION, COOKIE, ... and it will work flawlessly. Or on PHP5.3 with register_globals=on (on your php.ini file).


##My questions##

Keeping in mind that STDIN is available in PHP.

  • Do you need to read from STDIN in requirements like from STDIN or an acceptable alternative or is any other method acceptable?
  • Is a command line argument an acceptable alternative to STDIN in?
  • Is using register_globals=on acceptable?

If the last two methods are in fact acceptable, then all PHP answers could get rid of $argsv[n] and fget[c/s](STDIN) and simply use $a ... $n based on the amount of input values.


This question is narrowed to PHP but the answers may apply for other languages as well.


###Related###

I had a few discussions regarding to use or not to use STDIN in answer written in PHP. Reading from STDIN is very expensive in PHP consuming 12 bytes:

fgetc(STDIN) // single character
fgets(STDIN) // whole line

##Different wordings in requirements##

From Implement a Truth Machine

  • take input from STDIN or an acceptable alternative
  • If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program

My answer was discussed by Martin Büttner as I used a command line argument instead. Another answer ignored the requirements completely and the OP argued:

I went for "or an acceptable alternative". I figured it's about the technique, not forcebly use STDIN. This is one of the very few 'keep the code shorter' tricks PHP can use, especially compared to the other languages


From Write a Program that Writes a function BUT in a different language!

Write the shortest program that takes one input (n) from STDIN (or equivalent) [...]

My answer using STDIN was also discussed:

Why not just x=>x+<?=$x;? It's valid PHP4.1 and you can pass the values over POST, GET, SESSION, COOKIE, ... and it will work flawlessly. Or on PHP5.3 with register_globals=on (on your php.ini file).


##My questions##

Keeping in mind that STDIN is available in PHP.

  • Do you need to read from STDIN in requirements like from STDIN or an acceptable alternative or is any other method acceptable?
  • Is a command line argument an acceptable alternative to STDIN in?
  • Is using register_globals=on acceptable?

If the last two methods are in fact acceptable, then all PHP answers could get rid of $argsv[n] and fget[c/s](STDIN) and simply use $a ... $n based on the amount of input values.


This question is narrowed to PHP but the answers may apply for other languages as well.


###Related###

I had a few discussions regarding to use or not to use STDIN in answer written in PHP. Reading from STDIN is very expensive in PHP consuming 12 bytes:

fgetc(STDIN) // single character
fgets(STDIN) // whole line

##Different wordings in requirements##

From Implement a Truth Machine

  • take input from STDIN or an acceptable alternative
  • If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program

My answer was discussed by Martin Büttner as I used a command line argument instead. Another answer ignored the requirements completely and the OP argued:

I went for "or an acceptable alternative". I figured it's about the technique, not forcebly use STDIN. This is one of the very few 'keep the code shorter' tricks PHP can use, especially compared to the other languages


From Write a Program that Writes a function BUT in a different language!

Write the shortest program that takes one input (n) from STDIN (or equivalent) [...]

My answer using STDIN was also discussed:

Why not just x=>x+<?=$x;? It's valid PHP4.1 and you can pass the values over POST, GET, SESSION, COOKIE, ... and it will work flawlessly. Or on PHP5.3 with register_globals=on (on your php.ini file).


##My questions##

Keeping in mind that STDIN is available in PHP.

  • Do you need to read from STDIN in requirements like from STDIN or an acceptable alternative or is any other method acceptable?
  • Is a command line argument an acceptable alternative to STDIN in?
  • Is using register_globals=on acceptable?

If the last two methods are in fact acceptable, then all PHP answers could get rid of $argsv[n] and fget[c/s](STDIN) and simply use $a ... $n based on the amount of input values.


This question is narrowed to PHP but the answers may apply for other languages as well.


###Related###

replaced http://meta.codegolf.stackexchange.com/ with https://codegolf.meta.stackexchange.com/
Source Link
replaced http://meta.codegolf.stackexchange.com/ with https://codegolf.meta.stackexchange.com/
Source Link
Loading
edited tags
Link
Alex A. Mod
  • 24.8k
  • 4
  • 55
  • 91
Loading
Source Link
Loading

AltStyle によって変換されたページ (->オリジナル) /