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 ea78c76
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 26 deletions.
71 changes: 67 additions & 4 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,12 +72,16 @@ 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;
Expand All @@ -39,13 +91,22 @@ def waitForItem : Dir -> Cmd Text = \d.
case item (\_. waitForItem d) return;
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,9 +119,11 @@ def replicatePattern = \standbyFunc. \n.

def go =
move;

let sentinel = "flower" in
place sentinel;

doN 16 $ make "cytosine";

waitWhileHere sentinel;
moveToPattern;
replicatePattern moveToOtherRow 32;
Expand Down
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;
8 changes: 3 additions & 5 deletions data/scenarios/Challenges/_dna/verifier.sw
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,20 @@ def spawnComplementer =

def makeDnaStrand =
teleport self (5, -2);
r <- spawnComplementer;
clonedOrganism <- placeBase myStandby 32;
doN 3 move;
drill forward;
teleport self (36, -12);
give r "gold coin";

return clonedOrganism
end;

def go =
instant $ waitUntilHere "flower";
// _f <- grab;
create "pixel (G)";
clonedOrganism <- makeDnaStrand;
teleport self (40, -13);
place clonedOrganism;
// teleport self (40, -13);
// place clonedOrganism;
end;

go;
Loading

0 comments on commit ea78c76

Please sign in to comment.