Love letter

This commit is contained in:
gauthiier 2023-01-16 10:43:25 +01:00
parent 641a48ed4d
commit 953780d09e

View File

@ -311,19 +311,20 @@ MUC
Can you decipher certain writing patterns in the above formulations? If so, what are they? Can you decipher certain writing patterns in the above formulations? If so, what are they?
Consider this sentence: Consider the following sentences:
``` ```
MY YEARNING FERVENTLY LIKES YOUR AMOROUS PASSION. MY YEARNING FERVENTLY LIKES YOUR AMOROUS PASSION.
MY APPETITE TENDERLY CHERISHES YOUR BEAUTIFUL WISH.
``` ```
We can "code" this sentence as follow: We can "code" this sentence as follow:
```determiner``` + ```noun``` + ```adverb``` + ```verb``` + ```determiner``` + ```adjective``` + ```noun``` + . MY + ```noun``` + ```adverb``` + ```verb``` + YOUR + ```adjective``` + ```noun``` + .
In fact, we could even add an ```adjective``` before the first ```noun``` as to make it even more "wordy": In fact, we could even add an ```adjective``` before the first ```noun``` as to make it even more "wordy":
```determiner``` + ```adjective``` + ```noun``` + ```adverb``` + ```verb``` + ```determiner``` + ```adjective``` + ```noun``` + . MY + ```adjective``` + ```noun``` + ```adverb``` + ```verb``` + YOUR + ```adjective``` + ```noun``` + .
Now consider this sentence, whose structure seems to come up often: Now consider this sentence, whose structure seems to come up often:
@ -346,7 +347,7 @@ Which can be coded as:
MY + ```adjective``` + ```noun``` + . MY + ```adjective``` + ```noun``` + .
So we have two types of sentences: So we have two types of sentences:
* long form: ```determiner``` + ```noun``` + ```adverb``` + ```verb``` + ```determiner``` + ```adjective``` + ```noun``` + . * long form: MY + ```noun``` + ```adverb``` + ```verb``` + YOUR + ```adjective``` + ```noun``` + .
* short form: YOU ARE MY + ```adjective``` + ```noun``` + . OR MY + ```adjective``` + ```noun``` + . * short form: YOU ARE MY + ```adjective``` + ```noun``` + . OR MY + ```adjective``` + ```noun``` + .
In terms of sentences sequencing we notice that: In terms of sentences sequencing we notice that:
@ -383,8 +384,50 @@ function choice(array_to_choose_from) {
let random_index = floor(random(array_to_choose_from.length)); let random_index = floor(random(array_to_choose_from.length));
return array_to_choose_from[random_index]; return array_to_choose_from[random_index];
} }
```
With both these elements we can start devising the code of the long form we identified above.
MY + ```noun``` + ```adverb``` + ```verb``` + YOUR + ```adjective``` + ```noun``` + .
Let's do this coding with a function again:
```javascript
// function that randomly generates a long form sentence
function long() {
return "MY " + choice(nouns) + " " + choice(adverbs) + " " + choice(verbs) + " YOUR " + choice(adjectives) + " " + choice(nouns) + ".";
}
```` ````
This will certainly work. Yet I would like to have more variation with the sentences the function returns. At the moment it will always follow the long form structure.
How about we make ```adjective``` and ```adverb``` non mandatory, meaning they maybe there or maybe not. What I have in mind is something like:
```javascript
// function that randomly generates a long form sentence
function long() {
return "MY " + maybe(adjectives) + " " + choice(nouns) + " " + maybe(adverbs) + " " + choice(verbs) + " YOUR " + maybe(adjectives) + " " + choice(nouns) + ".";
}
````
To decide if an element (```adjective``` and ```adverb```) should be there or not we will write a ```maybe``` function which will randomly choose true or false if the element should be chose from an array.
```javascript
// function that randomly decides if an element from an array should be selected or not
function maybe(array_to_choose_from) {
// choose between true or false
if(choice([true, false])) {
// if true then return an element from the array
return choice(array_to_choose_from);
} else {
// otherwise return and empty sentence (i.e. nothing)
return "";
}
}
````