Expanding an arthimetic algorithm for a Weightlifting [closed] - ruby

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
So I am a quite novice programmer, I have been teaching myself Ruby for a couple of weeks now, and I made a program that estimates your 1 repetition max possible weight lifting capabilities.
The algorithm I used is:
weight = gets.to_i
reps = gets.to_i
x=Rational(reps,30)
x=x.to_f
one_RM = weight*(1+x)
Now this has worked well to get an estimate equal to other 1rep max calculators out there, but what I want to do is to make it so that it takes any weight and reps value and lets the user choose which rep range to convert to.
If that was unclear here is an example of what I mean:
user writes 100 kg and 10 reps program prompts the user for a rep value it would like to get an estimate for, eg instead of only 1rm it can predict anything from 1-100rm etc.
here is a series of formulas for how to calculate the 1 rep maximum:
http://en.wikipedia.org/wiki/One-repetition_maximum#Calculating_1RM
I tried looking trough them and see if I could come up with an idea, but I'm not an expert at math(understatement) and I am very new to programming, so my brain is not contributing any useful solutions, any insights greatly appreciated!

You need to compute the 1RM and then invert the formulas you link to using the new value if r (the number of repetitions your user wants to do).
So with the formula you're using, and r_asked and w_asked the values for repetitions and weight :
You now need to do :
w_asked = one_RM / (1+ r_asked/30)

Related

Performance analysis of Sorting Algorithms [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am trying to compare the performance of couple of sorting algorithms. Are there any existing benchmarks that can make my task easy? If not I want create my own benchmark. How would I achieve this?
Couple of things I need to consider:
Test on different possible input permutation
Test on different scale of input size
Keep hardware configuration consistent across all the algorithms
Major challenge is in implementing sorting algorithm. Because if I implement one and if that happens to be the non-efficient way of implementation it will generate inaccurate result. How would I tackle this?
Tomorrow if someone comes up with his/her own sorting algorithms how would he/she compare with other sorting algorithm?
Though I am flexible with any programming language but would really appreciate if someone can suggest me some functions available in python.
Well, i think you are having trouble what a doubling ratio test is. I know only basics of python so i got this code from here
#!/usr/bin/python
import time
# measure wall time
t0 = time.time()
procedure() // call from here the main function of your sorting class and as
the (sorting)process ends then it will automatically print
the time taken by a sorting algorithm
print time.time() - t0, "seconds wall time"

Algorithm for finding similar words [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
In order to support users learning English, I want to make a multiple-choice quiz using the vocabulary that the user is studying.
For example, if the user is learning "angel" then I need an algorithm to produce some similar words such as "angle" and "angled"
Another example, if the user is learning "accountant" then I need an algorithm to produce some similar words such as "accounttant" and "acountant", "acounttant"
You could compute the Levenshtein Distance from the starting word to each word in your vocabulary and pick the 2 or 3 shortest ones.
Depending on how many words are in your dictionary this might take a long time though, so I would recommend bailing out after a certain (small) number of steps - i.e. if you have made 3 mutations and still haven't arrived at your target word then stop and move on to the next one.

Algorithm to generate an evenly distributed random permutation [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have a set of N questions, each one categorized as one of R subjects. I'm trying to generate some random permutation of the questions for a quiz.
How would I generate a random permutation of the set of questions such that no two consecutive questions have the same subject? It does not need to be perfect; I just don't want to bore people with five of the same type of question in a row.
Additionally, if such an ordering is not possible (as in, 18 of A and 2 of B), could the algorithm find an "evenly distributed" permutation? (in this case, something reasonably like 6As, B, 7As, B, 5As)
Alternatively, since I'm delivering the questions sequentially, could I each time randomly select a remaining question of a different subject without the chance of forcing some repeats at the end?
I've looked around randomly on Google for a while and can't seem to find anything that fits this case. Other than randomly generating permutations until you find one that works, which is slow, ugly and stupid.
Here's an idea:
Group your questions into R groups according to their subject.
Shuffle each group separately
Interleave the groups depending on their relative size, so that they are evenly spaced.
This is simple and fits your requirements. A bit of 'randomness' is lost because the interleaving is always the same (i.e. question from subject 1, then from subject 2, then from subject 3, and start with subject 1 again).
This could be improved by randomizing the order in which you pick groups for each iteration.
Remove the previously used subject from the list of candidate subjects.
For example, in Java, suppose you have 10 subjects:
Subject previous = listSubjects.get( 0 );
while( true ){
listCandidateSubjects.remove( previous );
int xSelection = Random.nextInt( 10 );
Subject current = listCandidateSubjects.get( xSelection );
listCandidateSubjects.add( previous );
// generate question for current subject here
// when have enough questions break
previous = current;
}

How can I calculate the trending nature of a link? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
The above image represents an article's page views over time. I'm looking for a decent, not to complex either physics or statistical calculation that would be able to give me (based on the history of the page views) what the current trending of the page views is for the past n days (which is represented by the blue box).
So basically, in the past 5 days is this link trending unusually higher than it usually does and if so by what degree/magnitude?
Ideally the accepted answer would provide an algorithm class that applies to this problem as well as some example of that using the data provided from this chart above.
thanks!
One approach could be to perform a least squares fit of the points within the blue box. Trends could then measured by the difference between the points and the least squares fit approximation value.
It sounds like you want to compare a short term (5-day) moving average to a longer-term moving average (e.g., something like 90 days).
As a refinement, you might want to do a least-squares linear regression over the longer term, and then compare the shorter term average to the projection you get from that.

Algorithm for creating infinite terrain/landscape/surface? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Does any have an algorithm for creating infinite terrain/landscape/surface?
Constraints
The algorithm should start by a random seed
The algorithm should be one to one, (the same seed gives the same result)
Other input parameter are allowed as long as 2 is fulfilled
The algorithm may output a 2d map
It suppose to create only surface with varying height (mountains), not three, ocean etc.
I’m looking for an algorithm and not a software.
It should be fast
None of other related questions in here answers this question.
If anything is unclear please let me know!
I would suggest something like Perlin noise, I've used it before for something like you're describing above, and it fits the bill. Check out this Example and you can see the sort of output you would expect from the noise generator.Here is a link to algorithm p-code too.
http://freespace.virgin.net/hugo.elias/models/m_perlin.htm
As others already said perlin noise is a possibility. Gpugems 3 has a nice capter about procedual generation using (IIRC, it has been some time since I read this) 3D Perlin noise.
Of course there are other methods too, e.g. Vterrain.org might be worth a look.

Resources