https://github.com/binkley/sekwences
Explore various math sequences in Kotlin
https://github.com/binkley/sekwences
Last synced: 3 months ago
JSON representation
Explore various math sequences in Kotlin
- Host: GitHub
- URL: https://github.com/binkley/sekwences
- Owner: binkley
- License: unlicense
- Created: 2023-04-30T17:46:47.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-01-30T23:25:26.000Z (12 months ago)
- Last Synced: 2025-03-20T10:56:14.279Z (10 months ago)
- Language: Shell
- Size: 233 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Sekwences
[](https://github.com/binkley/sekwences/actions)
[](https://github.com/binkley/sekwences/pulls)
[](https://github.com/binkley/sekwences/issues/)
[](https://snyk.io/test/github/binkley/sekwences)
[](http://unlicense.org/)
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
- [_Inside Sequences: Create Your Own Sequence
Operations_](https://typealias.com/guides/inside-kotlin-sequences/)
- [_On-Line Encyclopedia of Integer Sequences_](https://oeis.org/wiki/Main_Page)