আংশিক পণ্য আউটপুট


17

ইন দীর্ঘ গুণ , সংখ্যা গুন করার পরে, আপনি আংশিক পণ্যের সঙ্গে, এই চ্যালেঞ্জ আপনি আউটপুট ঐ আংশিক পণ্য হবে বাকি হয়।

যেহেতু দীর্ঘ গুণ দীর্ঘ, তাই আপনার কোডটি ক্ষতিপূরণ দেওয়ার জন্য যতটা সম্ভব সংক্ষিপ্ত হওয়া দরকার।

উদাহরণ

34, 53
102, 1700

48, 38 
384, 1440

361, 674
1444, 25270, 216600

0, 0
0

1, 8
8

বিশেষ উল্লেখ

  • ইনপুট / আউটপুট যেকোন যুক্তিসঙ্গত বিন্যাসে যেমন অ্যারে, কমা-বিভাজিত স্ট্রিং (বা অন্য কোনও ডিলিমিটার যা অঙ্ক নয়), তালিকা, ফাংশন আর্গুমেন্ট ইত্যাদি হতে পারে may
  • আংশিক পণ্য অবশ্যই ক্রমবর্ধমান ক্রম হতে হবে।
  • যদি আংশিক পণ্য হয় তবে 0আপনি এটি আউটপুট দিতে চান কিনা তা চয়ন করতে পারেন।

এটি তাই বাইট জেতে সংক্ষিপ্ততম কোড!


আমি ধরে নিচ্ছি যে সংখ্যাগুলি স্ট্রিং হতে পারে, তাই না?
মামা ফান রোল

0,0 পরীক্ষার কেসটি এটিকে আরও শক্ত করে তুলছে।
xnor

এর জন্য প্রত্যাশিত ফলাফল কী 12, 102? বেশিরভাগ উত্তর ফিরে আসবে বলে মনে হচ্ছে 24, 0, 1200
ডেনিস

@ ডেনিস 24, 0, 1200ভাল আছেন। আমি পোস্টে উল্লেখ করব
ডাউনগোট

উত্তর:


4

জেলি, 10 বাইট

DU×µLR’⁵*×

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

কিভাবে এটা কাজ করে

DU×µLR’⁵*×  Left argument: multiplier -- Right argument: multiplicant

D           Convert the multiplier to base 10 (array of digits).
 U          Reverse the array.
  ×         Multiply each digit by the multiplicant.
   µ        Begin a new, monadic chain. Argument: A(array of products)
    L       Get the length of A.
     R      Turn length l into [1, ..., l].
      ’     Decrement to yield [0, ..., l-1].
       ⁵*   Compute 10**i for each i in that range.
         ×  Hook; multiply the powers of ten by the corresponding elements of A.

3
আমি অনুমান করছি যে এই ভাষার নামটি এ থেকে আসে যে এটি প্রত্যেককে জেলি অনুভব করে।
জিওকাভেল

7

পাইথ, 12 বাইট

.e**Qsb^Tk_w

পরীক্ষা স্যুট

ইনপুট নিউলাইনকে পৃথক করে, যেমন akes

361
674

ব্যাখ্যা:

.e**Qsb^Tk_w
                Implicit: Q = eval(input()),T = 10
           w    Input the second number as a string.
          _     Reverse it.
.e              Enumerated map, where b is the character and k is the index.
     sb         Convert the character to an int.
   *Q           Multiply by Q.
  *    ^Tk      Multiply by T ^ k. (10 ^ index)

4

জাভাস্ক্রিপ্ট (ES7), 48 বাইট

(a,b)=>[...b+""].reverse().map((d,i)=>10**i*a*d)

ES6 (56 বাইট)

(a,b)=>[...b+""].reverse().map((d,i)=>a*d+"0".repeat(i))

ব্যাখ্যা

সংখ্যা হিসাবে আংশিক পণ্যগুলির অ্যারে প্রদান করে।

(a,b)=>
  [...b+""]    // convert the multiplier to an array of digits
  .reverse()   // reverse the digits of the multiplier so the output is in the right order
  .map((d,i)=> // for each digit d of the multiplier
    10**i      // get the power of ten of the digit
      *a*d     // raise the product of the digit to it
  )

পরীক্ষা

এটি স্ট্যান্ডার্ড ব্রাউজারগুলিতে কাজ করার Math.powপরিবর্তে পরীক্ষাগুলি ব্যবহার **করে।


3

লুয়া, 72 68 বাইট

b=arg[2]:reverse()for i=1,#b do print(arg[1]*b:sub(i,i)*10^(i-1))end

3

এপিএল, 21 বাইট

{⍺×x×10*1-⍨⍳≢x←⊖⍎¨⍕⍵}

এটি একটি ডায়াডিক ফাংশন যা বাম এবং ডানদিকে পূর্ণসংখ্যার গ্রহণ করে এবং একটি অ্যারে প্রদান করে। এটি কল করতে, এটি একটি ভেরিয়েবলের জন্য বরাদ্দ করুন।

ব্যাখ্যা:

             x←⊖⍎¨⍕⍵} ⍝ Define x to be the reversed digits of the right input
     10*1-⍨⍳≢         ⍝ Generate all 10^(1-i) for i from 1 to the number of digits
{⍺×x×                 ⍝ Multiply the right input by the digits and the powers of 10

1
⍎¨⍕বেশ চালাক।
ডেনিস

2

05 এ বি 1 ই , 15 বাইট

কোড:

VDgUSXFTNmY**=\

ব্যাখ্যা:

VDgUSXFTNmY**=\

V                 # Assign the input to Y
 D                # Duplicate of input, because the stack is empty
  g               # Pushes the length of the last item
   U              # Assign the length to X
    S             # Split the last item
     X            # Pushes X (length of the last item)
      F           # Creates a for loop: for N in range(0, X)
       TNm        # Pushes 10 ^ N
          Y       # Pushes Y (first input)
           *      # Multiplies the last two items
            *     # Multiplies the last two items
             =    # Output the last item
              \   # Discard the last item

2

পাইথ, 26 বাইট

DcGHKjHTFNJlK*G*@Kt-JN^TN

এটি একটি ফাংশনটিকে cএমনভাবে সংজ্ঞায়িত করে যে এটি 2আর্গুমেন্ট গ্রহণ করে এবং ফাংশনটি আংশিক পণ্যগুলি মুদ্রণ করে।

DcGHKjHTFNJlK*G*@Kt-JN^TN
DCGH                      Define function c(G, H)
    KjHT                  Set K to the list of digits converting H to base 10
        FNJlK             Set J to the length of K and loop with variable N
                          (Implicit: print)
             *G*@Kt-JN    Calculates the partial product
                      ^TN Raising it to the appropriate power of 10

1

এমএটিএল , 18 বাইট

ij48-tn:1-P10w^**P

কম্পাইলার (5.1.0) মতলব এবং অক্টেভ কাজ করে।

প্রতিটি সংখ্যা পৃথক লাইনে ইনপুট থাকে।

উদাহরণ

>> matl ij48-tn:1-P10w^**P
> 361
> 674
1444  25270 216600

ব্যাখ্যা

i           % input first number (say 361)
j           % input second number, interpreted as a string (say '674')
48-         % subtract '0' to obtain vector of figures (gives [6 7 4])
tn:1-P      % vector [n-1, ... 1, 0] where n is the number of figures (gives [2 1 0])
10w^        % 10 raised to that, element-wise (gives [100 10 1])
*           % multiply, element-wise (gives [600 70 4])
*           % multiply (gives 361*[600 70 4], or [216600 25270 1444])
P           % flip vector ([1444 25270 216600]). Implicitly display

1

হাস্কেল, 60 57 54 বাইট

g x=zipWith(\b->(x*10^b*).read.pure)[0..].reverse.show

5 বাইট কম (ড্রপ .show ) যদি আমি স্ট্রিং হিসাবে দ্বিতীয় নম্বর নিতে পারি।

ব্যবহারের উদাহরণ: g 361 674-> [1444,25270,216600]

গুন এর বিপরীত প্রতিটি অঙ্ক yসঙ্গে xসঙ্গে স্কেল 10^iযেখানে i = 0,1,2,...

সম্পাদনা: 3 বাইটের জন্য @ মরিসকে ধন্যবাদ!


আপনি এমনকি করতে পারেন (\b->(x*10^b*).read.pure)
লিন

@ মরিস: ভালো লাগছে। অনেক ধন্যবাদ!
নিমি

1

জুলিয়া, 50 49 বাইট

f(a,b)=[a*d*10^~-i for(i,d)=enumerate(digits(b))]

এটি এমন একটি ফাংশন যা দুটি পূর্ণসংখ্যা গ্রহণ করে এবং পূর্ণসংখ্যার অ্যারে প্রদান করে।

digitsফাংশন বিপরীত ক্রম ইনপুট পূর্ণসংখ্যা এর ডিজিটের একটি বিন্যাস দেখায়। আমরা সূচকটি পাই, মান enumerateজোড় ব্যবহার করে এবং আংশিক পণ্যগুলি অঙ্কের প্রথম অঙ্কের হিসাবে অঙ্কের দশকের দশকে 10 এর অঙ্কের শক্তিতে উত্থাপিত হিসাবে গণনা করি - 1।

ডেনিসকে একটি বাইট সংরক্ষণ করে!



1

সিজেম, 19 17 বাইট

q~W%eef{~~A@#**}p

প্রথম আইটেমটি একটি পূর্ণসংখ্যা এবং দ্বিতীয়টি স্ট্রিং (যেমন 34 "53") হিসাবে ইনপুট নেয় । পরামর্শগুলি স্বাগত, কারণ আমি নিশ্চিত যে এটি আরও কম হতে পারে। দুটি বাইট সঞ্চয় করার জন্য ডেনিসকে ধন্যবাদ।

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

ব্যাখ্যা

q~    e# Get input and evaluate it, x and "y"
W%    e# Reverse y so it will be properly sorted
ee    e# Enumerate through y with each character and its index
f{    e# For each digit in y...
  ~~  e# Convert the digit to an integer on the stack
  A@# e# Take 10 to the power of y's index
  **  e# Multiply all three together to get the final result
}
p     e# Print the array

1
~~A@#**কয়েকটা বাইট সাশ্রয় করে।
ডেনিস

1

হাস্কেল, 37 বাইট

a%0=[]
a%b=b`mod`10*a:(a*10)%div b 10

কোনও স্ট্রিংফাইং নয়, কেবল গাণিতিক। পুনরাবৃত্তিমূলকভাবে ক্ষুদ্রতম আংশিক পণ্যটিকে বাকী অংশে সংশোধন করে, যেখানে এর শেষ bঅঙ্কটি কেটে ফেলা হয় এবং 10 এর গুণক প্রয়োগ করা হয়। অপারেটর অগ্রাধিকার সুন্দরভাবে কাজ করে।


0

𝔼𝕊𝕄𝕚𝕟, ১১ টি চর / ২৩ বাইট (অপ্রতিযোগিতামূলক)

ᴙíⓢⓜî*$*Ⅹⁿ_

Try it here (Firefox only).

এই সমস্যার সমাধানের কোডিংয়ের সময় একটি বাগ খুঁজে পেয়েছে ...

ব্যাখ্যা

          // Implicit: î = input 1, í = input 2
ᴙíⓢ      // reverse í and split it into an array
ⓜî*$*Ⅹⁿ_ // multiply î by each individual digit in í and put in previous array
          // implicit output

0

জাপট , 28 বাইট

I=[]Vs w m@IpApY+1 /A*U*X};I

ব্যাখ্যা:

I=[]Vs w m@IpApY+1 /A*U*X};I
I=[]                         //that's simple, init an array I
    Vs                       //take the second input and convert to string
       w                     //reverse it and...
         m@              }   //...map through the chars; X is a char, Y is counter
           Ip............    //push the following value into I...
             ApY+1 /A*U*X    //10^(Y+1)/10*U*X, U is the first input
                           I //output the resulting array

দোভাষীর বাগের কারণে, ApY+1 /10পরিবর্তে ব্যবহার করতে হবে ApY, কারণ Ap0(যা 10 ^ 0) 100 দেয় gives আমি অনুমান করি যে এটি দ্রুত স্কোয়ারিংয়ের অনুমতি দেওয়ার কারণ Ap, তবে এর 0অর্থ "কোনও যুক্তি নেই" doesn't Plz ফিক্স, Eth।
নিকেল

0

পাইথন 2, 42 বাইট

f=lambda a,b:b*[0]and[b%10*a]+f(a*10,b/10)

কোনও স্ট্রিংফাইং নেই, কেবল গাণিতিক। পুনরাবৃত্তভাবে বাকীগুলির মধ্যে ক্ষুদ্রতম আংশিক পণ্য সংযোজন করে, যেখানে এর শেষ bঅঙ্কটি কেটে ফেলা হয় এবং 10 এর গুণক প্রয়োগ করা হয়।

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