Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
object LinearCombination extends App {
|
||||
val combos = Seq(Seq(1, 2, 3), Seq(0, 1, 2, 3),
|
||||
Seq(1, 0, 3, 4), Seq(1, 2, 0), Seq(0, 0, 0), Seq(0),
|
||||
Seq(1, 1, 1), Seq(-1, -1, -1), Seq(-1, -2, 0, -3), Seq(-1))
|
||||
|
||||
private def linearCombo(c: Seq[Int]): String = {
|
||||
val sb = new StringBuilder
|
||||
for {i <- c.indices
|
||||
term = c(i)
|
||||
if term != 0} {
|
||||
val av = math.abs(term)
|
||||
def op = if (term < 0 && sb.isEmpty) "-"
|
||||
else if (term < 0) " - "
|
||||
else if (term > 0 && sb.isEmpty) "" else " + "
|
||||
|
||||
sb.append(op).append(if (av == 1) "" else s"$av*").append("e(").append(i + 1).append(')')
|
||||
}
|
||||
if (sb.isEmpty) "0" else sb.toString
|
||||
}
|
||||
for (c <- combos) {
|
||||
println(f"${c.mkString("[", ", ", "]")}%-15s -> ${linearCombo(c)}%s")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue