শব্দযুক্ত ক্যালকুলেটর


14

ইংরেজি সংখ্যা ক্যালকুলেটরের একটি সরল সংস্করণ

কার্য

একটি প্রোগ্রাম লিখুন যা ইনপুট হিসাবে স্ট্রিং নেয় এবং অভিব্যক্তির ফলাফলকে আউটপুট করে।

বিধি

ইনপুট স্ট্রিংটি শব্দযুক্ত হবে এবং সংখ্যা নয়।

কোনও বন্ধনী থাকবে না।

গণনার ক্রম বিভাজন হবে, গুণ হবে, বিয়োগ করবে তারপরে যোগ হবে।

একই ক্রিয়াকলাপের জন্য, গণনাগুলি বাম থেকে ডানে করতে হবে।

সমস্ত ইনপুট নম্বরগুলি -৯৯৯ থেকে ৯৯৯ পর্যন্ত পূর্ণসংখ্যা হবে (উভয়ই অন্তর্ভুক্ত)

আউটপুট যে কোনও ব্যাপ্তির পূর্ণসংখ্যা হবে।

বিভাগ সর্বদা নিখুঁতভাবে বিভাজ্য হবে এবং শূন্য কখনই ডিনমিনেটর হতে পারে না।

ইনপুট জন্য ক্ষেত্রে সীমাবদ্ধতা isচ্ছিক। আপনাকে ইনপুটটির বৈধতা পরীক্ষা করতে হবে না।

সংখ্যা বিন্যাস

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

নেতিবাচক সংখ্যার জন্য: minusএর ইতিবাচক সমতুল্যে যুক্ত করুন

অপারেশন ফর্ম্যাট

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

উদাহরণ:

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

এটি কোড-গল্ফ তাই সংক্ষিপ্ততম কোডের জয়


1
প্রতিলিপি? - আমি মনে করি এটিকে যথেষ্ট হিসাবে বিবেচনা করা যায়।
কিরিল এল।

2
এটা আসলে খুব কাছাকাছি। তবে আমি মনে করি এটি আরও ভালভাবে নির্দিষ্ট এবং এর আরও যুক্তিসঙ্গত সীমাবদ্ধতা রয়েছে।
আর্নল্ড

1
@ আরনাউল্ড আমি তখন এটি উন্মুক্ত রাখব তবে অন্যরা যদি অন্যরকমভাবে চিন্তা করেন তবে কেবল এটি সদৃশ হিসাবে চিহ্নিত করুন।
বেদন্ত কান্দোই

15
আমি বলি one times twotimeসাধারণ ব্যবহার করছেন ?
জো কিং

2
আমার মনে হয় আপনি 'এক সময় বোঝানো গুলি সাতশো'?
আউটফ্লাক করুন

উত্তর:


18

জাভাস্ক্রিপ্ট (ES6), 257 252 249 235 বাইট

3 শে বাইট সংরক্ষিত হয়েছে @ শেগগিকে ধন্যবাদ

s=>eval(s.split` `.map(w=>(i='zeonwohrr44fx3n5t54nn3leel8tou7fn7n98etetwthfofisiseeinihuplmitidiby'.match(/../g).findIndex(x=>~(w+w.length+w).search(x)))>28?n+' '+'+-*/ '[n='',i-29]:(n=+n+(i<28?i<20?i:i*10-180:n*99),''),n='').join``+n)

এটি অনলাইন চেষ্টা করুন!

কিভাবে?

ওয়াটএলআমিওয়াট+ +এল+ +ওয়াট

নাম্বার

 index | word              | word + length + word         | key substring
-------+-------------------+------------------------------+---------------
    0  | "zero"            | "zero4zero"                  | "ze"
    1  | "one"             | "one3one"                    | "on"
    2  | "two"             | "two3two"                    | "wo"
    3  | "three"           | "three5three"                | "hr"
    4  | "four"            | "four4four"                  | "r4"
    5  | "five"            | "five4five"                  | "4f"
    6  | "six"             | "six3six"                    | "x3"
    7  | "seven"           | "seven5seven"                | "n5"
    8  | "eight"           | "eight5eight"                | "t5"
    9  | "nine"            | "nine4nine"                  | "4n"
   10  | "ten"             | "ten3ten"                    | "n3"
   11  | "eleven"          | "eleven6eleven"              | "le"
   12  | "twelve"          | "twelve6twelve"              | "el"
   13  | "thirteen"        | "thirteen8thirteen"          | "8t"
   14  | "fourteen"        | "fourteen8fourteen"          | "ou"
   15  | "fifteen"         | "fifteen7fifteen"            | "7f"
   16  | "sixteen"         | "sixteen7sixteen"            | "n7"
   17  | "seventeen"       | "seventeen9seventeen"        | "n9"
   18  | "eighteen"        | "eighteen8eighteen"          | "8e"
   19  | "nineteen"        | "nineteen8nineteen"          | "te"
   20  | "twenty"          | "twenty6twenty"              | "tw"
   21  | "thirty"          | "thirty6thirty"              | "th"
   22  | "forty"           | "forty5forty"                | "fo"
   23  | "fifty"           | "fifty5fifty"                | "fi"
   24  | "sixty"           | "sixty5sixty"                | "si"
   25  | "seventy"         | "seventy7seventy"            | "se"
   26  | "eighty"          | "eighty6eighty"              | "ei"
   27  | "ninety"          | "ninety6ninety"              | "ni"
   28  | "hundred"         | "hundred7hundred"            | "hu"

অপারেটর

 index | word              | word + length + word         | key substring
-------+-------------------+------------------------------+---------------
   29  | "plus"            | "plus4plus"                  | "pl"
   30  | "minus"           | "minus5minus"                | "mi"
   31  | "times" or "time" | "times5times" or "time4time" | "ti"
   32  | "divided"         | "divided7divided"            | "di"
   33  | "by"              | "by2by"                      | "by"

ব্যাখ্যা

এনআমি

i > 28 ?                  // if the word is an operator:
  n +                     //   append n (which is either an empty string or a number)
  ' ' +                   //   append a space
  '+-*/ '[n = '', i - 29] //   reset n to an empty string and append the operator
                          //   the useless keyword 'by' is translated into a harmless space
: (                       // else:
    n =                   //   update n:
      +n + (              //     force the coercion of the current value of n to a number
        i < 28 ?          //     if the word is not 'hundred':
          i < 20 ?        //       if the value of the word is less than 'twenty':
            i             //         add i
          :               //       else:
            i * 10 - 180  //         add i * 10 - 180 (e.g. 'fifty' -> 23 * 10 - 180 = 50)
        :                 //     else:
          n * 99          //       multiply n by 100 by adding 99 * n to itself
      ),                  //
    ''                    //   remove this word from the original string
  )                       //

11

পার্ল 6 , 170 139 129 128 124 122 বাইট

-13 বাইট ধন্যবাদ nwellnhof!

{S:g/(<:N>+)+%\s/({'+'X$0})/.EVAL}o{S:g/" ҈"/00/}o{TR"⁢ʼn؊⟠"*/൰ "}o*.words>>.&{chr first *.uniname.comb(.uc),1..*}

এটি অনলাইন চেষ্টা করুন!

univalআবার উদ্ধার! এটি (বর্তমানে) এমনকি গল্ফিংয়ের মতো ভাষাও মারধর করছে 05AB1E!

ব্যাখ্যা:

*.words     # Split by word boundaries (in this case spaces)
       >>.{                            }  # Map each word to
           chr first             ,1..*    # The first character where:
                     *.uniname      # The unicode name of that character
                                    # e.g. DIGIT FIVE
                      .comb(.uc)    # Contains the uppercase of the word
{             }o  # Pass this list to another function
                  # That converts the list to a string
 TR"⁢ʼn؊⟠"*/൰ "    #"# And parse out the garbage characters that were wrong
                  # INVISIBLE TIMES => "*"
                  # LOZENGE DIVIDED BY HORIZONTAL RULE => "/"
                  # ARABIC-INDIC PER TEN THOUSAND SIGN => "൰" (value ten)
                  # LATIN SMALL LETTER N PRECEDED BY APOSTROPHE => " "
{S:g/" ҈"/00/}o   # Replace the character for "hundred" with 00

{                                }o   # And finally combine with
 S:g/(<:N>+)+%\s/   # Substitute each number-like character separated by spaces
                /({'+'X$0})/   # With the numbers prefixed by '+'s, in brackets
               # This works because Perl 6 supports numeric unicode literals, like
               # ፳ => 20, ፴ => 30, ፺ => 90, etc.
                            .EVAL   # And finally evaluate the whole expression


5

ওল্ফ্রাম ভাষা 95 94 82 বাইট

Interpreter["SemanticExpression"][#~StringReplace~{"me "->"mes ","plus m"->"m"}]&

# খাঁটি ফাংশনের জন্য ইনপুট উপস্থাপন করে।

প্রয়োজনে StringReplace"সময়" এর সাথে "বার", "প্লাস বিয়োগ" কে "বিয়োগ" ( যথাক্রমে "me "->"mes ", "plus m"->"m" মাধ্যমে ") প্রতিস্থাপন করে। সংক্ষিপ্ত প্রতিস্থাপন ফর্মগুলি, প্রস্তাবিত lirtosiast, 12 বাইট সংরক্ষণ করেছে।

Interpreter["SemanticExpression"] বাকি সব না।


আপনি পরিবর্তন করতে পারি "time "->"times "করতে "me"->"mes"এবং "plus minus"->"minus"করতে "plus m"->"m"?
lirtosiast

হ্যাঁ. দুর্দান্ত পরামর্শ।
ডেভিডসি

3

05 এ বি 1 ই , 166 147 141 139 135 বাইট

„byK“¡×€µ‚•„í†ìˆÈŒšï¿Ÿ¯¥Š—¿áÓÁÏ“#vyN:}'tK'…§¦'+T«:'°¡„ *т«©:.•1×j›o!ĆÖ•3ôŽ9oS:'y®¨:©“‰´Øè„Æ€ººß“'tK#UX¡εð¡õK2ôJ.EO}®áX"+-**/"S:Sðì.ιJ.E

খুব দীর্ঘ পথ .. এখান থেকে এটি গল্ফ করার চেষ্টা করবে।

-4 ধন্যবাদ বাইট @Emigna
-২ বাইটস @ জোকিংকে ধন্যবাদ ।

এটি অনলাইনে চেষ্টা করুন বা সমস্ত পরীক্ষার কেস যাচাই করুন

ব্যাখ্যা:

byK                 # Remove "by" from the (implicit) input-string
“¡×€µ‚•„í†ìˆÈŒšï¿Ÿ¯¥Š—¿áÓÁÏ“
                     # Push string "zero one two three four five six seven eight nine ten eleven twelve"
 #                   # Split by spaces
  v   }              # Loop over each of these items:
   yN:               #  Replace the item with its 0-indexed index
'tK                 '# Remove all "t"
'…§¦                '# Push string "teen", and remove the first character: "een"
    '+              '# Push string "+"
      T«             # Append 10: "+10"
        :            # Replace all "een" with "+10"
'°¡                 '# Push string "hundred"
    *               # Push string " *"
      т«             # Append 100: " *100"
        ©            # Store it in the register (without popping)
         :           # Replace all "hundred" with " *100"
.•4º»Ÿć'Rþн•        '# Push string "wenhirforfif"
            3ô       # Split the string into parts of size 3: ["wen","hir","for","fif"]
              Ž9o    # Push integer 2345
                 S   # Split to digits: [2,3,4,5]
                  :  # Replace each
'y                  '# Push string "y"
  ®                  # Push the " *100" from the register
   ¨                 # Remove the last character: " *10"
    :                # Replace all "y" with " *10"
©                    # Save the current string in the register (without popping)
 “‰´Øè„Æ€ººß“        # Push string "plus minus times time divided"
             'tK    '# Remove all "t": "plus minus imes ime divided"
                #    # Split by spaces: ["plus","minus","imes","ime","divided"]
                 U   # Pop and save it in variable `X`
                  X  # And push variable `X` back again
                   ¡ # Split the string by those operator-strings
ε          }         # Map each substring to:
 ð¡                  #  Split by spaces (NOTE: cannot be `#`; if the string contains no
                     #   spaces, `#` remains string, whereas `ð¡` wraps it in a list)
   õK                #  Remove empty strings from the list
     2ô              #  Split the list into parts of two
       J             #  Join each pair together
        .E           #  Evaluate each as a Python `eval` expression
          O          #  Sum them
®                    # Put the string from the register to the stack again
 á                   # Remove everything except for letters
  X                  # Push variable `X`: ["plus","minus","imes","ime","divided"]
   "+-**/"           # Push string "+-**/"
          S          # Split to characters: ["+","-","*","*","/"]
           :         # Replace each
S                    # Split the string of operators to loose characters
 ðì                  # Prepend a space before each
                   # Interweave all sums with these operator-characters
     J               # Join everything together to a single string
.E                   # Evaluate each as a Python `eval` expression (and output implicitly)

(বিভাগে আমার এই 05AB1E ডগা দেখুন কিভাবে অভিধান ব্যবহার করতে হয়? , কিভাবে কম্প্রেস স্ট্রিং অভিধান অংশ নয়? আর কত বড় পূর্ণসংখ্যার কম্প্রেস কিভাবে? ) বুঝতে “¡×€µ‚•„í†ìˆÈŒšï¿Ÿ¯¥Š—¿áÓÁÏ“, '…§, '°¡, .•4º»Ÿć'Rþн•, Ž9o, এবং “‰´Øè„Æ€ººß“হবে।

ধাপে ধাপে উদাহরণ:

  • ইনপুট: two hundred twenty two divided by two times minus fifty seven plus three hundred eighteen minus minus ten
  • পদক্ষেপ 1: "বাই" সরান: two hundred twenty two divided two times minus fifty seven plus three hundred eighteen minus minus ten
  • পদক্ষেপ 2: সঠিক সংখ্যা সহ "বারো" এর মাধ্যমে "শূন্য" রূপান্তর করুন: 2 hundred twenty 2 divided 2 times minus fifty 7 plus 3 hundred 8een minus minus 10
  • পদক্ষেপ 3: সমস্ত "টি" সরান: 2 hundred weny 2 divided 2 imes minus fify 7 plus 3 hundred 8een minus minus 10
  • পদক্ষেপ 4: "" 10 "দিয়ে" সমস্ত "প্রতিস্থাপন করুন: 2 hundred weny 2 divided 2 imes minus fify 7 plus 3 hundred 8+10 minus minus 10
  • পদক্ষেপ 5: সমস্ত "শত" "" 100 "এর সাথে প্রতিস্থাপন করুন: 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
  • পদক্ষেপ 7: সমস্ত "y" কে "* 10" দিয়ে প্রতিস্থাপন করুন: 2 *100 2 *10 2 divided 2 imes minus 5 *10 7 plus 3 *100 8+10 minus minus 10
  • পদক্ষেপ 8: ["প্লাস", "বিয়োগ", "আইমে", "আইমেস", "বিভক্ত"] দ্বারা বিভক্ত করুন: ["2 *100 2 *10 2 "," 2 "," "," 5 *10 7 "," 3 *100 8+10 "," "," 10"]
  • পদক্ষেপ 9: প্রতিটি স্পেসে বিভক্ত করুন: [["2","","*100","2","*10","2",""],["","","2",""],["",""],["","5","*10","7",""],["","3","","*100","8+10",""],["",""],["","10"]]
  • পদক্ষেপ 10: খালি আইটেমগুলি সরান: [["2","*100","2","*10","2"],["2"],[],["5","*10","7"],["3","*100","8+10"],[],["10"]]
  • পদক্ষেপ 11: আকার 2 এর অংশগুলিতে বিভক্ত হয়ে যোগ দিন: [["2*100","2*10","2"],["2"],"",["5*10","7"],["3*100","8+10"],"",["10"]]
  • পদক্ষেপ 12: পাইথন evalপ্রতিটি:[[200,20,2],[2],"",[50,7],[300,18],"",[10]]
  • পদক্ষেপ 13: প্রতিটি যোগ করুন: [222,2,"",57,318,"",10]
  • পদক্ষেপ 14: রেজিস্টার থেকে স্ট্রিংটি আবার চাপুন এবং অক্ষরগুলি বাদ দিয়ে সমস্ত কিছু সরিয়ে ফেলুন: dividedimesminusplusminusminus
  • পদক্ষেপ 15: অপারেটর অক্ষরের সাথে "প্লাস", "বিয়োগ", "আইমেস", "আইমে", "বিভক্ত" প্রতিস্থাপন করুন এবং একটি স্পেস দিয়ে এগুলিকে প্রিপেন্ড করুন: [" /"," *"," -"," +"," -"," -"]
  • পদক্ষেপ 16: একসাথে কাটা এবং উভয় এক সাথে যোগদান: 222 /2 * -57 +318 - -10
  • আউটপুট: পাইথন evalস্ট্রিং এবং আউটপুট সুস্পষ্টভাবে:-5999.0

স্ক্র্যাচ থেকে কোনও সমাধান করার চেষ্টা করেননি বা আপনার বিস্তারিত আলোচনা করেছেন, তবে আমি একটি গল্ফ লক্ষ্য করেছি ।
Emigna

@ এমিগনা ধন্যবাদ!
কেভিন ক্রুইজসেন

2

sfk , 572 449 423 বাইট

এটি সবই এক লাইন হতে পারে তবে এটি পড়ার উদ্দেশ্যে আমি ফাঁকা জায়গাগুলির পরিবর্তে নিউলাইনগুলি ব্যবহার করেছি।

xed -i
_plus_+_
_minus_-_
_times[ortext]time_*_
_divided?by_/_
+xed
"_[white][2 chars of a-z][chars of a-z]ty_[parts 1,2]0_"
"_[white][2 chars of a-z][chars of a-z]een_[part1]1[part2]_"
_ten_10_
_lev_11_
_twe_12_
+xed
_ze_0_
_on_1_
_tw_2_
_th_3_
_fo_4_
_fi_5_
_si_6_
_se_7_
_ei_8_
_ni_9_
+xed
_0[white][keep][digit]__
"_[chars of e-z ]__"
+xed
"_?dd[keep][2 digits]_[part1]_"
_?dd[keep][digit]_[part1]0_
_dd_00_
+calc #text

এটি অনলাইন চেষ্টা করুন!

আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.