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

এএসসিআইআই আর্টের সাথে দীর্ঘ বিয়োগফলটি ভিজ্যুয়ালাইজ করুন: 6 মাসের মধ্যে সরাসরি আপনার কাছে আসছেন
ক্যালকুলেটরফলাইন

বেশ নয়, এটি আমার তালিকায় রয়েছে;)
জে এটকিন

1
আসলে আমাকে ফলাফলের অধীনে ক্যারি সারিটি রাখা শিখানো হয়েছিল।
নীল

1
আমাদের কীভাবে পরিচালনা করা উচিত 9+9+9+9+9+9+9+9+9+9+9+9+9?
ডাউনওয়েট

1
@ ডাওনগোট ... 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

জাভাস্ক্রিপ্ট (ES6), 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তাই যে নেতৃস্থানীয় কলামটি একটি ফাঁকা বহনকারী স্থান তৈরি করে))

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