Skip to content

binkley/sekwences

Repository files navigation

Public Domain

Sekwences

build pull requests issues vulnerabilities license

Explore various math sequences in Kotlin.

Build and try

To build, use ./mvnw clean verify. Try ./run for a demonstration.

To build as CI would, use ./batect build. Try ./batect run for a demonstration as CI would.

This project assumes JDK 17. There are no run-time dependencies beyond the Kotlin standard library.

Sequences

"Flip-flop"

"Flip-flop" refers to a sequence defined as:

  • Given non-negative integers
  • Given an open boundary (cap) value, M
  • Given a starting value (seed), a1 less than M
  • Given a function, f, such the next sequence value f(current value). f is essentially a "fold left" function that starts with the initial seed value
  • When the current sequence value exceeds the cap, subtract the overage from the cap; that is the next sequence value
  • Stop when seeing a previously seen sequence value (you have found a loop)

This code explores M equal to 100, and f equal to 2X (doubling the previous value), and impact of adjusting M or f.

Questions to explore:

  • Do all values result in cycles smaller than exhausting the entire range?
  • What are distinct cycles sharing no values in common? These are orthogonal (in some sense)
  • How does changing M change cycles?
  • How does changing f change cycles?
  • What minimizes or maximizes cycle lengths?
  • Are there non-trivial isolated cycles that only repeat to themselves? (A trivial example is starting with 0 as a sequence seed and using 2x as the function to compute the next sequence value.)
  • What are restrictions on f to stay "close" within range? Should sequence expectations stay within some range? For example e^x blows up (exceeds expected bounds) but does produce a cycle

This sequence was a bedtime exercise akin to "counting sheep."

Reading

About

Explore various math sequences in Kotlin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published