ASCII कला के साथ लंबे समय तक कल्पना करें


13

पूरी तरह से ASCII कला के साथ कल्पना लंबे विभाजन से प्रेरित नहीं ;)

आपका काम ASCII कला के साथ लंबे समय तक हाथ दिखाना है। आप परिणाम में लोगों के स्थान के मान को रखते हुए, और अगले कॉलम के शीर्ष पर दसवें स्थान पर ले जाकर, बाएं से दाएं को जोड़कर लॉन्गहैंड जोड़ को हल करते हैं।

इनपुट

इनपुट मूल रूप से आपके इच्छित किसी भी प्रारूप में आ सकता है, जब तक आप इनपुट के रूप में 2 से 9 नंबर लेते हैं।

उत्पादन

यहाँ प्रारूपण की संभावना मेल खाती है कि आपने इसे स्कूल में कैसे सीखा:

carry row
 number1 
 number2
     ...
+   numX
--------
  result

आपके पास केवल इच्छित व्हाट्सएप की किसी भी राशि के बारे में हो सकता है;)

उदाहरण

50, 50

1
 50
+50
---
100


1651, 9879

1111
 1651
+9879
-----
11530

6489789, 9874, 287

   1122
 6489789
    9874
+    287
--------
 6499950

ASCII कला के साथ लंबे समय तक घटाव की कल्पना करें: 6 महीने में सीधे आपके पास आ रहा है
कैलक्यूलेटरफैनलाइन

बिलकुल नहीं, यह मेरी सूची में है;)
जे एटकिन

1
दरअसल मुझे कैरी रो को परिणाम के तहत रखना सिखाया गया था।
नील

1
हमें कैसे संभालना चाहिए 9+9+9+9+9+9+9+9+9+9+9+9+9?
डाउनगेट

1
@Downgoat ... you take from 2 to 9 numbers as input...
पुरखाकूदरी

जवाबों:


5

पायथ, 59 58 बाइट्स

L.[dJhl`eSQ`b:jk_.u/+NsYT.t_MjRTQ00\0djbyMPQXyeQ0\+*J\-ysQ

इसे ऑनलाइन आज़माएं। परीक्षण सूट।

बहुत लंबा रास्ता। गोल्फ अधिक करना चाहिए।

व्याख्या

L                  helper function y = lambda b:
        eSQ          largest number in input
      l`             length as string
     h               increment
    J                save to J
 .[d       `b        pad argument with spaces to that length

                             carry row:
                jRTQ           each input to base 10
              _M               reverse each result
            .t      0          transpose, padding with zeroes
    .u               0         cumulative reduce from 0:
         sY                      sum digits of column
       +N                        add previous carry
      /    T                     floor-divide by 10
   _                           reverse
 jk                            join by ""
:                     \0d      replace 0 by space

          number rows:
    PQ      all input numbers but last one
  yM        pad to correct length
jb          print on separate lines

           last number row:
  eQ         last input number
 y           pad to correct length
X   0\+      change first char to +

        separator row:
 J        width of input (saved in helper)
* \-      that many dashes

       result row:
 sQ      sum of inputs
y        pad to correct length

1

बैच, 326 बाइट्स

बाइट काउंट में स्पष्टीकरण शामिल नहीं है, बेशक।

@echo off
set t=%*                            Get the space separated parameters
set t=%t: =+%                       Change the spaces into + signs
set/at=%t%,l=p=1                    Add together, and initialise length and power
set c=                              Carry string
set d=-                             Dash string
:l                                  Loop though each power of 10
set/al+=1,p*=10,s=t/p               Divide the total by the power
for %%n in (%*)do set/as-=%%n/p     Subtract each parameter divided
set c=%s%%c%                        Anything left must have been carried
set d=-%d%                          Add a - to the line of dashes
if %p% leq %t% goto l               Keep going until we run out of powers
echo(%c:0= %                        Delete any zeros in the carry and output it
:i                                  Loop through each parameter
set n=%d:-= %%1                     Pad it with a whole bunch of spaces
call set n=%%n:~-%l%%%              Extract the rightmost characters
if "%2"=="" set n=+%n:~1%           Insert a + before the last parameter
echo %n%                            And output it
shift                               Move to the next parameter
if not "%1"=="" goto i              Until they are all consumed
echo %d%                            Output the line of dashes
echo  %t%                           Output the total (with an indent for the +)

0

जावास्क्रिप्ट (ईएस 6), 199 बाइट्स

a=>[[...t=` `+a.reduce((t,n)=>t+n)].map((_,i)=>a.reduce((c,n)=>c-n[i],90+t[i])%10||` `),a=a.map(n=>(` `.repeat(l=t.length)+n).slice(-l))).join``,...a,`-`.repeat(l),t].join`\n`.replace(/ (?=.*\n-)/,`+`)

जहां पहला \nएक शाब्दिक न्यूलाइन वर्ण का प्रतिनिधित्व करता है, जबकि दूसरा एक दो-वर्ण रेग्जैक्स एस्केप अनुक्रम है। स्पष्टीकरण:

a=>[                            Accept an array of numbers
 [...                           Split the total into digits
  t=` `+a.reduce((t,n)=>t+n)    Calculate the total and add a space
 ].map((_,i)=>a.reduce((c,n)=>  For each column
  c-n[i],90+t[i])               Subtract the column from the total
  %10||` `),                    Deduce the carry that was needed
  a=a.map(n=>                   For each input value
   (` `.repeat(l=t.length)+n)   Pad to the length of the total
    .slice(-l))                 Remove excess padding
 ).join``,                      Join the carries together
 ...a,                          Append the padded input values
 `-`.repeat(l),                 Append the dividing line
 t].join`\n`                    Append the total and join together
  .replace(/ (?=.*\n-)/,`+`)    Insert the + on the line above the -

कैरी कैलकुलेशन कुल 90कॉलम, प्रीफिक्सिंग, उस कॉलम के सभी इनपुट वैल्यू अंकों को घटाते हुए और परिणाम मोड्यूलो 10. लेते हुए काम करता है। (प्रीफिक्स इसके 90बजाय होता है, 9ताकि प्रमुख कॉलम एक खाली कैरी स्पेस उत्पन्न करे।)

हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.