Skip to content

Instantly share code, notes, and snippets.

@hatred
Last active March 16, 2017 02:42
Show Gist options
  • Save hatred/4e8a1c519c262ba50654f5eb9e206e89 to your computer and use it in GitHub Desktop.
Save hatred/4e8a1c519c262ba50654f5eb9e206e89 to your computer and use it in GitHub Desktop.
In the space of POSITIVE integers...
"Increasing" number = from left to right, digits are all >= than previous digit
Examples:
123
1223
134468
"Decreasing" number = from left to right, digits are all <= than previous digit
Examples:
321
3221
66420
"Flat" number = from left to right, digits are all the same
Examples:
111
2222
33333
"Bouncy" number = not Increasing/Decreasing/Flat
Examples:
121
1324
155349
Milestones:
* At 538, exactly 50% of positive integers <= 538 are "bouncy"
* At 21780, exactly 90% of positive integers <= 21780 are "bouncy"
Find the least number for which:
* Exactly 99% of positive integers <= X are "bouncy"
Example graph:
20
B - - - - E
/ \ / \
/ \ 18/ \
16/ 17\ / 11\
/ 21 \ / 23 \
A - - - - D - - - - G
\ / \ /
\ 28/ \ 27/
12\ / 19\ /
\ / \ /
C - - - - F
31
Sum of weights in example = 243
Graph in matrix form:
| A | B | C | D | E | F | G
A | | 16 | 12 | 21 | | |
B | 16 | | | 17 | 20 | |
C | 12 | | | 28 | | 31 |
D | 21 | 17 | 28 | | 18 | 19 | 23
E | | 20 | | 18 | | | 11
F | | | 31 | 19 | | | 27
G | | | | 23 | 11 | 27 |
Optimized graph:
B E
/ \ / \
/ \ 18/ \
16/ 17\ / 11\
/ \ / \
A D G
\ \
\ \
12\ 19\
\ \
C F
Sum of weights in optimized example graph = 93
Code a general algorithm for determining the total weight
of an optimized graph, given an arbitrary matrix of edges
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment