Skip to content

Commit

Permalink
Better motivated puzzle
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Oct 8, 2024
1 parent 0f373f9 commit 1995a12
Show file tree
Hide file tree
Showing 5 changed files with 403 additions and 127 deletions.
82 changes: 82 additions & 0 deletions data/scenarios/Challenges/_dna/mirrorbot.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end;

def getBaseForNumber = \n.
if (n == 0) {
"guanine";
} {
if (n == 1) {
"cytosine";
} {
if (n == 2) {
"adenine";
} {
"thymine";
};
};
};
end;

def getNumberForBase = \n.
if (n == "guanine") {
0;
} {
if (n == "cytosine") {
1;
} {
if (n == "adenine") {
2;
} {
if (n == "thymine") {
3;
} {-1};
};
};
};
end;

def getComplementNumber = \n.
if (n == 0) {
1;
} {
if (n == 1) {
0;
} {
if (n == 2) {
3;
} {
2;
};
};
};
end;

def placeComplementOf = \item.
let baseNumber = getNumberForBase item in
if (baseNumber >= 0) {
let complementNumber = getComplementNumber baseNumber in
let newItem = getBaseForNumber complementNumber in
move;
create newItem;
place newItem;
} {
let sludge = "organic sludge" in
create sludge;
place sludge;
}
end;

def waitUntilHere =
watch down;
wait 1000;

maybeItemDown <- scan down;
case maybeItemDown (\_. waitUntilHere) (\itemHere.
placeComplementOf itemHere;
);
end;

def go =
instant waitUntilHere;
end;

go;
100 changes: 94 additions & 6 deletions data/scenarios/Challenges/_dna/solution.sw
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end;

def getBaseForNumber = \n.
if (n == 0) {
"guanine";
} {
if (n == 1) {
"cytosine";
} {
if (n == 2) {
"adenine";
} {
"thymine";
};
};
};
end;

def getNumberForBase = \n.
if (n == "guanine") {
0;
} {
if (n == "cytosine") {
1;
} {
if (n == "adenine") {
2;
} {
3;
};
};
};
end;

def getComplementNumber = \n.
if (n == 0) {
1;
} {
if (n == 1) {
0;
} {
if (n == 2) {
3;
} {
2;
};
};
};
end;

def waitWhileHere = \item.
stillHere <- ishere item;
if stillHere {
Expand All @@ -24,28 +72,54 @@ def moveToPattern =
turn right;
doN 2 move;
turn right;
doN 5 move;
doN 4 move;
turn right;
move;
turn left;
move;
end;

def moveToOtherRow =
turn right;
doN 9 move;
doN 8 move;
turn right;
move;
end;

def waitForItem : Dir -> Cmd Text = \d.
item <- scan d;
case item (\_. waitForItem d) return;
case item (\_.
watch d;
wait 1000;
waitForItem d;
) return;
end;

def waitForSpecificItem = \item. \d.
itemIsHere <- ishere item;
if itemIsHere {
} {
watch d;
wait 1000;
waitForSpecificItem item d;
}
end;

def placeComplementOf = \item.
let baseNumber = getNumberForBase item in
let complementNumber = getComplementNumber baseNumber in
let newItem = getBaseForNumber complementNumber in
place newItem;
end;

/**
Store the observed entities in the recursion stack.
*/
def replicatePattern = \standbyFunc. \n.
if (n > 0) {
thingTemp <- waitForItem down;
thingTemp <- waitForItem left;
let thing = thingTemp in
placeComplementOf thing;
move;
replicatePattern standbyFunc $ n - 1;

Expand All @@ -58,16 +132,30 @@ def replicatePattern = \standbyFunc. \n.

def go =
move;

let sentinel = "flower" in
place sentinel;

doN 16 $ make "cytosine";

waitWhileHere sentinel;
moveToPattern;
replicatePattern moveToOtherRow 32;

// Activate the switch
doN 3 move;
drill forward;
turn left;
doN 4 move;
turn left;
doN 40 move;
turn left;
doN 2 move;
turn left;
move;

waitForSpecificItem "flower" down;
grab;

end;

go;
go;
90 changes: 90 additions & 0 deletions data/scenarios/Challenges/_dna/topchecker.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
def doN = \n. \f. if (n > 0) {f; doN (n - 1) f} {}; end;

def getBaseForNumber = \n.
if (n == 0) {
"guanine";
} {
if (n == 1) {
"cytosine";
} {
if (n == 2) {
"adenine";
} {
"thymine";
};
};
};
end;

def getNumberForBase = \n.
if (n == "guanine") {
0;
} {
if (n == "cytosine") {
1;
} {
if (n == "adenine") {
2;
} {
if (n == "thymine") {
3;
} {-1};
};
};
};
end;

def getComplementNumber = \n.
if (n == 0) {
1;
} {
if (n == 1) {
0;
} {
if (n == 2) {
3;
} {
2;
};
};
};
end;

def waitUntilHere = \remainingCount.
if (remainingCount > 0) {
maybeItemHere <- scan down;
case maybeItemHere (\_.
watch down;
wait 1000;
waitUntilHere remainingCount;
) (\itemHere.

maybeItemAbove <- scan left;
case maybeItemAbove (\_. fail "Expected an item here.") (\itemAbove.
let num = getNumberForBase itemAbove in
if (num >= 0) {
let complementNum = getComplementNumber num in
let complementItem = getBaseForNumber complementNum in
if (complementItem == itemHere) {
move;
waitUntilHere $ remainingCount - 1;
} {
create "pixel (R)";
}
} {
fail "Expected nonnegative item index."
}
);
);
} {
log "Finished verifying top row";
create "pixel (G)";
};

end;

def go =
instant $ waitUntilHere 32;
end;

go;
Loading

0 comments on commit 1995a12

Please sign in to comment.