Last active
August 30, 2018 00:01
-
-
Save seanvikoren/3c51846862db6879e881ec3b15f42a30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
var Knave = false; | |
var Knight = true; | |
var knaveCount = 0; | |
var r = Random(); | |
List<bool> islanderList = List<bool>(); | |
bool lie(bool i) { return !i; } | |
String islanderToString(bool i) { return i == Knight ? "Knight" : "Knave"; } | |
String whisperToString(bool w) { return w ? "Yes" : "No"; } | |
bool getIslander() { return Knight; } | |
bool getIslanderQ() { return r.nextBool(); } | |
void add(bool i) { | |
islanderList.add(i); | |
if (i == Knave) { knaveCount++; } | |
} | |
void main() { | |
var count = 10; | |
var fixed = 5; | |
for (var i = 0; i < count - fixed; i++) { add(Knight); } | |
for (var i = 0; i < count - fixed; i++) { add(Knave); } | |
print("At least n of us are Knaves."); | |
print("Knave count = ${knaveCount}\n"); | |
for (var i = 0; i < count; i++) { | |
var claimedMinimumKnaveCount = i + 1; | |
var a = "${islanderToString(islanderList[i])}".padRight(6); | |
var claim = claimedMinimumKnaveCount.toString().padLeft(2, " "); | |
var isTrue = knaveCount >= claimedMinimumKnaveCount; | |
print("${a} ${claim} or more of us are Knaves (${isTrue})"); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment