GC7R0TA-Rechenzentrum/levels.php
2024-05-04 09:40:23 +02:00

558 lines
20 KiB
PHP
Executable File

<?
/*********************************************************************
* GC7R0TA - Level 1-5
*
*
* Zum debuggen muss die erste Zeile
* --debug
* heissen
**********************************************************************/
/*
* geocache ID and name
*/
$GC_ID = "GC7R0TA";
$GC_NAME = "Rechenzentrum (Für Einsteiger)";
/*
* The final coordinate is calculated in level 5
*/
$level_5_coordinates = array( 4,7, 1,9, 4,0,6, // N 47° 19.406'
0,0,8, 4,7, 2,0,2); // E 8° 47.202', total 15 digits
// N 47° 19.463' E 008° 46.837'
$level_5_coordinates = array( 4,7, 1,9, 4,6,3,
0,0,8, 4,6, 8,3,7); // total 15 digits
/* Inbox
* ---------------------------------
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | => Take
* --------------------------------- (array_pop)
*/
/* Outbox
* ---------------------------------
* Add => | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
* (unshift) ---------------------------------
*/
// Level Beispiele:
// https://github.com/atesgoral/hrm-level-data/blob/master/index.json
/*******************************************************************
* Level 1
* Shift Inbox to Outbox
* Test-Code:
--debug
start:
inbox
outbox
jump start
*******************************************************************/
function level_1_description(){
$title = "Verschieben";
$description = "In der Inbox hat es einige Boxen mit Zahlen, welche in die Outbox verschoben werden sollen.<br>" .
"Schreibe ein Programm, welches das für dich macht!<br>" .
"Du brauchst dazu nur die Befehle <span class=\"inbox cmd\">INBOX</span>, <span class=\"inbox cmd\">OUTBOX</span>, " .
"<span class=\"jump cmd\">JUMP</span> sowie das dazu passende Ziel <span class=\"jumpdst cmd\">&lt;ZIEL&gt;:</span>.<br>" .
"Du hast 4 Daten-Register zur Verfügung (nummeriert von 0 bis 3), brauchst aber eigentlich keins.<br>" .
"Du musst dir auch keine Gedanken darüber machen, wann die Aufgabe erledigt ist. Das Programm wird automatisch beendet, wenn die Outbox korrekt gefüllt ist.";
// $example = "Inbox: " . print_box(5) . "<br>Erwartete Outbox: ";
$example = "Inbox: " . box(3) . box(28). box(7) . " , " .
"Erwartete Outbox: " . box(3) . box(28). box(7) . ".";
$criteria = "Verwende maximal 3 Instruktionen und maximal 17 Schritte."; //Make sure it matches the values in the init function!
$passcode_for_this_level = ""; //no passcode needed for level 1
return [$title, $description, $example, $criteria, $passcode_for_this_level];
}
function level_1_configuration(){
$configuration = array(
"level" => 1,
"inbox_size" => 6, //elements in inbox, use even number!
"show_outbox_as_coordinate" => false, // only last level should set this to true
"max_allowed_instruction" => 3, // counting only true instructions, no comments, labels or empty lines
"max_allowed_steps" => 17, // counting only true instructions, no comments, labels or empty lines
"hand" => "", // content of the hand, single value
"data_registers" => array("", "", "", ""), // content of the 4 data registers
"passcode_for_next_level" => 20685401, // passcode for next level
"reward" => "Herzliche Gratulation!<br>Du darfst zum <a href=\"editor.php?level=2&passcode=20685401\">nächsten Level</a> weiter. Der Passcode ist 20685401.", // shown text if level successes
"test_runs" => 1000, // test runs to check if the program works with any input data
"inbox_preparation_function" => "level_1_prepare_inbox", // function name of function to prepare inbox
"reference_program" => "level_1_reference_program" // function name of the reference program
);
return $configuration;
}
/* Level 1 Inbox preparations
*
*/
function level_1_prepare_inbox($level_configuration) {
$inbox = array();
for($j = 0; $j < $level_configuration['inbox_size']; $j++){
array_push($inbox, mt_rand(-9, 29));
}
return $inbox;
}
/* Level 1 Reference Program
*
*/
function level_1_reference_program($inbox, $level_configuration) {
$expected_outbox = array();
for($j = 0; $j < $level_configuration['inbox_size']; $j++){
$a = array_pop($inbox);
array_unshift($expected_outbox, $a);
}
return $expected_outbox;
}
/*******************************************************************
* Level 2
* Sort 2 numbers, add higher first
* Test-Code:
--debug
-- Sort 2 Numbers
start:
INBOX
COPYTO 0
INBOX
COPYTO 1
SUB 0
JUMPN neg
--pos
COPYFROM 1
OUTBOX
COPYFROM 0
OUTBOX
JUMP start
--neg
neg:
COPYFROM 0
OUTBOX
COPYFROM 1
OUTBOX
JUMP start
*******************************************************************/
function level_2_description(){
$title = "Sortieren";
$description = "Nimm jeweils nacheinander zwei Boxen aus der Inbox. Sortiere sie der Reihe nach und lege zuerst die Grössere, danach die Kleinere in die Outbox.<br>" .
"Tipp: Verwende die Daten-Register, um eine Box zwischenzulagern, Du hast total 4 Daten-Register zur Verfügung (nummeriert von 0 bis 3).";
// $example = "Inbox: " . print_box(5) . "<br>Erwartete Outbox: ";
$example = "Inbox: " . box(3) . box(7). box(16) . box(11) . " , " .
"Erwartete Outbox: " . box(3) . box(7) . box(11) . box(16) . ".";
$criteria = "Verwende maximal 43 Instruktionen und maximal 16 Schritte."; //Make sure it matches the values in the init function!
$passcode_for_this_level = "20685401"; //given in level 1 reward
return [$title, $description, $example, $criteria, $passcode_for_this_level];
}
function level_2_configuration(){
$configuration = array(
"level" => 2,
"inbox_size" => 8, //elements in inbox, use even number!
"show_outbox_as_coordinate" => false, // only last level should set this to true
"max_allowed_instruction" => 16, // counting only true instructions, no comments, labels or empty lines
"max_allowed_steps" => 43, // counting only true instructions, no comments, labels or empty lines
"hand" => "", // content of the hand, single value
"data_registers" => array("", "", "", ""), // content of the 4 data registers
"passcode_for_next_level" => 301861, // passcode for next level
"reward" => "Herzliche Gratulation!<br>Du darfst zum <a href=\"editor.php?level=3&passcode=301861\">nächsten Level</a> weiter. Der Passcode ist 301861.", // shown text if level successes
"test_runs" => 1000, // test runs to check if the program works with any input data
"inbox_preparation_function" => "level_2_prepare_inbox", // function name of function to prepare inbox
"reference_program" => "level_2_reference_program" // function name of the reference program
);
return $configuration;
}
/* Level 2 Inbox preparations
*
*/
function level_2_prepare_inbox($level_configuration) {
$inbox = array();
for($j = 0; $j < $level_configuration['inbox_size']; $j++){
array_push($inbox, mt_rand(-9, 29));
}
return $inbox;
}
/* Level 2 Reference Program
*
*/
function level_2_reference_program($inbox, $level_configuration) {
$expected_outbox = array();
//*******************************************/
for($j = 0; $j < $level_configuration['inbox_size']/2; $j++){
$a = array_pop($inbox);
$b = array_pop($inbox);
if($a > $b){
array_unshift($expected_outbox, $a);
array_unshift($expected_outbox, $b);
}
else{
array_unshift($expected_outbox, $b);
array_unshift($expected_outbox, $a);
}
}
//*******************************************/
return $expected_outbox;
}
/*******************************************************************
* Level 3
* Modulo
* Test-Code:
--debug
-- Modulo
start:
copyfrom 3
copyto 2
INBOX
COPYTO 0
INBOX
COPYTO 1
count:
copyfrom 0
sub 1
jumpn done
copyto 0
bumpup 2
jump count
done:
copyfrom 0
outbox
jump start
*******************************************************************/
function level_3_description(){
$title = "Modulo";
$description = "Nimm jeweils nacheinander zwei Boxen aus der Inbox, dividiere die erste Box durch die Zweite und verschiebe den Rest in die Outbox.
Keine Angst, Du musst nicht wirklich dividieren! Und keine Angst, die Inbox enthält weder Boxen mit Nullen noch Boxen mit negativen Zahlen.<br>" .
"Du hast 4 Daten-Register zur Verfügung. " .
"Zur Unterstützung habe ich Dir ins Daten-Register 3 eine Box mit Wert " . box(0) . " gelegt!";
$example = "Inbox: " . box(3) . box(9). box(5) . box(27). " , " .
"Erwartete Outbox: " . box(0) . box(2) . ".";
$criteria = "Verwende maximal 15 Instruktionen und maximal 260 Schritte."; //Make sure it matches the values in the init function!
$passcode_for_this_level = "301861"; //given in level 2 reward
return [$title, $description, $example, $criteria, $passcode_for_this_level];
}
function level_3_configuration(){
$configuration = array(
"level" => 3,
"inbox_size" => 8, //elements in inbox, use even number!
"show_outbox_as_coordinate" => false, // only last level should set this to true
"max_allowed_instruction" => 15, // counting only true instructions, no comments, labels or empty lines
"max_allowed_steps" => 350, // counting only true instructions, no comments, labels or empty lines
"hand" => "", // content of the hand, single value
"data_registers" => array("", "", "", "0"), // content of the 4 data registers
"passcode_for_next_level" => 405435, // passcode for next level
"reward" => "Herzliche Gratulation!<br>Du darfst zum <a href=\"editor.php?level=4&passcode=405435\">nächsten Level</a> weiter. Der Passcode ist 405435.", // shown text if level successes
"test_runs" => 1000, // test runs to check if the program works with any input data
"inbox_preparation_function" => "level_3_prepare_inbox", // function name of function to prepare inbox
"reference_program" => "level_3_reference_program" // function name of the reference program
);
return $configuration;
}
/* Level 3 Inbox preparations
*
*/
function level_3_prepare_inbox($level_configuration) {
$inbox = array();
for($j = 0; $j < $level_configuration['inbox_size']/2; $j++){
array_push($inbox, mt_rand(2, 9));
array_push($inbox, mt_rand(9, 29));
}
return $inbox;
}
/* Level 3 Reference Program
*
*/
function level_3_reference_program($inbox, $level_configuration) {
$expected_outbox = array();
//*******************************************/
for($j = 0; $j < $level_configuration['inbox_size']/2; $j++){
$a = array_pop($inbox);
$b = array_pop($inbox);
$c = $a % $b;
array_unshift($expected_outbox, $c);
}
//*******************************************/
return $expected_outbox;
}
/*******************************************************************
* Level 4
* Die kleinste Zahl (HRM Level 23)
* For each zero terminated string in the INBOX, send to the OUTBOX only the SMALLEST number you've seen in that string. You will never be given an empty string. Reset and repeat for each string.\n\nWhat's a \"zero terminated string\"? Go ask your boss on the previous floor!
* Test-Code:
--debug
-- Die grösste Zahl
start:
INBOX
COPYTO 0
pos:
INBOX
JUMPZ terminator
copyto 1
copyfrom 0
SUB 1
JUMPN neg
JUMP pos
-- zweite ist grösser
neg:
--undo sub
copyfrom 1
COPYTO 0
JUMP pos
--Ende der Gruppe
terminator:
COPYFROM 0
OUTBOX
JUMP start
*******************************************************************/
function level_4_description(){
$title = "Die grösste Zahl";
$description = "Die Inbox enthält mehrere Zahlen-Gruppen, welche jeweils mit einer Box mit Wert 0 abgeschlossen (terminiert) wird. Für jede Gruppe, lege diejenige Box mit der grössten Zahl in die Outbox.<br>
Eine Zahlen-Gruppe enthält mindestens eine Zahlen-Box und eine Terminator-Box.<br>" .
"Du hast 4 Daten-Register zur Verfügung. ";
$example = "Inbox: " . box(0) . box(8) . box(5) . box(27) .
box(0) . box(19) . box(3) . " , " .
"Erwartete Outbox: " . box(27) . box(19) . ".";
$criteria = "Verwende maximal 15 Instruktionen und maximal 100 Schritte."; //Make sure it matches the values in the init function!
$passcode_for_this_level = "405435"; //given in level 3 reward
return [$title, $description, $example, $criteria, $passcode_for_this_level];
}
function level_4_configuration(){
$configuration = array(
"level" => 4,
"inbox_size" => 6, //elements in inbox, use even number!
"show_outbox_as_coordinate" => false, // only last level should set this to true
"max_allowed_instruction" => 15, // counting only true instructions, no comments, labels or empty lines
"max_allowed_steps" => 70, // counting only true instructions, no comments, labels or empty lines
"hand" => "", // content of the hand, single value
"data_registers" => array("", "", "", ""), // content of the 4 data registers
"passcode_for_next_level" => 5018676, // passcode for next level
"reward" => "Herzliche Gratulation!<br>Du darfst zum <a href=\"editor.php?level=5&passcode=5018676\">nächsten Level</a> weiter. Der Passcode ist 5018676.", // shown text if level successes
"test_runs" => 1000, // test runs to check if the program works with any input data
"inbox_preparation_function" => "level_4_prepare_inbox", // function name of function to prepare inbox
"reference_program" => "level_4_reference_program" // function name of the reference program
);
return $configuration;
}
/* Level 4 Inbox preparations
*
*/
function level_4_prepare_inbox($level_configuration) {
$inbox = array();
while(count($inbox) < $level_configuration['inbox_size']){
array_push($inbox, 0);
$l = mt_rand(1, 4);
for($j = 0; $j < $l; $j++){
array_push($inbox, mt_rand(1, 29));
}
}
return $inbox;
}
/* Level 4 Reference Program
*
*/
function level_4_reference_program($inbox, $level_configuration) {
$expected_outbox = array();
//*******************************************/
start4:
$a = array_pop($inbox);
do{
$b = array_pop($inbox);
if(($b > $a) and ($b !== 0)){
$a = $b;
}
}while($b !== 0);
array_unshift($expected_outbox, $a);
if(count($inbox) > 0){
goto start4;
}
//*******************************************/
return $expected_outbox;
}
/*******************************************************************
* Level 5
* Der Funkspruch
* Test-Code:
--debug
--Der Funkspruch
nextWord:
--get counter
inbox
copyto 0
nextBox:
--get box (and drop it, if zero)
inbox
jumpz nextBox
--decrement counter
bumpdn 0
jumpz NextIsHot
jump nextBox
-- counter is zero, Next box is hot
NextIsHot:
--hot box
inbox
outbox
jump nextWord
*******************************************************************/
function level_5_description(){
$title = "Der Funkspruch";
$description = "Vom ausländischen Geheimdienst konnte ein Funkspruch abgefangen, aber noch nicht entschlüsselt werden.
Wir haben eine lange Zahlen-Kette, von der wir lediglich wissen, dass die erste Box angibt, wieviele Boxen verworfen werden müssen, bis eine Box
mit sinnvollem Inhalt auftaucht (welche wir dann in die Outbox legen sollten). Die Box danach wiederum scheint die Anzahl der nächsten \"Verwerfungen\" zu enthalten.
Leider ist dem noch nicht genug; Soll eine Box verworfen werden, welche 0 enthält, gilt sie als Platzhalter und darf nicht mitgezählt werden.
Die letzte zu verwerfende Box enthält jedoch nie eine 0!<br>
Der Funkspruch ist so aufgebaut, dass immer mindestens eine Box verworfen werden muss.<br>".
"Du hast 4 Daten-Register zur Verfügung. ";
$example = "Inbox: " . box(0) . box(1) . box(4) . box(9). box(6). box(2). box(5). box(4) . box(5) . box(0) . box(3) . box(2) .
box(7) . box(9) . box(1) . " , " .
"Erwartete Outbox: " . box(0) . box(4) . box(7) . ".";
// $criteria = "Verwende maximal 10 Instruktionen und maximal 315 Schritte."; //Make sure it matches the values in the init function!
$criteria = "Funkspruch korrekt entschlüsseln."; //Make sure it matches the values in the init function!
$passcode_for_this_level = "5018676"; //given in level 4 reward
return [$title, $description, $example, $criteria, $passcode_for_this_level];
}
function level_5_configuration(){
global $level_5_coordinates;
$configuration = array(
"level" => 5,
"inbox_size" => count($level_5_coordinates), //elements in inbox, use even number!
"show_outbox_as_coordinate" => true, // only last level should set this to true
"max_allowed_instruction" => 99, // counting only true instructions, no comments, labels or empty lines
"max_allowed_steps" => 999, // counting only true instructions, no comments, labels or empty lines
"hand" => "", // content of the hand, single value
"data_registers" => array("", "", "", ""), // content of the 4 data registers
"passcode_for_next_level" => "", // passcode for next level
"reward" => "Herzliche Gratulation!<br>Du kannst die Koordinate des Geocaches in der Outbox ablesen.", // shown text if level successes
"test_runs" => 1, // test runs to check if the program works with any input data. Since the inbox is always the same one run is enough
"inbox_preparation_function" => "level_5_prepare_inbox", // function name of function to prepare inbox
"reference_program" => "level_5_reference_program" // function name of the reference program
);
return $configuration;
}
/* Level 5 Inbox preparations
* The inbox is always the same!
*/
function level_5_prepare_inbox($level_configuration) {
global $level_5_coordinates;
$level_5_coordinates_copy = $level_5_coordinates;
$inbox = array();
for($j = 0; $j < $level_configuration['inbox_size']; $j++){
//add hot Box
// $hot_box = mt_rand(10, 19);
$hot_box = array_shift($level_5_coordinates_copy);
array_push($inbox, $hot_box);
// echo("$hot_box, ");
array_push($expected_outbox, $hot_box); //also add it to outbox
//add dropping values
$drops = mt_rand(1, 5); //min 1 max 5
for($i = 0; $i < $drops; $i++){ //add dropping values
if(mt_rand(0, 9) < 5){ //5 out of 10 should be a zero,
if($i > 0){ //but only if not the last drop
array_push($inbox, 0); //add zero
}
}
array_push($inbox, mt_rand(1, 9));
}
array_push($inbox, $drops); //add counter
}
return $inbox;
}
/* Level 5 Reference Program
*
*/
function level_5_reference_program($inbox, $level_configuration) {
global $level_5_coordinates;
$level_5_coordinates_copy = $level_5_coordinates;
$expected_outbox = array();
//*******************************************/
for($j = 0; $j < $level_configuration['inbox_size']; $j++){
//add hot Box
// $hot_box = mt_rand(10, 19);
$hot_box = array_shift($level_5_coordinates_copy);
array_push($inbox, $hot_box);
// echo("$hot_box, ");
array_push($expected_outbox, $hot_box); //also add it to outbox
//add dropping values
$drops = mt_rand(1, 5); //min 1 max 5
for($i = 0; $i < $drops; $i++){ //add dropping values
if(mt_rand(0, 9) < 5){ //5 out of 10 should be a zero,
if($i > 0){ //but only if not the last drop
array_push($inbox, 0); //add zero
}
}
array_push($inbox, mt_rand(1, 9));
}
array_push($inbox, $drops); //add counter
}
//*******************************************/
// print_r($expected_outbox);
return $expected_outbox;
}
?>