RosettaCodeData/Task/Balanced-ternary/Phix/balanced-ternary-2.phix
2016-12-05 23:44:36 +01:00

16 lines
442 B
Text

atom t0 = time()
string f999 = dec2bt(1)
for i=2 to 999 do
f999 = bt_mul(f999,dec2bt(i))
end for
string f1000 = bt_mul(f999,dec2bt(1000))
printf(1,"In balanced ternary, f999 has %d digits and f1000 has %d digits\n",{length(f999),length(f1000)})
integer count = 0
f999 = negate(f999)
while f1000!="0" do
f1000 = bt_add(f1000,f999)
count += 1
end while
printf(1,"It took %d subtractions to reach 0. (%3.2fs)\n",{count,time()-t0})