2021-03-15 05:47:13 +00:00
|
|
|
|
package tf.bug.fancade
|
|
|
|
|
|
|
|
|
|
object Main {
|
|
|
|
|
|
|
|
|
|
def main(args: Array[String]): Unit = {
|
|
|
|
|
import Fanscript._
|
|
|
|
|
import tf.bug.shinji.syntax.all._
|
2021-05-07 04:53:09 +00:00
|
|
|
|
// min, max, start, result, after -> end, index, sum, before
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val sum: (Number.type × Number.type × Pull.type × Number.type × Pull.type) → (Pull.type × Number.type × Number.type × Pull.type) = {
|
|
|
|
|
val getSum: T.type → Number.type = Builtin.GetNumber("Sum")
|
|
|
|
|
val setSum: (Number.type × Pull.type) → Pull.type = Builtin.SetNumber("Sum")
|
|
|
|
|
val addToSum: (Number.type × Pull.type) → Pull.type = {
|
|
|
|
|
val add: (Number.type × Number.type) → Number.type = Builtin.AddNumbers
|
|
|
|
|
val sumAsFirstInput: (T.type × Number.type) → (Number.type × Number.type) = fanscript.first(getSum)
|
|
|
|
|
val branch: Number.type → (T.type × Number.type) = fanscript.deunitorLeft
|
|
|
|
|
val justSecondInput: Number.type → (Number.type × Number.type) = fanscript.andThen(branch, sumAsFirstInput)
|
|
|
|
|
val addSum: Number.type → Number.type = fanscript.ldimap[Number.type × Number.type, Number.type, Number.type](justSecondInput).apply(add)
|
|
|
|
|
val storeSum: (Number.type × Pull.type) → Pull.type = setSum
|
|
|
|
|
fanscript.ldimap[Number.type × Pull.type, Pull.type, Number.type × Pull.type](fanscript.lbimap(addSum)).apply(storeSum)
|
2021-03-15 05:47:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val getIndex: T.type → Number.type = Builtin.GetNumber("Index")
|
|
|
|
|
val setIndex: (Number.type × Pull.type) → Pull.type = Builtin.SetNumber("Index")
|
|
|
|
|
val indexGreaterThan: Number.type → Bool.type = {
|
|
|
|
|
val greaterThan: (Number.type × Number.type) → Bool.type = Builtin.GreaterThan
|
|
|
|
|
val indexAsFirstInput: (T.type × Number.type) → (Number.type × Number.type) = fanscript.first(getIndex)
|
|
|
|
|
val branch: Number.type → (T.type × Number.type) = fanscript.deunitorLeft
|
|
|
|
|
val comparisonAsSecondInput: Number.type → (Number.type × Number.type) = fanscript.andThen(branch, indexAsFirstInput)
|
|
|
|
|
fanscript.andThen(comparisonAsSecondInput, greaterThan)
|
2021-05-07 04:53:09 +00:00
|
|
|
|
}
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val indexNotGreaterThan: Number.type → Bool.type = fanscript.andThen(indexGreaterThan, Builtin.Not)
|
|
|
|
|
val checkContinue: (Number.type × Pull.type × Pull.type × Pull.type) → Pull.type = {
|
|
|
|
|
val ifBlock: (Bool.type × Pull.type × Pull.type × Pull.type) → Pull.type = Builtin.If
|
|
|
|
|
val checkGreater: (Number.type × Pull.type × Pull.type × Pull.type) → (Bool.type × Pull.type × Pull.type × Pull.type) = {
|
|
|
|
|
val one: (Number.type × Pull.type) → (Bool.type × Pull.type) = fanscript.first(indexGreaterThan)
|
|
|
|
|
val two: (Number.type × Pull.type × Pull.type) → (Bool.type × Pull.type × Pull.type) = fanscript.first(one)
|
|
|
|
|
val three: (Number.type × Pull.type × Pull.type × Pull.type) → (Bool.type × Pull.type × Pull.type × Pull.type) = fanscript.first(two)
|
2021-05-07 04:53:09 +00:00
|
|
|
|
three
|
|
|
|
|
}
|
|
|
|
|
fanscript.andThen(checkGreater, ifBlock)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// sumToIndex -> before
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val initializeSum: Pull.type → Pull.type = {
|
|
|
|
|
val zero: T.type → Number.type = Builtin.NumberValue(0.0F)
|
|
|
|
|
val zeroAsInput: (T.type × Pull.type) → (Number.type × Pull.type) = fanscript.first(zero)
|
|
|
|
|
val branch: Pull.type → (T.type × Pull.type) = fanscript.deunitorLeft[Pull.type]
|
|
|
|
|
fanscript.andThen(fanscript.andThen(branch, zeroAsInput), setSum)
|
2021-05-07 04:53:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// min, indexToLoopStart -> sumToIndex
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val initializeIndex: (Number.type × Pull.type) → Pull.type = setIndex
|
2021-05-07 04:53:09 +00:00
|
|
|
|
|
|
|
|
|
// max, start, ◌, after -> (indexToLoopStart + incrementToLoop)
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val startLoop: (Number.type × Pull.type × Pull.type × Pull.type) → Pull.type = checkContinue
|
2021-05-07 04:53:09 +00:00
|
|
|
|
|
|
|
|
|
// result, increaseSum -> end
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val increaseSum: (Number.type × Pull.type) → Pull.type = addToSum
|
2021-05-07 04:53:09 +00:00
|
|
|
|
|
|
|
|
|
// incrementToLoop -> increaseSum
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val incrementIndex: Pull.type → Pull.type = {
|
|
|
|
|
val get: T.type → Number.type = getIndex
|
|
|
|
|
val set: (Number.type × Pull.type) → Pull.type = setIndex
|
|
|
|
|
val one: T.type → Number.type = Builtin.NumberValue(1.0F)
|
|
|
|
|
val additionOperands: T.type → (Number.type × Number.type) = fanscript.merge(get, one)
|
|
|
|
|
val add: T.type → Number.type = fanscript.andThen(additionOperands, Builtin.AddNumbers)
|
|
|
|
|
val carryPull: (T.type × Pull.type) → (Number.type × Pull.type) = fanscript.first(add)
|
|
|
|
|
val branch: Pull.type → (T.type × Pull.type) = fanscript.deunitorLeft[Pull.type]
|
|
|
|
|
fanscript.andThen(fanscript.andThen(branch, carryPull), set)
|
2021-05-07 04:53:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// min, indexToLoopStart -> before
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val initialize: (Number.type × Pull.type) → Pull.type = fanscript.andThen(initializeIndex, initializeSum)
|
2021-05-07 04:53:09 +00:00
|
|
|
|
|
|
|
|
|
// result, incrementToLoop -> end
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val postLoop: (Number.type × Pull.type) → Pull.type = {
|
|
|
|
|
val carryResult = fanscript.second[Pull.type, Pull.type, Number.type](incrementIndex)
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.andThen(carryResult, increaseSum)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// max, start, after -> (indexToLoopStart + incrementToLoop)
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val condition: (Number.type × Pull.type × Pull.type) → Pull.type = {
|
|
|
|
|
val zThree: (Number.type × Pull.type) → (Number.type × Pull.type × Pull.type) =
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.andThen(fanscript.deunitorRight, fanscript.rbimap(Z))
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val zFour: (Number.type × Pull.type × Pull.type) → (Number.type × Pull.type × Pull.type × Pull.type) =
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.lbimap(zThree)
|
2021-05-08 00:23:05 +00:00
|
|
|
|
fanscript.ldimap[Number.type × Pull.type × Pull.type × Pull.type, Pull.type, Number.type × Pull.type × Pull.type](zFour).apply(checkContinue)
|
2021-05-07 04:53:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// min, max, start, result, after -> end, index, sum, before
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val result: (Number.type × Number.type × Pull.type × Number.type × Pull.type) → (Pull.type × Number.type × Number.type × Pull.type) = {
|
2021-05-07 04:53:09 +00:00
|
|
|
|
// max, start, after -> indexToLoopStart, incrementToLoop
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val duplicateCondition: (Number.type × Pull.type × Pull.type) → (Pull.type × Pull.type) =
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.andThen(condition, fanscript.duplicate)
|
|
|
|
|
|
|
|
|
|
// min, indexToLoopStart, result, incrementToLoop -> before, end
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val conditionPrecursors: (Number.type × Pull.type × Number.type × Pull.type) → (Pull.type × Pull.type) =
|
|
|
|
|
fanscript.associateRight[Number.type × Pull.type, Number.type, Pull.type] >>> (initialize *** postLoop)
|
2021-05-07 04:53:09 +00:00
|
|
|
|
|
|
|
|
|
// min, result, (indexToLoopStart, incrementToLoop) -> end, before
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val orientConditionPrecursors: ((Number.type × Number.type) × (Pull.type × Pull.type)) → (Pull.type × Pull.type) = {
|
|
|
|
|
val flattenAssoc: ((Number.type × Number.type) × (Pull.type × Pull.type)) → (((Number.type × Number.type) × Pull.type) × Pull.type) = fanscript.associateLeft
|
|
|
|
|
val assocInside: (((Number.type × Number.type) × Pull.type) × Pull.type) → ((Number.type × (Number.type × Pull.type)) × Pull.type) = fanscript.lbimap(fanscript.associateRight)
|
|
|
|
|
val swapInside: ((Number.type × (Number.type × Pull.type)) × Pull.type) → ((Number.type × (Pull.type × Number.type)) × Pull.type) = fanscript.lbimap(fanscript.rbimap(fanscript.swap))
|
|
|
|
|
val reassocInside: ((Number.type × (Pull.type × Number.type)) × Pull.type) → (((Number.type × Pull.type) × Number.type) × Pull.type) = fanscript.lbimap(fanscript.associateLeft)
|
|
|
|
|
val orientConditionInputs: ((Number.type × Number.type) × (Pull.type × Pull.type)) → (((Number.type × Pull.type) × Number.type) × Pull.type) =
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.andThen(fanscript.andThen(fanscript.andThen(flattenAssoc, assocInside), swapInside), reassocInside)
|
|
|
|
|
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val swapEnd: (Pull.type × Pull.type) → (Pull.type × Pull.type) = fanscript.swap
|
2021-05-07 04:53:09 +00:00
|
|
|
|
|
|
|
|
|
fanscript.dimap(orientConditionInputs, swapEnd)(conditionPrecursors)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// min, max, start, result, after -> end, before
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val nonNumbers: (Number.type × Number.type × Pull.type × Number.type × Pull.type) → (Pull.type × Pull.type) = {
|
|
|
|
|
val duplicateConditionLeftNumbers: ((Number.type × Number.type) × (Number.type × Pull.type × Pull.type)) → ((Number.type × Number.type) × (Pull.type × Pull.type)) =
|
|
|
|
|
fanscript.second[Number.type × Pull.type × Pull.type, Pull.type × Pull.type, Number.type × Number.type](duplicateCondition)
|
2021-05-07 04:53:09 +00:00
|
|
|
|
|
|
|
|
|
// (min, result), (max, start, after) -> end, before
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val aggregate: ((Number.type × Number.type) × (Number.type × Pull.type × Pull.type)) → (Pull.type × Pull.type) =
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.andThen(duplicateConditionLeftNumbers, orientConditionPrecursors)
|
|
|
|
|
|
|
|
|
|
// (max, start, after, (min, result)) -> end, before
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val align: (Number.type × Pull.type × Pull.type × (Number.type × Number.type)) → (Pull.type × Pull.type) =
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.andThen(fanscript.swap, aggregate)
|
|
|
|
|
|
|
|
|
|
// max, start, after, min, result -> end, before
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val assoc: (Number.type × Pull.type × Pull.type × Number.type × Number.type) → (Pull.type × Pull.type) =
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.andThen(fanscript.associateRight, align)
|
|
|
|
|
|
|
|
|
|
// min, max, start, result, after -> max, start, after, min, result
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val realign: ((((Number.type × Number.type) × Pull.type) × Number.type) × Pull.type) → ((((Number.type × Pull.type) × Pull.type) × Number.type) × Number.type) = {
|
|
|
|
|
val one: ((((Number.type × Number.type) × Pull.type) × Number.type) × Pull.type) → (((Number.type × (Number.type × Pull.type)) × Number.type) × Pull.type) =
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.lbimap(fanscript.lbimap(fanscript.associateRight))
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val two: (((Number.type × (Number.type × Pull.type)) × Number.type) × Pull.type) → ((((Number.type × Pull.type) × Number.type) × Number.type) × Pull.type) =
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.lbimap(fanscript.lbimap(fanscript.swap))
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val three: ((((Number.type × Pull.type) × Number.type) × Number.type) × Pull.type) → (((Number.type × Pull.type) × Number.type) × (Number.type × Pull.type)) =
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.associateRight
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val four: (((Number.type × Pull.type) × Number.type) × (Number.type × Pull.type)) → (((Number.type × Pull.type) × Number.type) × (Pull.type × Number.type)) =
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.rbimap(fanscript.swap)
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val five: (((Number.type × Pull.type) × Number.type) × (Pull.type × Number.type)) → ((((Number.type × Pull.type) × Number.type) × Pull.type) × Number.type) =
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.associateLeft
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val six: ((((Number.type × Pull.type) × Number.type) × Pull.type) × Number.type) → (((Number.type × Pull.type) × (Number.type × Pull.type)) × Number.type) =
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.lbimap(fanscript.associateRight)
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val seven: (((Number.type × Pull.type) × (Number.type × Pull.type)) × Number.type) → (((Number.type × Pull.type) × (Pull.type × Number.type)) × Number.type) =
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.lbimap(fanscript.rbimap(fanscript.swap))
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val eight: (((Number.type × Pull.type) × (Pull.type × Number.type)) × Number.type) → ((((Number.type × Pull.type) × Pull.type) × Number.type) × Number.type) =
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.lbimap(fanscript.associateLeft)
|
|
|
|
|
|
|
|
|
|
fanscript.andThen(
|
|
|
|
|
fanscript.andThen(
|
|
|
|
|
fanscript.andThen(
|
|
|
|
|
fanscript.andThen(
|
|
|
|
|
fanscript.andThen(
|
|
|
|
|
fanscript.andThen(
|
|
|
|
|
fanscript.andThen(
|
|
|
|
|
one,
|
|
|
|
|
two
|
|
|
|
|
),
|
|
|
|
|
three
|
|
|
|
|
),
|
|
|
|
|
four
|
|
|
|
|
),
|
|
|
|
|
five
|
|
|
|
|
),
|
|
|
|
|
six
|
|
|
|
|
),
|
|
|
|
|
seven
|
|
|
|
|
),
|
|
|
|
|
eight
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fanscript.andThen(realign, assoc)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// end, before -> end, index, sum, before
|
2021-05-08 00:23:05 +00:00
|
|
|
|
val addOutputs: (Pull.type × Pull.type) → (Pull.type × Number.type × Number.type × Pull.type) =
|
2021-05-07 04:53:09 +00:00
|
|
|
|
fanscript.lbimap(fanscript.andThen(
|
2021-05-08 00:23:05 +00:00
|
|
|
|
fanscript.andThen[Pull.type, Pull.type × T.type, Pull.type × Number.type](fanscript.deunitorRight[Pull.type], fanscript.rbimap(getIndex)),
|
|
|
|
|
fanscript.andThen[Pull.type × Number.type, Pull.type × Number.type × T.type, Pull.type × Number.type × Number.type](fanscript.deunitorRight[Pull.type × Number.type], fanscript.rbimap(getSum))
|
2021-05-07 04:53:09 +00:00
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
fanscript.andThen(nonNumbers, addOutputs)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result
|
2021-03-15 05:47:13 +00:00
|
|
|
|
}
|
2021-05-07 04:53:09 +00:00
|
|
|
|
|
|
|
|
|
pprint.pprintln(sum)
|
2021-03-15 05:47:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|