Created
May 27, 2022 08:49
-
-
Save joningold/9e249ac59ae3e6edf8402a728295a719 to your computer and use it in GitHub Desktop.
Assigning Values to List Items
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
LIST Entrants = PabloPicasso, VanGogh, LucyPhillipsAged11 | |
~ temp place = 3 | |
- (loop) | |
{ stopping: | |
- "Third place in the art competition goes to..." | |
- "Second place goes to..." | |
- "And so the winner is..." | |
} | |
* {getValueOfState(PabloPicasso) == 0} "Pablo Picasso!" | |
~ setValueOfState( PabloPicasso, place) | |
* {getValueOfState(VanGogh) == 0} "Vincent Van Gogh!" | |
~ setValueOfState( VanGogh, place) | |
* {getValueOfState(LucyPhillipsAged11) == 0} "Lucy Phillips, Aged 11!" | |
~ setValueOfState( LucyPhillipsAged11, place) | |
- { place > 1: | |
~ place-- | |
-> loop | |
} | |
{ getValueOfState(PabloPicasso) == 1: | |
Picasso nods sanguinely. | |
} | |
{ getValueOfState(LucyPhillipsAged11) == 1: | |
Lucy dances on the spot! | |
} | |
{ getValueOfState(VanGogh) == 1: | |
Van Gogh blushes from ear. | |
} | |
{ getValueOfState(LucyPhillipsAged11) == 3: | |
Lucy punches an angry hole through her canvas. | |
} | |
{ getValueOfState(VanGogh) == 3: | |
Van Gogh sighs sadly. | |
} | |
{ getValueOfState(PabloPicasso) == 3: | |
Picasso starts drink moodily. | |
} | |
-> DONE | |
// 1) Storage space | |
VAR StatesBinary1 = "" | |
VAR StatesBinary2 = "" | |
VAR StatesBinary4 = "" | |
VAR StatesBinary8 = "" | |
VAR StatesBinary16 = "" | |
VAR StatesBinary32 = "" | |
VAR StatesBinary64 = "" | |
VAR StatesBinary128 = "" | |
VAR StatesBinary256 = "" | |
VAR StatesBinary512 = "" | |
VAR StatesBinary1024 = "" | |
VAR StatesBinary2048 = "" // storage up to 4095 | |
// --> ADDITIONAL STORAGE GOES HERE | |
CONST MAX_BINARY_BIT = 2048 | |
// 2) Get value for state being set | |
=== function getValueOfState(state) // always single | |
// do this the dumb long way rather than a fancy loop | |
~ temp value = 0 | |
~ temp id = stateID(state) | |
~ value += returnIfTrue(StatesBinary1 ? id, 1) | |
~ value += returnIfTrue(StatesBinary2 ? id, 2) | |
~ value += returnIfTrue(StatesBinary4 ? id, 4) | |
~ value += returnIfTrue(StatesBinary8 ? id, 8) | |
~ value += returnIfTrue(StatesBinary16 ? id, 16) | |
~ value += returnIfTrue(StatesBinary32 ? id, 32) | |
~ value += returnIfTrue(StatesBinary64 ? id, 64) | |
~ value += returnIfTrue(StatesBinary128 ? id, 128) | |
~ value += returnIfTrue(StatesBinary256 ? id, 256) | |
~ value += returnIfTrue(StatesBinary512 ? id, 512) | |
~ value += returnIfTrue(StatesBinary1024 ? id, 1024) | |
~ value += returnIfTrue(StatesBinary2048 ? id, 2048) | |
// --> ADDITIONAL STORAGE GOES HERE | |
~ return value | |
// 3) Set value for state being set | |
=== function setValueOfState(state, value) // always single | |
{ value >= 2 * MAX_BINARY_BIT: | |
[ ERROR - trying to store a value of {value}, which is the space provided. Please increase {MAX_BINARY_BIT}, and supply additional storage values. ] | |
} | |
~ _setBinaryValuesForState(stateID(state), value, MAX_BINARY_BIT ) | |
// [ {value} - set value for {state} to {getValueOfState(state) } ] | |
=== function _setBinaryValuesForState(id, value, binaryValue) | |
{ value >= binaryValue: | |
~ value -= binaryValue | |
{binaryValue: | |
- 1: ~ StatesBinary1 += id | |
- 2: ~ StatesBinary2 += id | |
- 4: ~ StatesBinary4 += id | |
- 8: ~ StatesBinary8 += id | |
- 16: ~ StatesBinary16 += id | |
- 32: ~ StatesBinary32 += id | |
- 64: ~ StatesBinary64 += id | |
- 128: ~ StatesBinary128 += id | |
- 256: ~ StatesBinary256 += id | |
- 512: ~ StatesBinary512 += id | |
- 1024: ~ StatesBinary1024 += id | |
- 2048: ~ StatesBinary2048 += id | |
// --> ADDITIONAL STORAGE GOES HERE | |
} | |
} | |
{ binaryValue > 1: | |
~ _setBinaryValuesForState(id, value, binaryValue / 2) | |
} | |
// 2) Auxiliary functions | |
=== function stateID(x) | |
~ return ":{x};" | |
=== function returnIfTrue(test, val) | |
{test: | |
~ return val | |
- else: | |
~ return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment