Skip to content

Instantly share code, notes, and snippets.

@benharsh
Created October 6, 2017 22:33
Show Gist options
  • Save benharsh/2cd96e3d144c294cbea29b8275c5347f to your computer and use it in GitHub Desktop.
Save benharsh/2cd96e3d144c294cbea29b8275c5347f to your computer and use it in GitHub Desktop.
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);
}
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