Skip to content

Instantly share code, notes, and snippets.

@Levi-Lesches
Last active February 20, 2020 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Levi-Lesches/90b42240a92110d88d5db02c88402e50 to your computer and use it in GitHub Desktop.
Save Levi-Lesches/90b42240a92110d88d5db02c88402e50 to your computer and use it in GitHub Desktop.
Simple stock market code
class Range {
final num buy, sell;
const Range(this.buy, this.sell);
}
Range maxProfit(List<double> points) {
// We want to find a range by examining a list of local minima and maxima
// We can assign a new list (think about what type it would hold) of those minima and maxima
// To find that list, we go through the list of points, two at a time, watching
// for changes in whether the points are increasing or decreasing.
//
// To find the best points to buy and sell, we can check every combination
// (in chronological order) of the local minima and maxima to maximize
// value.
double previousValue, nextValue;
for (final MapEntry<int, double> entry in points.asMap().entries) {
final int index = entry.key;
final double value = entry.value;
if (index != points.length - 1) {
// Assign nextValue here
}
}
}
@Levi-Lesches
Copy link
Author

0 V L V ~(i <==> g)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment