Skip to content

Instantly share code, notes, and snippets.

@shawnlauzon
Last active May 20, 2020 22:45
Show Gist options
  • Save shawnlauzon/d051a8038f3e664fe312f84da10340ba to your computer and use it in GitHub Desktop.
Save shawnlauzon/d051a8038f3e664fe312f84da10340ba to your computer and use it in GitHub Desktop.
Brute force guesser of a function, simply applies each of the possible functions to get a final result
guessFunction([
MapEntry('𝜖', epsilon.rad),
MapEntry('α', st.angle().rad),
MapEntry('α', st.angle().rad),
MapEntry('𝜖', epsilon.rad)
]);
void guessFunction(List<MapEntry<String, num>> vals) {
final unaryOps = {
'sin': sin,
'cos': cos,
'tan': tan,
'atan': atan,
'-': (a) => -a,
'': (a) => a
};
final binOps = {
'+': (a, b) => a + b,
'-': (a, b) => a - b,
'*': (a, b) => a * b,
'/': (a, b) => a / b,
};
final mods = {'+π': (num a) => a + pi, '': (a) => a};
int numOps = 0;
for (var v1 in vals) {
for (var op1 in unaryOps.entries) {
var res1 = op1.value(v1.value);
for (var v2 in vals) {
if (v1.value == v2.value) continue;
for (var op2 in unaryOps.entries) {
var res2 = op2.value(v2.value);
for (var op3 in binOps.entries) {
var binR = op3.value(res1, res2);
var unR = atan(binR);
for (var op4 in mods.entries) {
var r = op4.value(unR);
print(
'atan(${op1.key}(${v1.key}) ${op3.key} ${op2.key}(${v2.key})) ${op4.key} = $r');
numOps++;
}
}
}
}
}
}
print('tried $numOps ops');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment