Probleme mit faulen Wörtern

15

Zusammenfassung

Einem Lehrer wurde gesagt, er solle den Schülern Wortprobleme vorbereiten. Sie bekommt eine Liste von Gleichungen und muss sie als das entsprechende Wortproblem schreiben. Sie ist jedoch sehr faul, weshalb sie nicht viel Kreativität in sie steckt. Stattdessen schreibt sie es einfach wörtlich. Wenn sie zum Beispiel liest 1+1, schreibt sie one plus one, 47 * 2verwandelt sich in forty seven times twound 56.2 / 7.4wirdfifty six point two divided by seven point four .

Schreiben Sie einen Code, um diesem faulen Lehrer zu helfen.

Einzelheiten

  • Zahlen können einen Dezimalpunkt und ein negatives Vorzeichen enthalten.
  • Zahlen sollten in der kurzen Skala geschrieben werden. (dh 1,000,000,000istone billion )
  • Die Zahlen können bis zu 999.999.999.999.999.999 (nine hundred ninety nine quadrillion...nine hundred ninety nine ) gehen.
  • Gruppen von Nullen müssen weggelassen werden. zB 1,000,000geht one millionnichtone million zero thousand zero hundred .
  • Es können beliebig viele Stellen nach dem Komma stehen.
  • Nachkommastellen müssen ziffernweise aufgelistet werden. zB 12.34geht twelve point three fournichttwelve point thirty four .
  • Zwei Nummern werden immer durch einen Operator getrennt.
  • Die gültigen Operatoren sind plus ( +), minus ( -), times ( *) und dividiert durch ( /).
  • Es gibt keine Klammern.
  • Zahlen wie 1234können optional ein andin ihre Ausgabe aufnehmen, wie in one thousand two hundred *and* thirty four.
  • Kommas und Leerzeichen in der Eingabe werden möglicherweise ignoriert.

Beispiele

Eingabe: 24 + 65
Ausgabe:twenty four plus sixty five

Eingabe: 3.33333 - 0
Ausgabe:three point three three three three three minus zero

Eingabe: 3.6 * 18.18 / 999.0
Ausgabe:three point six times eighteen point one eight divided by nine hundred ninety nine point zero

Eingabe: 1-1
Ausgabe:one minus one

Eingabe: 1+-1
Ausgabe:one plus negative one

Eingabe: 1,000,000,000 + 0.2
Ausgabe:one billion plus zero point two

Eingabe: 123,000,456,789,012,345.6789
Ausgabe:one hundred twenty three quadrillion four hundred fifty six billion seven hundred eighty nine million twelve thousand three hundred forty five point six seven eight nine

Eingabe: -4.3 * 7
Ausgabe:negative four point three times seven

Eingabe: -1-1--1
Ausgabe:negative one minus one minus negative one

Daffy
quelle
1
Könnten Sie 123,456,789,012,345.6789den Beispielen etwas Ähnliches hinzufügen ? Es sollte viele Testfälle abdecken.
Maxb
2
Können wir minusstatt verwenden negative?
Jo King
3
Für Mathematica: Es gibt wieder eine eingebaute , aber /eine overnegative Zahl minus, daher ist eine gewisse Manipulation erforderlich.
user202729
2
@ user202729 Erstaunlich ... warum wundert es mich nicht, dass Mathematica ein eingebautes Programm dafür hat? :)
Daffy

Antworten:

15

JavaScript (ES6), 552 532 Bytes

Dieses dreckige Monster kommt direkt aus der Hölle des Code-Golfens.

Erwartet eine Eingabezeichenfolge ohne Leerzeichen.

S=>S[R='replace'](/[\d.,]+|./g,s=>1/s[0]?a(+s[S=0]&&14)+s[R](/(\D?)(\d+)/g,(_,s,n)=>s>','?' point'+n[R](/./g,a):j--*n?(u=a(n%10||14),n>99?a(n[0])+' hundred':'')+((n%=100)<13?a(n||14):n<20?(a(n)||u)+'teen':(a(n/10+18)||a(n/10))+'ty'+u)+a(j+27)+(j>1?'illion':''):'',j=s.split`,`.length):a(S='+-*/'.indexOf(s=='-'&&S||s)+34),a=n=>(s='zero0one0two0three0four0five0six0seven0eight0nine0ten0eleven0twelve0thir00fif000eigh00twen0thir0for0fif000eigh00thousand0m0b0tr0quadr0negative0plus0minus0times0divided by'.split`0`[n|0])&&' '+s).trim()

Probieren Sie es online!

Arnauld
quelle
3
Sie können 18 Bytes kürzen, indem Sie Ihr Riesen-String-Literal durch ersetzen btoa`ÍêèÒ‰ÞÒÜ(ÒØkyí¢êô~+ÞÒȱÒǯz}ŠmÒx§{K^ŸG¥z÷§ÒÜ–÷´¶«ÓGâM4z(!ÓKpz}-†*ô~Šô~'ôÓG¢‚4¶.±©ÝÒmÒÚôªæ�¯IÞ�«b½í)–ë4š)î³Kb™ë4v+âuçu×Vò`.replace(111,' ').
Kamoroso94
Ich liebe Antworten, die solche String-Literale kreativ komprimieren.
Daffy
6

Perl 6 , 434 401 387 359 Bytes

{~S:g/\d+/{n($//100+64184)x($/>100),$/%100>19&&(n($//10%10+64175),n($!=$/%10)x?$!)||n($/%100+7679),[$,"thousand",|(<m b tr quadr>X~"illion")][+$/.postmatch.words[0].comb(',')]if +$/} /.trans("+,-/*"=><<plus''minus"divided by"times>>).words}o{S:g/\.(\d)+/ point {$0>>.&n}/}o{S:g/[\s|^]0/ zero/}o{S:g/\-(\d)/negative $0/}
my&n=(*+1632+|0).uniname.lc.words[2..*]

Probieren Sie es online!

Hier besteht definitiv Verbesserungsbedarf. Ich sage das, aber ich bemerke immer wieder Randfälle, die ich nicht bearbeitet habe:( . Es wird davon ausgegangen, dass bei der Eingabe die Operatoren durch Leerzeichen getrennt sind und das Negativ einer Zahl nicht getrennt ist.

Erläuterung:

my&n=(*+1632+|0).uniname.lc.words[2..*]  # Define a helper function
           # This gets the unicode name, e.g ARABIC-INDIC DIGIT ZERO
           #                              or AEGEAN NUMBER ONE HUNDRED
           # And returns the 3rd word onwards in lowercase e.g. 'zero' or 'one hundred'
{S:g/\-(\d)/negative $0/}  # Turn dashes before numbers to negative
{S:g/[\s|^]0/ zero/}       # Handle zeros
{S:g/\.(\d)+/ point {$0>>.&n}/}  # Replace decimals
{~S:g/\d+/        # Replace series of numbers with
    n($//100+64184)x($/>100)  # The hundreds if the num is bigger than 100
    $/%100>19&&               # If the number is bigger than 19
      (
      n($//10%10+64175),         # The tens number
      n($!=$/%10)x?$!            # And the singles number (if it's not zero)
      )
    ||                        # Else
      n($/%100+7679)             # The name of the number below 20
    ,                      # Then
    [$,"thousand",|(<m b tr quadr>X~"illion")][   # Index into the list of postfixes
      +                         .comb(',')   # The number of commas
       $/.postmatch.words[0]  # in the rest of the number
  if +$/           # All if the number is not 0
.trans("+,-/*"=><<plus''minus"divided by"times>>)  # Translate operators
                                                   # And remove commas
.words}     # And remove all the excess spaces between words
Scherzen
quelle
5

Ruby + Swift 4, 283 279 270 Bytes

$_=gsub(/(?<=\d)-/,"minus ").gsub(/[*-\/]/,?.=>"point ",?-=>"negative ",?+=>"plus ",?*=>"times ",?/=>"divided by ").gsub(/(?<=^|[^t] )\d+|\d/){`echo "import Foundation
var f=NumberFormatter()
f.numberStyle = .spellOut
print(f.string(from:#$&)!)">.a
swift .a`.tr'-
',' '}

Probieren Sie es online!

Ich muss verrückt sein, eine solche Frankenstein-Lösung vorzuschlagen, aber einerseits ist es sehr verlockend, Swifts integrierte Funktionalität für diese Aufgabe zu verwenden, und andererseits scheint es eine Golfkatastrophe zu sein, Strings mit Regexes in Swift zu verarbeiten.

Aus diesem Grund habe ich mich für die grundlegende Verarbeitung von Zeichenfolgen in Ruby entschieden, aber um Zahlen auszudrücken, speichere ich sie in einer Swift-Quelldatei, führe Swift in einem Shell-Befehl aus und sammle die Ausgabe.

Ich stelle fest, dass Swifts "spellOut" -Zahlenformatierer fast genau das tut, was wir brauchen, außer, dass unnötige Bindestriche für zweistellige Zahlen wie in eingefügt werden twenty-two. Tatsächlich ist sogar die Gleitkommaausgabe im Format von integer part point digit digit...gut, aber hier kommt die Einschränkung: Es gibt keine unendliche Genauigkeit, und bei ausreichend großen Zahlen oder vielen Dezimalstellen gehen die Ergebnisse schief. Deshalb musste ich die ganzzahligen und gebrochenen Teile trennen und den Bruch ziffernweise vorschieben.

Kirill L.
quelle
1
Das ist absolut teuflisch und ich liebe es.
Daffy
4

sfk , 853 bytes

xed -i
"_*_ [part1]_"
+xed
_+_plus_
_\*_times_
"_/_divided by_"
"_- _minus _"
"_-_negative _"
+xed
"_,[keep][19 chars of 0-9,]_quadr@ _"
"_,[keep][15 chars of 0-9,]_tr@ _"
"_,[keep][11 chars of 0-9,]_b@ _"
"_,[keep][digits],[digits],_b@ _"
"_,[keep][digits],_m@ _"
"_,_ thousand _"
+xed
"_ 000[chars]@__"
"_ 000__"
"_ 00[keep][digit]_ _"
"_ 0[keep][2 digits]_ @_"
"_ [digit][keep][2 digits]_[part2]hundred @_"
"_ [ortext] 0[digit]0_ @[part2]_"
"_ [keep][2 digits]_ @_"
"_@_illion _"
+xed
_@11_eleven_
_@12_twelve_
_@1[digit]_@[part2]teen_
_@1_ten_
_@4_forty_
_@[digit]_@[part2]ty_
+xed
_@2_twen_
_@3_thir_
_@4_four_
_@5_fif_
_@6_six_
_@7_seven_
_@8_eigh_
_@9_nine_
+xed
"_0_ zero _"
"_1_ one _"
"_2_ two _"
"_3_ three _"
"_4_ four _"
"_5_ five _"
"_6_ six _"
"_7_ seven _"
"_8_ eight _"
"_9_ nine _"
"_._ point _"
+xed
"_[white]_ _"
+xed
"_[lstart] __"

Probieren Sie es online!

Erfordert, dass Operatoren und Zahlen durch mindestens ein Leerzeichen getrennt sind.

Οurous
quelle
4

Sauber , 766 ... 687 Bytes

import StdEnv,Text
m=""
z="zero"
@ =digitToInt
r=reverse
l k=(!!)k o@
^s=l[s:split" ""one two three four five six seven eight nine"]
g s=l[m,m,"twen","thir",s,"fif","six","seven","eigh","nine"]
~['0':t]= ~t
~[a,b,c]= ^""a+" hundred "+ ~[b,c]
~[b,c]|b>'1'=g"for"b+"ty "+ ^""c|c>'2'=g"four"c+"teen"=["ten","eleven","twelve"]!!(@c)
~[c]= ^""c
~_=m
$[]=m
$[x:y]#(h,t)=span(\e=e>'/'||e==',')if(x<'1')y[x:y]
=trim(join" "((case x of'0'=[z];'-'=["negative",$h];'.'=["point":map(^z)h];_=(r[u+v\\u<-r(map~(split[',']h))&v<-[m," thousand":[" "+k+"illion"\\k<-["m","b","tr","quadr"]]]|u>m]))++[?t]))
?['-':t]="minus "+ $t
?['+':t]="plus "+ $t
?['/':t]="divided by "+ $t
?['*':t]="times "+ $t
?t= $t

Probieren Sie es online!

Erwartet eine Zeichenfolge ohne Leerzeichen.

Οurous
quelle
1

05AB1E , 315 295 282 276 Bytes

"+-*/"DˆS¡εDõQi'¢…ë'.¡VYнD_i\'¡×ðë',¡DgUε0›i.•6b©•ð“†ìˆÈŒšï¿Ÿ¯¥Š“©'tKJ#'…§«…€µ‚•„í#®#«…—¿áÓÁÏ#«ìD9£©.•4º»Ÿć'Rþн•ŽH$S£“Œšï¿Ÿ¯¥Š“'tK#«„ty«sõšâðý«õšD®'°¡ðì«sâðý«yèð.•cG3₅¦„¥F•8ô'¾ß«…¡›‡È±°#«õªRXN-<èJëõ}}ðý}Yg<i®'¡×šYθSè'…®šðý}}J}s¯`Ã哉´Øè„ƺߓ#¤… by«¸s¨ì¯`ykè}.ιðý„  ð:„¢…Øè'¢…:

Übernimmt Eingaben ohne Leerzeichen.

Probieren Sie es online aus oder überprüfen Sie alle Testfälle .

Erläuterung:

"+-*/"                    # Push string "+-*/"
Dˆ                        # Duplicate it, pop the copy, and push it to the global array
S¡                        # Split the input by any "+", "-", "*", or "/"
ε                         # Map each number to:
 DõQi                     #  If the item is empty (happens for negative numbers)
     '¢…                 '#   Push string "negative"
 ë                        #  Else:
  '.¡                    '#   Split by "."
  VY                      #   Store it in variable `Y`
  н                       #   Take the first number (the integer part)
  D                       #   Duplicate this integer part
  _i                      #   If the integer part is exactly 0:
    \                     #    Discard the duplicated integer part
    '¡×                  '#    Push string "zero"
    ð                     #    Push a space " "
  ë                       #   Else:
   ',¡                   '#    Split by ","
   DgU                    #    Pop and store the amount of items in variable `X`
      ε                   #    Map each part to:
       0i                #     If it's larger than 0:
          .•6b©•          #      Push string "thir"
          ð               #      Push a space " "
          “†ìˆÈŒšï¿Ÿ¯¥Š“  #      Push string "four five six seven eight nine"
          ©               #      Store it in the register (without popping)
           'tK           '#      Remove all "t" (so "eight" becomes "eigh")
          J               #      Join it together with the "thir" and space
          #               #      Split by spaces
          '…§            '#      Push string "teen"
             «            #      And append it to every string in the list
                          #      (We now have ["thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"])
          …€µ‚•„í         #      Push string "one two three"
                 #        #      Split by spaces
          ®               #      Push the string from the register ("four" through "nine")
           #«             #      Split by spaces, and merge both lists together
          …—¿áÓÁÏ         #      Push string "ten eleven twelve"
                 #«       #      Split by spaces, and also merge both lists together
          ì               #      Prepend "one" through "twelve" before "thirteen" through "nineteen"
          D9£             #      Duplicate it, and take the first nine ("one" through "nine")
             ©            #      Store it in the register (without popping)
          .•4º»Ÿć'Rþн•   '#      Push string "twenthirforfif"
          ŽH$             #      Push integer 4433
             S            #      Split to digits: [4,4,3,3]
              £           #      And split the to parts of that size: ["twen","thir","for","fif"]
          “Œšï¿Ÿ¯¥Š“      #      Push string "six seven eight nine"
                    'tK  '#      Remove all "t" (so "eight" becomes "eigh")
                       #« #      Split by spaces, and merge both lists together
          ty             #      Push string "ty"
             «            #      And append it to every string in the list
                          #      (We now have ["twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"])
          s               #      Swap so the list "one" through "nine" is at the top again
           õš             #      Prepend an empty string to that list
             â            #      Create every possible pair of "one" through "nine" with "twenty" through "ninety"
              ðý          #      Join each pair with a space delimiter
          «               #      Merge the "twenty" through "ninety nine" list with "one" through "nineteen"
           õš             #      Prepend an empty string to that list
          D               #      Duplicate the entire list
          ®               #      Push the string from the register ("one" through "nine")
          '°¡            '#      Push string "hundred"
             ðì           #      Prepend it with a space " "
               «          #      Append it to every string in the list
                          #      (We now have ["one hundred","two hundred",...,"nine hundred"])
          s               #      Swap the two lists
           â              #      Create every possible pair of "one hundred" through "nine hundred" with "" through "ninety nine"
            ðý            #      Join each pair with a space delimiter
              «           #      Merge the "one" through "ninety nine" with "one hundred " through "nine hundred ninety nine"
                          #      (We now have ["","one",...,"nine hundred ninety nine"])
          y               #      Get the current number of the map
           è              #      And index it into this list
          ð               #      Push a space " "
          .•cG3₅¦„¥F     #      Push string "quadrilltrill"
                     8ô   #      Split into pieces of size 8: ["quadrill","trill"]
          '¾ß            '#      Push string "ion"
             «            #      Append it to every string in the list
          …¡›‡È±°         #      Push string "billion million thousand"
                 #        #      Split by spaces
                  «       #      And merge both lists together
          õª              #      Append an empty string
            R             #      Reverse the list
                          #      (We now have ["","thousand","million","billion","trillion","quadrillion"])
          X               #      Push variable `X`
           N-             #      Subtract the map-index from it
             <            #      Subtract an additional 1
              è           #      And index it into the list
          J               #      Join the stack together
       ë                  #     Else:
        õ                 #      Push an empty string ""
       }                  #     Close the if-else
      }                   #    Close the map
      ðý                  #    Join the mapped values with space delimiter
  }                       #   Close the if-else
  Y                       #   Push variable `Y`
  g<i                     #   If its length is exactly 2:
     ®                    #    Push the string from the register ("one" through "nine")
     '¡×                 '#    Push "zero"
        š                 #    Prepend it to the list
      Yθ                  #    Push variable `Y` again, and leave the second number (the decimal part)
        S                 #    Split it to digits
         è                #    And index each into the list
      '…®                '#    Push string "point"
         š                #    Prepend it in front of that list
      ðý                  #    Join the list with space delimiter
  }                       #   Close the if
 }                        #  Close the if-else
 J                        #  Join the stack together
}                         # Close the map
s                         # Swap to take the (implicit) input again
¯`                        # Push the global array, and dump it's content (string "+-*/")
  Ã                       # Only keep all "+", "-", "*", and "/", and remove everything else
ε                         # Map each to:
 “‰´Øè„ƺߓ               #  Push string "plus minus times divided"
           #              #  Split by spaces
 ¤                        #  Take the last item (without popping the list)
   by«                   #  Append it with string " by"
       ¸                  #  Wrap it to a list: ["divided by"]
 s                        #  Swap to take the list again
  ¨                       #  Remove the last item
   ì                      #  Prepend it in front of the list: ["plus","minus","times","divided by"]
 ¯`                       # Push the global array, and dump it's content (string "+-*/")
   yk                     #  Push the index in this string for the current map-value `y`
     è                    #  And use that index to index into the string-list
}                         # Close the map
                        # Interweave the list of numbers and list of operators
  ðý                      # Join everything with space delimiter
  ð:                     # Replace every two spaces for a single space
„¢…Øè'¢…:                '# And replace every "negative minus" with "negative"
                          # (and output the result implicitly)

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, warum:

  • ( Wie benutzt man das Wörterbuch? ) - '¢…ist "negative"; '¡×ist "zero"; “†ìˆÈŒšï¿Ÿ¯¥Š“ist "four five six seven eight nine"; '…§ist "teen"; …€µ‚•„íist "one two three"; …—¿áÓÁÏist "ten eleven twelve"; '°¡ist "hundred"; '¾ßist "ion"; …¡›‡È±°ist "billion million thousand";'…®ist "point"; und “‰´Øè„ƺߓist"plus minus times divided" .
  • ( Wie werden Zeichenfolgen komprimiert, die nicht im Wörterbuch enthalten sind? ) - .•6b©•is "thir";.•4º»Ÿć'Rþн•ist "twenthirforfif"; und .•cG3₅¦„¥F•ist "quadrilltrill".
  • ( Wie große ganze Zahlen komprimieren? ) - ŽH$ist 4433.
Kevin Cruijssen
quelle
1

Python 2 , 790 774 Bytes

lambda T:B("([+/*-])",lambda m:dict(zip("+/*-",S("z"," plus z divided by z times z minus ")))[m.group(0)],B("([+/*-]|^)-",r"\1negative ",B("[^+/*-]+","{}",T))).format(*[J([g[int(S("\.",j)[0])]+S("z",B("y","illion","z thousandz myz byz tryz quadry"))[len(S(",",m))+~i]+(" point "+J(s[int(c)]for c in S("\.",j)[-1]))*("."in j)for i,j in E(S(",",m))if 0<float(j)+(m<"1")])for m in S("[+/*-]+",T)[T[0]=='-':]])
from re import*
E,S,B,P=enumerate,split,sub," ";J=P.join
s,e=S(P,"zero one two three four five six seven eight nine"),[B("urty","rty",j)for i,j in E(c+d for d in S(P,"teen ty")for c in S(P,"twen thir four fif six seven eigh nine"))]
g=s+S(P,"ten eleven twelve")+e[1:8]+[a+(P+b)*(i>0)for a in e[8:]for i,b in E(s)]
g=[(j+" hundred ")*(i>0)+k for i,j in E(s)for k in g]

Probieren Sie es online!

So viele schlechte Praktiken. Das tat fast weh zu schreiben ....

Erwartet eine Nicht-Unicode-Zeichenfolge ohne Leerzeichen als Eingabe.

Erläuterung:

# import all functions from re (python regex library)
from re import*

# rename some repeatedly-used functions/variables for reduced bytecount
E,S,B,P=enumerate,split,sub," ";J=P.join

# list the names of 0-9
s=S(P,"zero one two three four five six seven eight nine")
# generate "twenteen" through nineteen and twenty though ninety, changing "fourty" to forty
# using enumerate (E) even though i is not required b/c it's shorter than range(len(x))
# using re.split (S) instead of string.split since it's shorter
e=[B("urty","rty",j)for i,j in E(c+d for d in S(P,"teen ty")for c in S(P,"twen thir four fif six seven eigh nine"))]
# generate 0-999
# 0-9
g=s+
   # 10, 11, 12
   +S(P,"ten eleven twelve")+
                            # remove "twenteen", 13-19
                            +e[1:8]+
                                   # tens' place + ones' place, if ones' place is not zero
                                   +[a+(P+b)*(i>0)                               ]
                                                   # for each tens' place in 20-90
                                                   for a in e[8:]
                                                                  # for each index, value in ones' places 0-9
                                                                  for i,b in E(s)


# hundreds' place if at least 100, plus tens' and ones' place (already calculated and stored in g from before)
g=[(j+" hundred ")*(i>0)+k                          ]
                           # (s) stores names for 0-9, need index to avoid "zero hundred"
                           for i,j in E(s)
                                          # for each hundred, iterate over all values (0-99) already in g
                                          for k in g

# actual function to call. uses previously declared global variable g.
def f(T):
    # gets the numbers in the supplied string (T) by splitting (T) on any operator character
    # remove first item if blank (only happens when staring with a - for negative numbers)
    n=S("[+/*-]+",T)[T[0]=='-':]

    # triply-nested set of re.subs to convert (T) to a sting of where the operators are replaced by their names and numbers are replaced by "{}"
    # EX: "-1-1--1" -> "-{}-{}--{}" -> "negative {}-{}-negative {}" -> "negative {} minus {} minus negative {}"
    # this sub happens last
    # re.sub (B) any operator, with the operators in a group "()" so that they return in match.group
    T=B("([+/*-])",                                                                                                                                        )
                  # an anonymous function to accept match objects (m) from re.sub's search.
                  ,lambda m:
                            # create a dictionary from the combination of operators and their names
                            # like {"+":" plus ",...}
                            # operator names are surrounded by spaces since number names are NOT
                            dict(zip("+/*-",S("z"," plus z divided by z times z minus ")))
                                                                                          # from the constructed dictionary, select the operator matched by re.sub's search and return it for replacement
                                                                                          [m.group(0)],
                                                                                                      # this substitution is second
                                                                                                      # re.sub (B) any operator followed by a minus (-), OR a minus at the beginning of the string
                                                                                                      # operators/start are grouped, trailing minus is not
                                                                                                      ,B("([+/*-]|^)-",                                    )
                                                                                                                      # replace match with the grouped items plus the word "negative"
                                                                                                                      # EX: "-1-1--1" -> "-{}-{}--{}" -> "negative {}-{}-negative {}"
                                                                                                                      ,r"\1negative ",
                                                                                                                                     # this substitution is done first
                                                                                                                                     # replace any sequence of NON-operators with "{}"
                                                                                                                                     # this removes numbers so the names can be inserted later
                                                                                                                                     # EX: "-1-1--1" -> "-{}-{}--{}"
                                                                                                                                     ,B("[^+/*-]+","{}",T))

    # technically the previous construction of (T) and (n) can be placed here to save 5 bytes but my poor eyes can't handle that.
    # insert constructed names back into original string.
    # EX: "-1-1--1" -> "negative {} minus {} minus negative {}" -> "negative one minus one minus negative one"
    print T.format(                                                                                                                                                                                                                     )
                   # string.format needs items in array unpacked, or it will attempt to insert the string representation of the array itself
                   *[                                                                                                                                                                                                                  ]
                     # for each number pulled from (T), generate names and join generated items back together with spaces
                     # EX: "1,456" -> ["1", "456"] -> ["one thousand", "four hundred fifty six"] -> "one thousand four hundred fifty six"
                     J(                                                                                                                                                                                                     )for m in n
                       # split j on periods (.) and take the first item
                       # convert that item into an integer and find the item at that index in g (0-999)
                       [g[int(S("\.",j)[0])]+                                                                                                                                                                              ]
                                            # insert prefix for millions +, split string on "z" (spaces must be preserved for proper separation)
                                            +S("z",B("y","illion","z thousandz myz byz tryz quadry"))
                                                                                                     # left is largest, so take the item at index (total # of groups - current place - 1)
                                                                                                     [len(S(",",m))+~i]+
                                                                                                                       # if group had a period, split string on period and take last item
                                                                                                                       # replace every character in group with number 0-9 name
                                                                                                                       # join them with spaces and add back to rest of group
                                                                                                                       +(" point "+J(s[int(c)]for c in S("\.",j)[-1]))*("."in j)
                                                                                                                                                                                # split number into groups by comma
                                                                                                                                                                                # EX: "123,456" -> ["123","456"]
                                                                                                                                                                                # only return item if j != 0 (avoids returning empty string which will result in too many joined spaces)
                                                                                                                                                                                # OR if m == 0 (avoids not returning anything when should return "zero")
                                                                                                                                                                                for i,j in E(S(",",m))if 0

Ich habe beim Schreiben der Erklärung etwa 150 Byte eingespart. Lassen Sie sich niemals sagen, dass das Kommentieren / Überprüfen Ihres Codes nicht hilfreich ist!

Triggernometrie
quelle