google / google/codeworld

Maze example is subtly broken

Open
#1,298 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Haskell
Stars
1.3k
Forks
201
PR merge metrics
No merged PRs in 30d

Description

**Shared Program**: https://code.world/#PFzfkNOVOL_C9ow2vC4A52Q

**Description**

Walking a few steps in the maze eventually gets one stuck at an apparent door. I didn't bother to figure out a good seed for repro, but I never was able to finish the maze with the original code.

The bug is apparently in `containsDoor`, though it's so simple it's very hard to imagine how it can be broken. I started rewriting it and the first change was to make it use an explicit fold https://code.world/#PugJuhO_2ascCpmZGqmOe1Q:
```haskell
containsDoor :: ([Door], Door) -> Truth
containsDoor(ds, d) = foldl(\(x,d')->x || dont(d', d), False, ds)

works((a,b), (c,d)) = ((a == c) && (b == d)) || ((a == d) && (b == c))
dont(a,b) = a == b || a == reverseDoor(b)
```

Now, switching `containsDoor` between `works` and `dont` toggles the bug. I don't understand how this can be.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.