Knights, Knaves, and Monks - Puzzle Solver

You are on the Island of Knights, Knaves, and Monks. Knights always tell the truth, knaves always lie, and monks may say anything at all. You encounter between 3 and 7 islanders, and fewer than half of them are Monks. The islanders make some statements about each other. Can you deduce what identity combinations are possible for this group?

Below is a puzzle solver. Enter a logical paraphrase of the islanders's statements and it will output the set of possible islander roles. Here is how you input a puzzle:

On line 1, the number of islanders. On each subsequent line, a claim of the form I: S signifying that islander I made statement S.

An islander I is one of A, B, C, D, E, F, G. A role R is one of K, M, V (i.e. Knight, Monk, knaVe). A number N is an integer between 0 and the number of islanders. Create statements S from islanders, roles, and other statements using the following syntax:

  • I=R // islander I has role R
  • I=I // two islanders have the same role
  • eR // an even number of islanders have role R
  • oR // an odd number of islanders have role R
  • NR // N islanders have role R
  • ImI // islander 1 speaks the truth more than islander 2
  • IlI // islander 1 speaks the truth less than islander 2
  • (S) // group one or more statements
  • -S // not S
  • S.S // and
  • S|S // or
  • S>S // if-then
  • S#S // biconditional (if and only if)

Find the code at https://github.com/tenedor/kmv-solver.