| Bytes | Lang | Time | Link |
|---|---|---|---|
| 000 | 05AB1E producing HTML | 250903T060445Z | Adá |
| nan | APL producing HTML | 250902T092821Z | Adá |
| nan | Python 3.8 prerelease | 250902T105512Z | V_R |
| 168 | A naive example in Python that produces Python — | 250902T055809Z | ACertain |
05AB1E producing HTML, score 0
In 05AB1E, the empty program takes input and outputs it verbatim (example). Since none of the paragraphs contain < or & or multiple consecutive spaces, then the output is valid HTML that will produce itself (a trivial quine).
APL producing HTML, score 10896.1
(Score is \$\text{len}(f_\text{main})×(\sum_{i=1}^{100}{\text{len}(f_\text{main}(p_i))\over100})^{1.5}\$.)
⍞
This prompts for a line of input and outputs it verbatim (example). Since none of the paragraphs contain < or & or multiple consecutive spaces, then the output is valid HTML that will produce itself (a trivial quine).
Python 3.8 (pre-release), score 465379.4785138254 (39 bytes, Python producing Python)
If it ain't broke, don't fix it.
print(f"print('''{input()}''',end='')")
Testing script (not part of challenge, only tiny changes from OP's)
import subprocess
import io
import sys
with open("golf.py", "r") as f:
size_of_program = len(f.read())
def run_program(cmd, input_str=""):
result = subprocess.run(
cmd,
input=input_str.encode(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True
)
return result.stdout.decode()
def execute_python_with_stdout_capture(python_code, input_str=""):
output_buffer = io.StringIO()
sys.stdout = output_buffer
exec(python_code, {'input': lambda: input_str})
sys.stdout = sys.__stdout__
captured_output = output_buffer.getvalue()
output_buffer.close()
return captured_output
if __name__ == "__main__":
with open("para.txt", "r", encoding="utf-8") as f:
file_content = f.readlines()
total = 0
for line in file_content:
line = line.strip()
output = run_program("python golf.py", line)
code_output = execute_python_with_stdout_capture(output)
if code_output!=line:
print(f"{code_output}\n{line}")
raise ValueError("Mismatch! Your program did not output the expected result and does not qualify!")
total+=len(output)
score = size_of_program*((total/100)**1.5)
output = run_program("python golf.py")
print("Your program works! Score:", score)
```
A naive example in Python that produces Python — (168 bytes; score is 1667263.6473830533)
import zlib,base64;print(f"import zlib,base64;print(zlib.decompress(base64.b85decode('{base64.b85encode(zlib.compress(input().encode())).decode()}')).decode(),end='')")
Testing script (not part of challenge)
import subprocess
import io
import sys
with open("golf.py", "r") as f:
size_of_program = len(f.read())
def run_program(cmd, input_str=""):
result = subprocess.run(
cmd,
input=input_str.encode(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True
)
return result.stdout.decode()
def execute_python_with_stdout_capture(python_code, input_str=""):
output_buffer = io.StringIO()
sys.stdout = output_buffer
exec(python_code, {'input': lambda: input_str})
sys.stdout = sys.__stdout__
captured_output = output_buffer.getvalue()
output_buffer.close()
return captured_output
if __name__ == "__main__":
with open("para.txt", "r") as f:
file_content = f.readlines()
total = 0
for line in file_content:
line = line.strip()
output = run_program("python3 golf.py", line)
code_output = execute_python_with_stdout_capture(output)
if code_output!=line:
print(f"{code_output}\n{line}")
raise ValueError("Mismatch! Your program did not output the expected result and does not qualify!")
total+=len(output)
score = size_of_program*((total/100)**1.5)
output = run_program("python3 golf.py")
print("Your program works! Score:", score)
```