실론, 195 바이트
Float[]s(Integer a,Integer b,Integer n)=>loop([a.float,b.float,[Float.divided,Float.plus,Float.times,Float.minus].cycled.rest])(([x,y,o])=>[y,(o.first else nothing)(x)(y),o.rest]).take(n)*.first;
형식화 및 의견 :
// Print the first n entries of the Stewies sequence with given starting entries.
//
// Question: http://codegolf.stackexchange.com/q/101145/2338
// My answer: http://codegolf.stackexchange.com/a/101251/2338
// Declare a function `s` which takes three integers, and returns a tuple
// of floats. (The more common syntax for the return value is [Float*],
// but Float[] is shorter.)
Float[] s(Integer a, Integer b, Integer n)
// it is implemented by evaluating the following expression for each call.
=>
// start a loop with ...
loop([
// ... float versions of the integers, and ...
a.float, b.float,
// ... an infinite sequence of the four operators, ever repeating.
// I needed the `.rest` here so the whole thing gets a {...*} type
// instead of {...+}, which doesn't fit to what o.rest returns.
// Each operator has the type Float(Float)(Float), i.e. you apply
// it twice to one float each to get a Float result.
[Float.divided, Float.plus, Float.times, Float.minus].cycled.rest])
// in each iteration of the loop, map the triple of two numbers
// and a sequence of operators to a triple of ...
(([x, y, o]) => [
// the second number,
y,
//the result of the first operator with both numbers
// (using this "else nothing" here to convince the
// compiler that o.first is not null),
(o.first else nothing)(x)(y),
// and the sequence of operators without its first element.
// (that one unfortunately has a {...*} type, i.e. a possibly
// empty sequence.)
o.rest])
// now we got an infinite sequence of those triples.
// We just want the first n of them ...
.take(n)
// and of each triple just the first element.
// (The *. syntax produces a tuple, non-lazily.
// We could also have used .map((z) => z.first)
// or .map(Iterable.first) or .map((z) => z[0]), each of
// which would return a (lazy) sequence, but they all would be
// longer.)
*.first;
사용법 예 :
shared void run() {
print(s(1, 3, 8));
print(s(0,1,11));
print(s(1,0,9));
print(s(6, 3, 29));
}
출력 예 :
[1.0, 3.0, 4.0, 12.0, -8.0, -1.5, -9.5, 14.25]
[0.0, 1.0, 1.0, 1.0, 0.0, Infinity, Infinity, Infinity, NaN, NaN, NaN]
[1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0]
[6.0, 3.0, 9.0, 27.0, -18.0, -1.5, -19.5, 29.25, -48.75, -0.6, -49.35, 29.61, -78.96000000000001, -0.37499999999999994, -79.33500000000001, 29.750625, -109.08562500000001, -0.2727272727272727, -109.35835227272727, 29.825005165289255, -139.18335743801651, -0.2142857142857143, -139.39764315230224, 29.870923532636194, -169.26856668493843, -0.17647058823529413, -169.44503727317374, 29.90206540114831, -199.34710267432206]
두 번째 예는 이것이 0으로 나누는 방법을 보여줍니다. 마지막 예는 어떤 종류의 산술 (및 반올림)이 사용 중인지에 따라 결과가 약간 벗어난다는 것을 보여줍니다 ... 실론의 64 비트 부동 소수점 산술은 질문에 게시 된 것보다 조금 더 가깝다고 생각합니다 .