-
-
Save benharsh/2cd96e3d144c294cbea29b8275c5347f 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
var idToString : [1..0] string; | |
var ingDom : domain(string); | |
var ingredients : [ingDom] int; | |
var f = open("info.txt", iomode.r); | |
for line in f.lines() { | |
const ingredient = line.strip(); // get rid of \n | |
if ingDom.member(ingredient) == false { | |
idToString.push_back(ingredient); | |
const ID = idToString.domain.last; | |
assert(idToString[ID] == ingredient); | |
ingDom.add(ingredient); | |
ingredients[ingredient] = ID; | |
} | |
} | |
for i in ingDom { | |
const ID = ingredients[i]; | |
writeln(i, " => ", ID); | |
assert(idToString[ID] == i); | |
} |
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
carrots | |
lettuce | |
potato | |
fries | |
candy | |
lettuce | |
lettuce | |
candy | |
potato | |
fries | |
carrots | |
carrots | |
salad |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment