Discover the Formula for Finding Trains of Any Length | Math Project Help"

  • Thread starter heartless
  • Start date
  • Tags
    Algorithms
In summary, the problem involves building "trains" using rods of integer sizes that all share a common length. The solution involves finding the number of trains of a given length and coming up with a formula and algorithm to generate all possible trains of a given length. The formula for the number of trains of length n is 2^(n-2) + 2^(n-3) + ... + 2^2 + 2^1 + 2^0 = h, and the algorithm should be recursive in nature.
  • #1
heartless
220
2
Hello math crew!

Here's the problem: http://www2.edc.org/makingmath/mathprojects/trains/trains.asp

just in case somebody doesn't want to click on the above link,

trains:
You can use rods of integer sizes to build "trains" that all share a common length. A "train of length 5" is a row of rods whose combined length is 5. Here are some examples:
trains0x.gif

Notice that the 1-2-2 train and the 2-1-2 train contain the same rods but are listed separately. If you use identical rods in a different order, this is a separate train.

* How many trains of length 5 are there?
* Come up with a formula for the number of trains of length n. (Assume you have rods of every possible integer length available.) Prove that your formula is correct.
* Come up with an algorithm that will generate all the trains of length n. Now I solved this problem, at least I think I solved it.
A formula for the number of trains of length n will be
a=length of a train
h=how many trains of a given length
2^(a-2) + 2^(a-3) + 2^(a-4)+...+ 2^2 + 2^1 + 2^0 = h
if a > 3
I'm not truly sure, if this formula is right, it works for 4,5,6,7 and seems to work for every length above 7, it doesn't work for lengths 1,2,3 though,
Also I have a problem with an algorithm.
Can anyone help me make one, or at least give some clues ont "how to make a good algorithm?" (eventually you may post some good books on algorithms. I got some books in my eye on algorithms, however still have not enough money or time to read 'em)

thanks for all the help fellows,
 
Last edited:
Physics news on Phys.org
  • #2
The formula can be made much simpler. Write out a list of the h values for a = 1, 2, 3, 4, 5, 6, 7, ... There's a very obvious pattern. The idea for the algorithm should follow from the way you think about solving the first problem. Here's a hint: how do you figure out how many ways you can build an n-train if you know how many ways you can build an n-1-train, and n-2-train, ..., a 1-train, (and a 0-train)? Everything about this problem screams "recursion" so your algorithm should be recursive. You should probably end up using some sort of "recursive thinking" to solve the first problem, and you can apply this recursive thinking to figure out your algorithm.
 
  • #3

Hello!

I am always excited to see people using math to solve problems and come up with formulas and algorithms. It shows that the skills we learn in math class can be applied to real-world situations.

Now, let's take a look at your formula for the number of trains of length n. I can see that you have put a lot of thought into it, but there are a few things we need to consider.

Firstly, let's define a few terms. The formula you have come up with is for the number of "unique" trains of length n, meaning that the order of the rods matters. For example, the train 1-2-2 is different from the train 2-1-2. However, the problem statement doesn't specify that the order matters. So, if we consider the order to be irrelevant, then there would only be one train of length 5 (the 1-1-1-1-1 train), not multiple trains as your formula suggests.

Secondly, your formula seems to work for lengths 4 and above, but as you mentioned, it doesn't work for lengths 1, 2, and 3. This is because for those lengths, there are only a few possible combinations of rods that can make up the train. For example, for a train of length 1, there is only one possible combination (1 rod of length 1). Therefore, your formula needs to be adjusted to account for these special cases.

As for an algorithm, here are some steps you can follow:

1. Start with a train of length n=1, consisting of one rod of length 1.
2. For each additional rod of length 1, add it to the end of the train to create a new train of length n+1.
3. For each additional rod of length 2, insert it at any point in the train to create a new train of length n+1.
4. For each additional rod of length 3, insert it at any point in the train (including between rods) to create a new train of length n+1.
5. Repeat steps 2-4 until you have exhausted all possible combinations of rods for a train of length n.

This algorithm will generate all possible trains of length n, including duplicates. So, you may need to adjust it to remove duplicates if the order of the rods is considered irrelevant.

I hope this helps guide
 

1. What is an algorithm?

An algorithm is a set of instructions or steps that are followed in order to solve a problem or complete a task. It is like a recipe that helps a computer or a person to perform a specific task.

2. Why do we need algorithms?

Algorithms are important because they help us to solve problems efficiently and effectively. They are used in many areas such as computer science, mathematics, and engineering to solve complex problems and make processes more efficient.

3. How do I improve my algorithmic skills?

To improve your algorithmic skills, it is important to practice regularly and challenge yourself with different types of problems. You can also read books, attend workshops, and participate in coding competitions to learn new techniques and approaches.

4. What are some common mistakes in algorithm design?

Some common mistakes in algorithm design include incorrect assumptions, not considering all possible inputs, and not optimizing for time and space complexity. It is important to thoroughly test and analyze your algorithm to avoid these mistakes.

5. Are there any resources available for help with algorithms?

Yes, there are many resources available for help with algorithms. You can find online tutorials, forums, and coding communities where you can ask for help and learn from others. You can also consult with a mentor or take a course to improve your algorithmic skills.

Similar threads

Replies
38
Views
467
  • Precalculus Mathematics Homework Help
Replies
4
Views
2K
Replies
9
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Special and General Relativity
2
Replies
58
Views
4K
Replies
66
Views
4K
Replies
7
Views
1K
Replies
1
Views
949
  • Precalculus Mathematics Homework Help
Replies
13
Views
2K
  • Special and General Relativity
3
Replies
78
Views
4K
Back
Top