function continued_fraction(num, denom)
a = []
quo, rem = divrem(num, denom)
a0 = quo
push!(a, a0)
num = denom
denom = rem
i = 1
while (rem != 0)
quo, rem = divrem(num, denom)
push!(a, quo)
num = denom
denom = rem
i += 1
end
return(a)
end
a = continued_fraction(1001, 64)
println(a)

I am experimenting writing continued fraction functions; at present restricted to integers, as shown above.

I got the above to work, but I want the array or vector a to be an integer so that I do not get the Any in front of the output.

But I have found that push! does not work with an Int64 array.

[] is equivalant to Any[] and creates an empty vector that can hold values of any type. Int[] creates an empty vector that can hold values of type Int.

It is a bit unclear what you tried that didn’t work, but your code runs if you change [] to Int[] at least.

Int is just an alias for your native integer type, on most systems this is equivalent to Int64 (64-bit integer).

That is a type not a value with that type. You could use Array{Int, 1}(), or the equivalent Vector{Int}(), but using Int[] is the most common method I think.

I don’t know what this means – there are no commas printed in my output:

The output from my above code, using a file rather than the REPL, gives me a row vector: [15, 1, 1, 1, 3, 1, 1, 2]

If I can change the first comma to a semi-colon, keeping the other commas intact, the output will be in one of the standard ways to express continued fractions.

Initially, I am going from a fraction to a continued fraction expansion.

I am not thinking now of the reverse process of going from the continued fraction to the fraction.

I have to read up on structs (like C?) before I take up your hint of one data structure for the forward and reverse directions. It strikes me as a clean approach.