<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<!-- question: 96598  -->
  <question type="coderunner">
    <name>
      <text>PROTOTYPE_KotlinElements</text>
    </name>
    <questiontext format="html">
      <text><![CDATA[<p>Kotlin Prototyp für Code-Elemente.</p>
<p>Damit sind Klassen und Funktionen gemeint, also alles was auf Top-Level stehen kann.</p>
<p>Test wird zusammengebaut aus:</p>
<ul>
<li>test_extra (top-level)</li>
<li>studentanswer (top-level)</li>
<li>testcode (in main)</li>
</ul>
<p>main wird dann ausgeführt.</p>]]></text>
    </questiontext>
    <generalfeedback format="html">
      <text></text>
    </generalfeedback>
    <defaultgrade>1</defaultgrade>
    <penalty>0</penalty>
    <hidden>0</hidden>
    <idnumber></idnumber>
    <coderunnertype>kotlin-elements</coderunnertype>
    <prototypetype>2</prototypetype>
    <allornothing>1</allornothing>
    <penaltyregime>10, 20, ...</penaltyregime>
    <precheck>0</precheck>
    <hidecheck>0</hidecheck>
    <showsource>0</showsource>
    <answerboxlines>18</answerboxlines>
    <answerboxcolumns>100</answerboxcolumns>
    <answerpreload></answerpreload>
    <globalextra></globalextra>
    <useace>1</useace>
    <resultcolumns></resultcolumns>
    <template><![CDATA[import subprocess
import sys
import os

# 1. Twig-Variablen abrufen
student_answer = """{{ STUDENT_ANSWER | e('py') }}"""
test_code = """{{ TEST.testcode | e('py') }}"""
test_extra = """{{ TEST.extra | e('py') }}"""

# 2. Code zusammenbauen (STRUKTURÄNDERUNG)
# Schülerantwort steht oben (Top-Level), Testcode steht in der main-Funktion
full_code = test_extra + "\n\n" + student_answer + "\n\nfun main(args: Array<String>) {\n" + test_code + "\n}"

with open("Solution.kt", "w") as src:
    src.write(full_code)

# Hilfsfunktion zum Filtern der JVM-Warnungen (beibehalten)
def run_and_filter(cmd):
    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
    stdout, stderr = proc.communicate()
    
    # Filtert die bekannten OpenJDK-Warnungen aus stderr
    filtered_lines = [
        line for line in stderr.splitlines() 
        if "OpenJDK 64-Bit Server VM warning" not in line 
        and "-Xverify:none" not in line 
        and "-noverify" not in line
    ]
    filtered_stderr = "\n".join(filtered_lines)
    
    return proc.returncode, stdout, filtered_stderr

# 3. Kompilierung
compile_cmd = [
    "kotlinc", "Solution.kt", "-d", "Solution.jar",
    "-J-Xmx1024m", "-J-Xss256k", "-J-XX:MaxMetaspaceSize=128m"
]

return_code, stdout_comp, stderr_comp = run_and_filter(compile_cmd)

if return_code != 0:
    print("** Kompilierung fehlgeschlagen **", file=sys.stderr)
    if stderr_comp:
        print(stderr_comp, file=sys.stderr)
    sys.exit(0)

# 4. Ausführung
# Der Klassenname 'SolutionKt' ist der Standard-Mapping-Name für die Datei 'Solution.kt'
run_cmd = [
    "kotlin", "-cp", "Solution.jar", "SolutionKt",
    "-J-Xmx512m", "-J-Xss256k", "-J-XX:MaxMetaspaceSize=128m"
]

return_code, stdout_run, stderr_run = run_and_filter(run_cmd)

# 5. Finale Ausgabe
if stderr_run:
    print(stderr_run, file=sys.stderr)

if stdout_run:
    print(stdout_run, end="")]]></template>
    <iscombinatortemplate>0</iscombinatortemplate>
    <allowmultiplestdins>0</allowmultiplestdins>
    <answer></answer>
    <validateonsave>1</validateonsave>
    <testsplitterre><![CDATA[|#<ab@17943918#@>#\n|ms]]></testsplitterre>
    <language>python3</language>
    <acelang>kotlin</acelang>
    <sandbox></sandbox>
    <grader>EqualityGrader</grader>
    <cputimelimitsecs>15</cputimelimitsecs>
    <memlimitmb>4096</memlimitmb>
    <sandboxparams></sandboxparams>
    <templateparams></templateparams>
    <hoisttemplateparams>1</hoisttemplateparams>
    <extractcodefromjson>1</extractcodefromjson>
    <templateparamslang>None</templateparamslang>
    <templateparamsevalpertry>0</templateparamsevalpertry>
    <templateparamsevald>{}</templateparamsevald>
    <twigall>0</twigall>
    <uiplugin>ace</uiplugin>
    <uiparameters></uiparameters>
    <attachments>0</attachments>
    <attachmentsrequired>0</attachmentsrequired>
    <maxfilesize>10240</maxfilesize>
    <filenamesregex></filenamesregex>
    <filenamesexplain></filenamesexplain>
    <displayfeedback>1</displayfeedback>
    <giveupallowed>0</giveupallowed>
    <prototypeextra></prototypeextra>
    <testcases>
    </testcases>
  </question>

</quiz>