Created
December 7, 2013 23:41
-
-
Save btholt/7851415 to your computer and use it in GitHub Desktop.
Dart Dare
Secret Santa Matching
Dec 7, 2013
This file contains hidden or 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
void main() { | |
print("Start rein.dart"); | |
var santaNames = [ | |
{"first" : "Brian", "last": "Holt"}, | |
{"first" : "Nikki", "last": "Holt"}, | |
{"first" : "Samwise", "last": "Gamgee"}, | |
{"first" : "Kyle", "last": "Beckerman"}, | |
{"first" : "Alvaro", "last": "Saborio"}, | |
{"first" : "Sebastian", "last": "Velasquez"}, | |
{"first" : "Javier", "last": "Morales"}, | |
{"first" : "Chris", "last": "Schuler"}, | |
{"first" : "Nick", "last": "Rimando"} | |
]; | |
santaNames.shuffle(); | |
print (santaNames); | |
var prev; | |
var first; | |
for(var i = 0; i < santaNames.length; i++) { | |
var cur = new Santa(); | |
cur.first = santaNames[i]['first']; | |
cur.last = santaNames[i]['last']; | |
if (i == santaNames.length - 1) { | |
cur.match = first; | |
} | |
if (i != 0) { | |
prev.match = cur; | |
} | |
else { | |
first = cur; | |
} | |
prev = cur; | |
} | |
printSantas(first); | |
} | |
void printSantas(Santa santa) { | |
var cur = santa; | |
do { | |
print(cur); | |
cur = cur.match; | |
} while(cur != santa); | |
} | |
class Santa { | |
String first; | |
String last; | |
Santa match; | |
toString() => first + " " + last + " => " + match.first + " " + match.last; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment