for example
:
* means a coin
a triangle of coins like this:
*
* *
* * *
its number is 3
when i invert it it will be like that:
* * *
* *
*
for more explination:
i want a formula to calculate the minimum transfers of coins to invert triangle
for example
:
* means a coin
a triangle of coins like this:
*
* *
* * *
its number is 3
when i invert it it will be like that:
* * *
* *
*
for more explination:
i want a formula to calculate the minimum transfers of coins to invert triangle
Hello, mido22!
A triangle of coins like this: .
Its dimension is
When inverted, it looks like this: .
Find a formula for , the minimum moves of coins to invert a triangle.
I cranked out the first few cases and found that there are two formulas,
. . depending on the parity of (odd or even).
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
For even is the sum of two consecutive Triangular Numbers.
. .
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
For odd is twice a Triangular Number.
. .
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Hi, I see you're a little new to the forum, and welcome.
You marked your thread as [SOLVED], which leads people not to make further posts because they believe you solved the problem on your own!
As for the problem, I don't know what you mean, and could you explain the rules more? What constitutes a "move"? Why did the yellow coins become blue in your image?
EDIT: It looks like Soroban knew what you meant. Nice problem!
thx 4 reply
1st: how can i remove solved???
2nd: it is a problem in programming and i want a formula to solve it
here is the link:
Sphere Online Judge (SPOJ) - Problem MINCOUNT
Should be near the top right of the thread: see where it says "Thread tools"? On a thread I started, there is an option "Mark this thread as solved..." I'm guessing you have a reverse option available.
Looking at test cases, it seems Soroban's answer doesn't give the minimal number of moves as desired. After staring mindlessly at the diagram for five minutes, I see how it's possible to invert h=4 in 3 moves:
(I used A instead of 10 so that it would look cleaner.)Code:1 2 3 4 5 6 7 8 9 A 7 2 3 A 4 5 6 8 9 1
I would try to find a formula like Soroban did. Haven't worked on it yet, but what have you tried so far?
. See floor function. Find out how to use the floor function in your programming language; using integer division has the same effect. (Coincidentally, the example on the MathWorld page for integer division is exactly the same calculation done in this post.)
By the way, here is how I got the first few terms. Consider h=6. Write
1
2
3
4
5
6
Now consider making the third row the new top row. Take coins from row 6 and put them in row 3.
1
2
3+3=6
4
5
6-3=3
Now take a coin from the row 5 and put it in row 4.
1
2
6
5
4
3
Lastly, move the top two rows to the bottom.
6
5
4
3
2
1
We see this is (3+1) + (1+2) = 7.
We could also have worked it out like this
1
2
3
4
5
6
1
2+4
3+2
4
5-2
6-4
giving (4+2) + (1) = 7.
You can continue further with higher values of h.
Are you sure it's a wrong equation as opposed to wrong presentation? Or possibly something like integer overflow? Also be careful with test cases like h=0 since it is a little unclear whether 0 or the empty string is supposed to be returned. Anyway OEIS is occasionally wrong but it's not typical. I could work it out further on paper or code a (slower but dependable) algorithmic approach based on my previous post, and it could be used to test against the formula.
Note that starting around 1/6 of the maximum value of a 64-bit long you will have overflow problems with that formula.
I might even join the programming site.. I'm a bit busy though.