Eine vereinfachte Version des englischen Zahlenrechners
Aufgabe
Schreiben Sie ein Programm, das eine Zeichenfolge als Eingabe verwendet und das Ergebnis des Ausdrucks ausgibt.
Regeln
Die Eingabezeichenfolge hat einen Wortlaut und keine Ziffer.
Es werden keine Klammern angezeigt.
Die Reihenfolge der Berechnung wird geteilt, multipliziert, subtrahiert und addiert.
Für die gleichen Operationen müssen die Berechnungen von links nach rechts durchgeführt werden.
Alle eingegebenen Zahlen sind ganze Zahlen von -999 bis 999 (beide inklusive)
Die Ausgabe erfolgt als Ganzzahl eines beliebigen Bereichs.
Division wird immer perfekt teilbar sein und Null wird niemals ein Nenner sein.
Die Einschränkung der Groß- / Kleinschreibung für die Eingabe ist optional. Sie müssen die Gültigkeit der Eingabe nicht überprüfen.
Zahlenformat
0 to 20 -> zero,one,two...nineteen,twenty
21 to 99 -> twenty one,twenty two.....ninety eight,ninety nine
100 to 999 -> one hundred, one hundred one, one hundred two...one hundred ten....two hundred fifty....nine hundred ninety eight,nine hundred ninety nine
Für negative Zahlen: Addiere minus
zum positiven Äquivalent
Operationsformat
Addition: one plus two
Subtraction: one minus two
Multiplication: one time two #Note that for one on the left of multiplication, it is one time and not times.
two times one hundred
Division: forty divided by two
Beispiele:
o/p <- input
20 four times five
35 twenty plus fifteen
70 fifty plus five times four
-90 minus one time ninety
25 twenty one minus minus four
45 ninety divided by two
700 one time seven hundred
555 one hundred eleven times two plus three hundred thirty three
99 one hundred plus minus one
45 forty five plus two hundred times zero
4 four
-3 three minus three minus three
Das ist Code-Golf, also gewinnt der kürzeste Code
one times two
. Verwendettime
normal?Antworten:
JavaScript (ES6),
257252249235 Byte3 Bytes gespart dank @Shaggy
Probieren Sie es online!
Wie?
Zahlen
Betreiber
Deutung
quelle
Perl 6 ,
170 139 129 128 124122 Bytes-13 bytes dank nwellnhof!
Probieren Sie es online!
unival
wieder zur Rettung! Dies schlägt (derzeit) sogar Golfsprachen wie05AB1E
!Erläuterung:
quelle
Python 2 ,
333...284277275 BytesProbieren Sie es online!
quelle
Wolfram Language
95 9482 Bytes#
repräsentiert den Eingang für die reine Funktion.Falls erforderlich,
StringReplace
ersetzt die "Zeit" mit Zeit " "plus minus" mit "Minus"(durch"me "->"mes "
,"plus m"->"m
" bezeichnet). Die von vorgeschlagenen verkürzten Ersetzungsformulare habenlirtosiast
12 Byte gespart.Interpreter["SemanticExpression"]
erledigt den ganzen Rest.quelle
"time "->"times "
zu"me"->"mes"
und"plus minus"->"minus"
zu wechseln"plus m"->"m"
?05AB1E ,
166147141139135 BytesViel zu lange. Ich werde versuchen, von hier aus Golf zu spielen.
-4 Bytes dank @Emigna .
-2 Bytes dank @JoKing .
Probieren Sie es online aus oder überprüfen Sie alle Testfälle .
Erläuterung:
Sehen Sie sich meinen Tipp 05AB1E an (Abschnitte Verwendung des Wörterbuchs , Komprimieren von Zeichenfolgen, die nicht Teil des Wörterbuchs sind , und Komprimieren großer Ganzzahlen ), um zu verstehen, wie
“¡×€µ‚•„í†ìˆÈŒšï¿Ÿ¯¥Š—¿áÓÁÏ“
,'…§
,'°¡
,.•4º»Ÿć'Rþн•
,Ž9o
, und“‰´Øè„Æ€ººß“
Arbeit.Schritt für Schritt Beispiel:
two hundred twenty two divided by two times minus fifty seven plus three hundred eighteen minus minus ten
two hundred twenty two divided two times minus fifty seven plus three hundred eighteen minus minus ten
2 hundred twenty 2 divided 2 times minus fifty 7 plus 3 hundred 8een minus minus 10
2 hundred weny 2 divided 2 imes minus fify 7 plus 3 hundred 8een minus minus 10
2 hundred weny 2 divided 2 imes minus fify 7 plus 3 hundred 8+10 minus minus 10
2 *100 weny 2 divided 2 imes minus fify 7 plus 3 *100 8+10 minus minus 10
2 *100 2y 2 divided 2 imes minus 5y 7 plus 3 *100 8+10 minus minus 10
2 *100 2 *10 2 divided 2 imes minus 5 *10 7 plus 3 *100 8+10 minus minus 10
["2 *100 2 *10 2 "," 2 "," "," 5 *10 7 "," 3 *100 8+10 "," "," 10"]
[["2","","*100","2","*10","2",""],["","","2",""],["",""],["","5","*10","7",""],["","3","","*100","8+10",""],["",""],["","10"]]
[["2","*100","2","*10","2"],["2"],[],["5","*10","7"],["3","*100","8+10"],[],["10"]]
[["2*100","2*10","2"],["2"],"",["5*10","7"],["3*100","8+10"],"",["10"]]
eval
jeweils:[[200,20,2],[2],"",[50,7],[300,18],"",[10]]
[222,2,"",57,318,"",10]
dividedimesminusplusminusminus
[" /"," *"," -"," +"," -"," -"]
222 /2 * -57 +318 - -10
eval
den String, und implizit ausgeben:-5999.0
quelle
sfk ,
572449423 bytesDies könnte alles eine Zeile sein, aber zum Lesen habe ich Zeilenumbrüche anstelle von Leerzeichen verwendet.
Probieren Sie es online!
quelle