Last active
July 11, 2021 01:37
-
-
Save joningold/05c72a144ec50f9d65251f13a1f47a05 to your computer and use it in GitHub Desktop.
A quick system for printing from a list by index in ink
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~ temp charA = RANDOM(1, 10000) | |
~ temp charB = RANDOM(1, 10000) | |
{characterName(charA)} and {characterName(charB)} walk into a bar. {characterName(charA)} is feeling {~ worried|happy}. | |
=== function characterName(nameSeed) | |
{firstNameByIndex(nameSeed / 100)} {secondNameByIndex(nameSeed % 100)} | |
=== function firstNamesInAList() | |
~ return "{&Annabel|Barbara|Charles|Douglas|Eoife|Fern|Ginger|Harriet|Ingrid|Jules|Karina|Lilian}" | |
=== function firstNameByIndex(k) | |
VAR _firstNameCycleLength = 0 | |
~ return getByIndex(-> firstNamesInAList, k, _firstNameCycleLength) | |
=== function secondNamesInAList() | |
~ return "{&Adams|Best|Cartwright|Dundee|Eggsby|Fartington|Goffard|Hutches|Illis|Jalowsky}" | |
=== function secondNameByIndex(k) | |
VAR _secondNameCycleLength = 0 | |
~ return getByIndex(-> secondNamesInAList, k, _secondNameCycleLength) | |
/* ---- | |
Internal stuff | |
---- */ | |
=== function getByIndex( -> nameCycle, idx, ref cycleLength) | |
{ cycleLength == 0: | |
~ cycleLength = detectCycleLength("{nameCycle()}", nameCycle, 1) | |
~ spoolCycle(nameCycle, cycleLength - 1) | |
} | |
{getNthFromCycle(nameCycle, idx, cycleLength)} | |
=== function detectCycleLength(firstInstance, -> nameCycle, k) | |
~ temp nextInstance = "{nameCycle()}" | |
{ firstInstance != nextInstance: | |
// [ {firstInstance} / {nextInstance} ] | |
~ return detectCycleLength(firstInstance, nameCycle, k+1) | |
} | |
// [ {k} ] | |
~ return k | |
=== function getNthFromCycle(-> nameCycle, idx, cycleLength) | |
~ idx = idx mod cycleLength | |
{ idx == 0: | |
~ idx = cycleLength | |
} | |
// [ get no. {idx} ] | |
~ spoolCycle(nameCycle, idx-1) | |
~ temp nextInstance = "{nameCycle()}" | |
// [ got {nextInstance} ] | |
~ spoolCycle(nameCycle, cycleLength-idx) | |
~ return "{nextInstance}" | |
=== function spoolCycle(-> nameCycle, timesToSpool) | |
{ timesToSpool > 0: | |
~ temp nextInstance = "{nameCycle()}" | |
// [ spool through {nextInstance } ] | |
~ return spoolCycle(nameCycle, timesToSpool - 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment