and
Palindromes are strings, which are identical when reserved.
Write a function, which prints to standard out “T” if a string is a palindrome, and “F” in any other case
I’m sure you’ve already thought about the solution, right?
Write down in plain english how you would solve the problem, then translate those steps in code.
And if you’re stuck with a certain piece of code, just post it here and explain what your problem is.
Challenge accepted!
BUT I will only give you the stupid solution for the first one
Why stupid? Because it’s with recursion and, for number 15 (as example) the result is 610 but it passes 114243 times through the function.
For no. 22 it took over 5 min and I got bored and stopped it. So, very non-efficient.
I will think at a nice solution in future.
But maybe, someone else comes with one before me
Access it using name_of_script.php?n=4 and you’ll see output. If you read the file, you’d see he was using $_GET to receive the number in the sequence to output.
Well, for the first one you need to define what the fibonacci (not the fibocanni) sequence is. Yes, i know what it is. No, i’m not doing your work for you. There are plenty of optimized ways to find the Nth fibonacci sequence number (in fact, you can do it as a N-order single line mathematical execution, but from the way your question is written for you, I think your teacher wants recursion.)
if($reverse == $word){ // compares the reverse layout of the word and the original word
echo "T"; // when true, output 'T'
}else{
echo "F"; // when false, output 'F'
}
You may want to brush up on the logic section of your programming textbook or section of the website you are attempting these from.
There’s actually a simplification of that formula using rounding. Because of the way exponential functions work, the second term will always reduce (1-sqrt(5)/2 < 1. All X < 1, y In Integers, f(X) = x^y, f(x+1) < f(x)), and when x is limited to the positive integers, f(1) in this case = -0.6; f(2) = 0.3 (and from then on becomes rounding-insignificant) the formula can safely be reduced as: F(x) = round((1/sqrt(5))*pow((1+sqrt(5))/2,$x+1)), for the Xth term of the fibonacci set. (Note this is a 0-indexed set; so F(0) = 1, F(1) = 1, F(2) = 2, etc. You can remove the +1 from the power to achieve a 1-indexed set and retrieve the Xth Term of the Sequence as F(x) = round((1/sqrt(5))*pow((1+sqrt(5))/2,$x)) )
it might be easier for all of us if you just paste the list of words you want to check here and we’ll respond manually to the list. I know that you are needing help with this, but can you be bothered to do any of the work yourself?
I think this is an instance where we’re giving you fish rather than teaching you to fish. If you can’t understand simple functions, you aren’t ready for solving the Nth number in a fibonacci sequence