FIB = [0,1,1,2,3,5,8,13]
def checkSequence(numArr):
i = 0
while i < len(numArr):
if FIB[i] == int(numArr[i]):
i += 1
else:
return i
numbers = input("Enter your numbers list and use comma to seperate them: ")
numlist = numbers.split(",")
answer = list()
i = 0
while i < len(numlist):
if int(numlist[i]) == 0:
ret = checkSequence(numlist[i:])
answer.append(numlist[i:i+ret])
i += 1
Как видите, вы можете довольно легко создать метод CheckSquence, чтобы проверить сращивание массива для последовательности и вернуть количество найденных записей. С ответом из checkSequence вы можете создать соединение для своего списка ответов. Это приводит к результатам, которые вы указали в своем вопросе.
РЕДАКТИРОВАТЬ: Вам нужно будет определить последовательность Фибоначчи раньше. Вы можете использовать статическую последовательность, как я, или вычислить до определенной точки, а затем сравнить с этим результатом.
Извините, это не возможно. Самыми близкими, которые Вы получите, являются константы:
define('CONS', 5);
echo CONS;
Нет. Переменные в PHP должны запуститься с $
.
Другой подход должен использовать константы.
Это похоже на просьбу, чтобы Java был non-strong-typed:
str = "some string";
System.out.print(str.contains("some"));
Не имеет никакого смысла вообще.
I trust the other answers in that this must be impossible.
While I personally hate PHP, everybody has some good characteristics. One reason the PHP $ is very nice has to do with variable interpolation:
$bob = "rabbit"
$joe = "dragon-$bob" // ==> dragon-rabbit
That's pretty nice and short. In Ruby, since variables do not have to have any particular starting character, you have to type a bit more:
bob = "rabbit"
joe = "dragon-#{bob}"
And the same thing happens in Java (well, I left Java when you still had to use either StringBuffer or concatenate with " + bob + "
... I'm sure that's gone by now).
So the dollar sign is annoying and ugly, but here's at least one advantage (there must be more).
At the same time, if you try to write really nice PHP code (in spite of what you see around), you will start to see your code as elegant, and those dollar signs will be symbolic for... money!