Oui est un langage basé sur la pile qui a quelques instructions séparées par des espaces:
yes: Push 1 to the stack
no: Push 0 to the stack
what: Push the input to the stack (input is taken at the start of program execution and is the same for the whole execution)
sure: Increment the last item in the stack
nah: Decrement the last item in the stack
really: If the last stack item is a number, replace it with its Unicode character. If it is a letter, replace it with its Unicode char code.
oh: convert the stack to strings and concatenate it, and push that to the stack.
nope: remove the first stack item
yep: remove the last stack item
Le dernier élément de la pile est toujours sorti à la fin du programme. Tous les caractères non alphanumériques et non espace sont ignorés. Tout le code est en minuscules. Exemples de programmes:
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
oh
impressions Hello, World!
.
what
imprime l'entrée ( cat
programme.)
no nah
impressions -1
.
no really
imprime le NUL
caractère ( U+0000
)
what
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
oh
imprime l'entrée et un trait de soulignement.
yes no nope
impressions 0
yes no yep
impressions 1
.
Vous devez écrire un interpréteur dans le moins d'octets possible. Voici une implémentation JS (pas bien jouée!):
function yes(code, input){
var stack = [];
var functions = {
"yes": "stack.push(1)",
"no": "stack.push(0)",
"what": "stack.push(input)",
"sure": "stack[stack.length - 1] ++",
"nah": "stack[stack.length - 1] --",
"really": "stack[stack.length - 1] = (typeof lastItem === 'number' ? String.fromCharCode(lastItem) : lastItem.charCodeAt())",
"oh": "stack.push(stack.reduce((x, y)=>''+x+y))",
"nope": "stack.shift()",
"yep": "stack.pop()"
};
code.replace(/[^a-z ]/g, "").split(" ").map(x=>(lastItem = stack[stack.length - 1],eval(functions[x])));
return stack[stack.length - 1];
}
textarea{
display: block;
}
Code: <textarea id = "code"></textarea>
Input: <textarea id = "input"></textarea>
<button onclick = "output.value = yes(code.value, input.value)">Run</button>
<textarea id = "output"></textarea>
Voir aussi ma réponse JS ci-dessous.
Vous pouvez supposer que tous les entiers impliqués seront inférieurs ou égaux à 126, qui really
ne seront jamais exécutés avec une chaîne multi-caractères au-dessus de la pile, et que la pile ne dépassera jamais 100 éléments.
Cas de bord
yes yes oh
impressions11
.- L'entrée peut être une chaîne ou un nombre.
- Le code peut contenir n'importe quel caractère. Ceux qui ne correspondent pas
[a-z ]
doivent être ignorés.
la source
really
faire s'il y a une chaîne à plusieurs caractères au-dessus de la pile?yes yes oh
imprimer11
?[a-zA-Z ]
?Réponses:
05AB1E ,
77676361 octetsSuppose que le programme se trouve en haut de la pile.
Essayez-le en ligne!
la source
yes no sey yep
JavaScript (ES6),
218215204203 octetsPrend la chaîne de programme
s
et l'entréei
dans la syntaxe de curry(s)(i)
.Comment?
Nous utilisons la fonction de hachage parfaite
parseInt(S, 35) % 156 % 9
pour convertir l'instruction S en un index en 0… 8 et utilisons cet index pour sélectionner le code JS à exécuter:le fonction P fait sortir le dernier élément de la pile s et le charge dans k .
Nous empêchons le résultat de certaines instructions d'être repoussé sur la pile en testant si la méthode .map () est définie, c'est-à-dire si le résultat est un tableau. Le code pour oh renvoie un tableau de par sa conception et nous forçons également nope et yep à renvoyer des tableaux. D'où la syntaxe:
Cas de test
Afficher l'extrait de code
la source
Röda , 256 octets
Essayez-le en ligne!
Explication
#variable
renvoie la longueur devariable
(s'il s'agit d'une chaîne ou d'un tableau).la source
Pyth , 69 octets
Essayez-le en ligne!
la source
013456789yes 012345678no oh
imprime 0, la sortie attendue est 10.yes yes oh
(spécifié dans la question), la sortie attendue est11
.JS (ES6),
361340 octetsPrend le code et la saisie par curry.
la source
JavaScript (ES6),
220216 octetsUne fonction qui accepte des entrées avec une syntaxe de curry, comme
f(code)(input)
.la source
Python 2 , 258 octets
Essayez-le en ligne!
-3 octets grâce à @Wondercricket
la source
-1
tant que variablePerl 6 ,
233225 octetsEssayez-le
Hello World
cat
-1
nul
cat_
0
1
Fonctionne de la même façon, sauf qu'il ne saisit que les deux derniers caractères de chaque commande et utilise
$_
au lieu de$/
pourreally
.Essayez-le (Hello World)
Étendu:
la source
PHP,
315305 octetsdeuxième projet, pas encore testé
Courez avec
php -nr '<php-code>' <input> <yes-code>
.panne
la source