1
$\begingroup$

For a certain sequence of numbers, the sum of the first $n$ numbers in the sequence is given by $n^3+4n$ for all positive integers $n$. What is the fifteenth number in the sequence?

How do you solve this problem the most efficient way?

$\endgroup$
  • $\begingroup$ Are you sure you're on an appropriate site? This one is for Mathematica programming. $\endgroup$ – Artes Oct 9 '15 at 4:10
  • $\begingroup$ Step 1: Ask on the right fora. You're after math.stackexchange... $\endgroup$ – ciao Oct 9 '15 at 4:10
  • 4
    $\begingroup$ Ask how to solve it on a site full of people who like solving problems? :-) $\endgroup$ – Brett Champion Oct 9 '15 at 4:22
  • $\begingroup$ People coming in from the hot questions list, please note the answers are fancy looking ways to do subtraction. I seriously don't understand the top answer (as in, why the duck that is the top answer), top answer should be s(15)-s(14) $\endgroup$ – Alec Teal Oct 9 '15 at 9:35
  • $\begingroup$ @AlecTeal The reason why my fellow Mathematica(TM) programmers and scientists found my answer interesting is because it's a literal translation to Mathematica(TM) of the problem exactly as posed by the OP (Solve fizz when buzz happens), without thinking in the math involved, and showing that Mathematica (TM) is able to solve it without human "intervention" $\endgroup$ – Dr. belisarius Oct 9 '15 at 13:17
9
$\begingroup$
Solve[Table[Sum[f[i], {i, 1, n}] == n^3 + 4 n, {n, 15}], Array[f, 15]]

(*
 {{f[1] -> 5, f[2] -> 11, f[3] -> 23, f[4] -> 41, f[5] -> 65, 
   f[6] -> 95, f[7] -> 131, f[8] -> 173, f[9] -> 221, f[10] -> 275, 
   f[11] -> 335, f[12] -> 401, f[13] -> 473, f[14] -> 551, 
   f[15] -> 635}}
 *)
$\endgroup$
  • $\begingroup$ "the most efficient way" is the one that takes you less time $\endgroup$ – Dr. belisarius Oct 9 '15 at 4:15
  • $\begingroup$ I love this for not doing any analysis of the problem; just plugin what you know and have it solved. $\endgroup$ – Brett Champion Oct 9 '15 at 4:18
  • $\begingroup$ @BrettChampion ha! That's why I wrote the comment above :) $\endgroup$ – Dr. belisarius Oct 9 '15 at 4:19
  • $\begingroup$ My solutions were variants of Differences[Table[n^3 + 4 n, {n, 0, 15}]], but that requires a step of reasoning first. $\endgroup$ – Brett Champion Oct 9 '15 at 4:20
  • 1
    $\begingroup$ @BrettChampion Thinking is cheating :) $\endgroup$ – Dr. belisarius Oct 9 '15 at 4:20
7
$\begingroup$
(FindSequenceFunction@ Differences[Prepend[n^3 + 4 n /. n -> Range@10, 0]])@15

(* 635 *)
$\endgroup$
6
$\begingroup$

Might as well...

DifferenceDelta[n^3 + 4 n, n] /. n -> 15 - 1
$\endgroup$
  • 1
    $\begingroup$ That's the one function I always forget among the 848747 built-ins ;-} +1 $\endgroup$ – ciao Oct 9 '15 at 6:03
  • $\begingroup$ Familiarity with the difference calculus has so far served me well. :) $\endgroup$ – J. M. will be back soon Oct 9 '15 at 6:08
5
$\begingroup$

Let $S_n=\sum^n_{j=1}a_n$. So $a_n=S_n-S_{n-1}$.

5 - 3 n + 3 n^2 /. n -> 15

yields 635. (Mathematica can obviously do this).

$\endgroup$
  • $\begingroup$ I saw the beginning of your answer and thought you were going to give an answer suitable for math.se. $\endgroup$ – Brett Champion Oct 9 '15 at 6:41
  • $\begingroup$ @BrettChampion...I can delete if you feel this is not in the spirit of the site. I just thought given the precise expression of the question, this was the simplest approach... $\endgroup$ – ubpdqn Oct 9 '15 at 6:44
  • $\begingroup$ This is more or less what DifferenceDelta[] does, made explicit. $\endgroup$ – J. M. will be back soon Oct 9 '15 at 8:15
  • $\begingroup$ @J. M. yes...I am sorry if it seemed like being a wise-guy...I just thought simplicity was warranted...I did upvote your answer as I was not aware of DifferenceDelta. I am happy to delete and acknowledge all the answers get to the same result. :) $\endgroup$ – ubpdqn Oct 9 '15 at 8:19
  • $\begingroup$ No, I didn't take it like that! I was merely adding an explanatory note; at least, OP will need to think a little bit more for your solution. :) $\endgroup$ – J. M. will be back soon Oct 9 '15 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.