2
$\begingroup$

I would like to Write a function which takes a list of numerators, of arbitrary length, and produces a simple continued fraction of the form

    cf[{a,b,c,d}] =  a/(1+b/(1+c/(1+d)))

So far I did this

    cf[a_, b_, c_, d_] = Fold[g, 0, { d, c, b, a}]

but I do not know how to generalise it to a list of arbitrary length, so that user can type in any number of variables.

$\endgroup$
3
$\begingroup$

This should work:

cf[a__] := Fold[g, 0, {a}]
| improve this answer | |
$\endgroup$
  • $\begingroup$ Is this a pattern of a pattern? $\endgroup$ – Henry Wang Apr 29 '17 at 0:25
  • $\begingroup$ @HenryWang I am not sure what you mean, but if you use the trusty Help, it will tell you that it is a BlankSequence, which matches any number of elements. $\endgroup$ – Igor Rivin Apr 29 '17 at 0:26
  • $\begingroup$ Aha, thank you! I thought it is basically Blank of a Blank. But I think I am mistaken. $\endgroup$ – Henry Wang Apr 29 '17 at 0:35

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.