What badges should I get for my 28th birthday?
1, 2, 3, 4, 5, 6, and 7
1, 2, 4, 7, and 14
seen from Poland
seen from Germany
seen from United Kingdom
seen from China
seen from United States

seen from United States
seen from Georgia

seen from Germany
seen from United States
seen from China
seen from China
seen from Germany

seen from United States
seen from Germany
seen from China

seen from Malaysia

seen from United States

seen from United States

seen from United States
seen from China
What badges should I get for my 28th birthday?
1, 2, 3, 4, 5, 6, and 7
1, 2, 4, 7, and 14

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch ⢠No registration required ⢠HD streaming
Solution #15
Well, all right, it wasnāt tomorrow.Ā I was, in fairness, busy with work :).Ā But yeah, solution below the line as per usual...
The Handshake Problem
This is a really good problem for looking at through the lens of patterns.
With 1 person, there are no handshakes.
Between two people, there is one, just between the two.
For three handshakes between Alice, Bob and Carol, Alice shakes both Bob and Carolās hand (thatās two) and then Bob and Carol need to shake hands. So thatās 3.Ā
Four handshakes: A, B, C, D. A shakes everyoneās hand (3). Then B has to shake C and Dās hand, but *not* Aās because they already shook. So thatās two more, and then C and D shake. Thatās 6 in total.
We could run through five handshakes, or we could imagine that A, B, C and D have already done all their handshaking, and then E walks into the room. What happens? Ze shakes everyoneās hand in the room, which is 4 more. So thatās 10.
The next person has five hands to shake, so thatās 15.
So our pattern is:
0, 0+1, 0+1+2, 0+1+2+3, 0+1+2+3+4,Ā 0+1+2+3+4+5 and so on.
So how many handshakes occur between and among 10 people? Well, the first person has to shake 9 hands, the next person 8, and so on. So 9+8+7+6+5+4+3+2+1=45.
Triangle Numbers
These are called the triangle numbers, because you can make increasing sizes of triangles like this, with each row having one more dot.
Consider, though, that in a group of 10, every person shakes 9 hands. So why arenāt there 90 handshakes? (Think about it)
Well, when two people shake hands, they both come away thinking thereās been a handshake, so there are two handshakes accounted for in the count. Each handshake is double counted, so there are 90/2=45 handshakes.
And this gives us a method for finding the number of handshakes among 100 people. Itās 100*99/2=4950. Or n people: n(n-1)/2.
This is just a bit off of the nth triangular number, because for triangular numbers, we donāt count 0 as the first, with one person. So the 100th triangular number is the number of handshakes among 101 people.
And we get a slightly different equation, which we can derive algebraically, or geometrically, which is cool. Take one of the above triangles, left justify it, double it and put them together to make a rectangle:
The area of the rectangle is n(n+1) and we divide it by two to get the area of the triangle,Ā n(n+1)/2.
Other Problems
Diagonals: How many diagonals does an n-gon have? Go try and find a pattern!
A triangle has no diagonals. A quadrilateral has two. A pentagon has five. A hexagon has nine.Ā
0, 2, 5, 9. Looks like we add two, then three, then four. Why would that be?
Well, letās look at a pentagon. There are five diagonals already. If we add a corner, what connects to that? This is our 6th corner, and it canāt connect to itself, nor to those corners directly adjacent to it. So it has three dots to connect to, adding three diagonals. But ALSO, one of the sides of our original pentagon is no longer a side, but a diagonal. This is probably best seen in pictures:
You see the original on the left, and then the new sides (in green) and the new diagonals (in purple), including IH, which was a side (DC) in the original.
What would happen next? The 7th corner will connect to four (7-itself-two adjacents=4) diagonals, and there will be another side turning into a diagonal. So 9+5=14.
So how many for a 10-gon? Well letās recap:
3-gon (triangle): 0
4-gon (quadrilateral): 2
5-gon (pentagon): 5 (2+3)
6-gon (hexagon): 9 (2+3+4)
7-gon (heptagon): 14: (2+3+4+5)
So it looks like 10-gon would be: 8 (start at 2 less than the number of sides) +7+6+5+4+3+2 (donāt include 1) = 35.
If you notice, we have the triangle numbers minus 1, because of no shape with only 1 diagonal.
Equation
Is there a faster way, like for the triangle numbers? Well, of course you could just do the triangle numbers minus 1, but being careful about which triangle number weāre at, because we start at n=3, with a triangle, because the first triangle number (1) minus 1 =0. So we have to subtract two from our nās.
So we could do (n-2)(n-1)/2 - 1. Letās test to see if Iāve done it right.
For n=3: (1)(2)/2 - 1=0. Good!
Or n=10: (8)(9)/2 - 1 =35. Great.
OR, look for another pattern like the handshakes. Every corner (n) connects to every other one, except itself and the two next to it (n-3).
Thatās n(n-3). But again, every line connecting two dots/corners is going to be counted twice, A to B and then B to A. So n(n-3)/2.
Again: for n=3, we get 0.
For n=10: 10(7)/2=35.
The power of patterns!
What do these have in common?
1. How many diagonals does a quadrilateral have? A pentagon? A triangle? An n-gon? 2. A line cuts a piece of paper (or a plane) into two sections. How about two lines (non parallel)? Three (only intersecting one other line at a time)? Four? N? 3. You're stacking cups. One sits on its own. Three make a triangle. How many cups do you need for the next size triangle? The next?

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch ⢠No registration required ⢠HD streaming
Project Euler, Exercise 12
This oneĀ was all about Triangle numbers. Here's a song to get us in the mood.
Back to our regularly scheduled bit of code.Ā
Here was my first shot at it.Ā
Spoilers for exercise 12, below the fold...