Skip to content

Instantly share code, notes, and snippets.

@Descalon
Last active October 29, 2019 11:49
Show Gist options
  • Save Descalon/55c11d2b873dff328b0329399b3742f9 to your computer and use it in GitHub Desktop.
Save Descalon/55c11d2b873dff328b0329399b3742f9 to your computer and use it in GitHub Desktop.
series0
tuple[int,list[str]] mostOccurringVariable(list[Declaration] asts) {
list[str] vars = [];
visit(asts) {
case \variable(name,_): vars += name;
}
map[int,set[str]] invDist = invert(distribution(vars));
int max = head(reverse(sort(toList(invDist<0>))));
return <max,toList(invDist[max])>;
}
tuple[int,list[str]] mostOccurringNumber(list[Declaration] asts) {
list[str] values = [];
visit(asts) {
case \number(v) : values += v;
}
map[int,set[str]] invDist = invert(distribution(values));
int max = head(reverse(sort(toList(invDist<0>))));
return <max,toList(invDist[max])>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment