Skip to content

Instantly share code, notes, and snippets.

@joningold
Last active June 15, 2021 18:45
Show Gist options
  • Save joningold/bd7c77acbf2a788eafaad255ae47e14a to your computer and use it in GitHub Desktop.
Save joningold/bd7c77acbf2a788eafaad255ae47e14a to your computer and use it in GitHub Desktop.
Using a list of adjectives to describe a number
Include list_descriptions.ink
LIST QualityAdjectives = awful = -3, bad = -1, ambivalent = 0, nice = 1, great = 3, amazing = 7
LIST InterpersonalAdjectives = excruciating = -3, dull = -1, fine = 0, interesting = 1, intriguing = 3, charming = 7
- (swipeRight)
~ temp food = RANDOM(-5, 4)
~ temp company = RANDOM(-2, 9)
~ temp dateScore = food + company
"Dinner was {describe(food, QualityAdjectives)}, {company * food < 0:but|and} the company was {describe(company, InterpersonalAdjectives)}. {dateScore >= 2: It was wonderful!}<>"
* {dateScore >= 2} [Settle]
You get a car, two kids and a dog. S'ok.
-> END
+ [Try again]
-> swipeRight
=== function describe(score, list)
// Ideally, floor score to int ...
~ return describeSearching(score, list, 0)
=== function describeSearching(score, list, searchDirection)
~ temp fullReactions = LIST_ALL(list)
{
- score <= LIST_VALUE(LIST_MIN(fullReactions)):
~ return LIST_MIN(fullReactions)
- score >= LIST_VALUE(LIST_MAX(fullReactions)):
~ return LIST_MAX(fullReactions)
}
~ temp eval = _getListValueWithValue(score, LIST_ALL(fullReactions ))
{ eval:
~ return eval
}
{ searchDirection != 0:
~ return describeSearching(score + searchDirection, list, searchDirection)
}
~ temp evalminus = describeSearching(score-1, list, -1)
~ temp evalplus = describeSearching(score+1, list, 1)
{ score - LIST_VALUE(evalminus) < LIST_VALUE(evalplus) - score:
~ return evalminus
- else:
~ return evalplus
}
=== function _getListValueWithValue(resultIdx, sourceList)
// Replicates ListName(value) but for any list.
{ sourceList:
~ temp el = pop(sourceList)
{ LIST_VALUE(el) == resultIdx:
// Found it!
~ return el
}
// Keep looking
~ return _getListValueWithValue(resultIdx, sourceList)
}
// Give up (you passed a value that isn't in the list at all)
~ return ()
=== function pop(ref list)
~ temp el = LIST_MIN(list)
~ list -= el
~ return el
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment