Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,55 @@
def linearCombo(c)
sb = ""
c.each_with_index { |n, i|
if n == 0 then
next
end
if n < 0 then
if sb.length == 0 then
op = "-"
else
op = " - "
end
elsif n > 0 then
if sb.length > 0 then
op = " + "
else
op = ""
end
else
op = ""
end
av = n.abs()
if av != 1 then
coeff = "%d*" % [av]
else
coeff = ""
end
sb = sb + "%s%se(%d)" % [op, coeff, i + 1]
}
if sb.length == 0 then
return "0"
end
return sb
end
def main
combos = [
[1, 2, 3],
[0, 1, 2, 3],
[1, 0, 3, 4],
[1, 2, 0],
[0, 0, 0],
[0],
[1, 1, 1],
[-1, -1, -1],
[-1, -2, 0, -3],
[-1],
]
for c in combos do
print "%-15s -> %s\n" % [c, linearCombo(c)]
end
end
main()