การรวมผลรวมของผลิตภัณฑ์ดิจิตอลซ้ำกันอย่างต่อเนื่อง


13

ป.ร. ให้ไว้เป็นจำนวนเต็มบวกn( ตัวอย่าง:n=1234444999 )

  • แยกเป็นการวิ่งหลักที่ต่อเนื่องกัน:
    • [1, 2, 3, 4444, 999]
  • ใช้ผลิตภัณฑ์ดิจิตอลของการทำงานแต่ละครั้ง
    • [1, 2, 3, 4*4*4*4, 9*9*9] = [1, 2, 3, 256, 729]
  • รวมมัน ...
    • 991
  • ทำซ้ำจนกระทั่งสิ่งนี้รวมเป็นตัวเลขเดียว:
    • 1234444999
    • 991
    • 82
    • 10
    • 1
  • ส่งคืนหมายเลขสุดท้าย

กรณีทดสอบ

BASE CASES:
0 = 0
...
9 = 9

OTHER CASES:
1234444999                     = 1
222222222222222                = 8
111222333444555666777888999000 = 9
11122233344455566677788899     = 8
1112223334445                  = 6
14536                          = 1
99                             = 9

ตัวอย่างที่ร้องขอ:

334455553666333
9+16+625+3+216+27
896
8+9+6
23
2+3
**5**

ชนะ?

มันคือนับว่าต่ำที่สุดนับเป็นผู้ชนะ


Annnnnnnnnnnnnnnnnnd ... นี่ไม่ใช่กล่องทราย อึ. ไม่มากที่ฉันสามารถทำได้ตอนนี้ขอโทษทุกคน..
Magic Octopus Urn

11
มันจะเป็นการดีถ้ามีกรณีทดสอบที่ตัวเลขแบบเดียวกันไม่ได้อยู่ในกลุ่มข้อมูลติดต่อกัน
xnor

1
เราสามารถรับข้อมูลเป็นรายการตัวเลขได้หรือไม่? 11122233344455566677788899บางภาษาไม่สามารถสนับสนุนจำนวนเต็มสูงที่สุดเท่าที่
ETHproductions

@ETHproductions คุณสามารถระบุจำนวนเต็มสูงสุดที่อนุญาตโดยภาษาของคุณและให้คำตอบของคุณถูกต้องหากคุณสามารถอธิบายขอบเขต
Magic Octopus Urn

4
evet หลักเดียวกันจะปรากฏใน 2 วิ่งที่แตกต่างกันเช่น: 33445555666333?
Mr. Xcoder

คำตอบ:


7

05AB1E , 7 6 5 ไบต์

ขอบคุณEmigna ที่บันทึกไบต์!

vSγPO

ใช้การเข้ารหัส05AB1E ลองออนไลน์!


3
ฉันเพิ่งสังเกตเห็นว่าเป็นครั้งแรกที่อวตารของคุณเป็น doge meme
Magic Octopus Urn

@MagicOctopusUrn และคุณทำให้ฉันสังเกตเห็นว่าเช่นกัน ...
Socratic Phoenix

คุณสามารถแทนที่ด้วยgF v
Emigna

@Emigna Oohh แน่นอน! ขอขอบคุณ! :)
Adnan

5

เยลลี่ขนาด 9 ไบต์

DŒgP€SµÐL

ลองออนไลน์

นี่คือวิธีการทำงาน:

D  - input as a list of digits
Œg - group runs of equal elements
P€ - the product of each element
S  - the sum of the list
µ  - syntax stuff to separate the left from the right
ÐL - repeat until we get a result twice, then return that result.

เหตุใด P จึงไม่เปลี่ยนเวกเตอร์อัตโนมัติ ดูเหมือนว่าจะแปลก ...
ผลไม้ที่แยกกันเมื่อ

ไม่มี P เวกเตอร์โดยอัตโนมัติเพื่อให้คุณไม่จำเป็นต้อง
แยกผลไม้

ไม่ P ไม่ได้ทำให้เป็นภาพเวกเตอร์: tio.run/##y0rNyan8/9/l6KT0gOBDWw9P8Pn//78RKgAA
Zacharý

โอ้ฉันเข้าใจ - Œgไม่สอดคล้องเมื่อมีกลุ่มเดียว อะไรคือเหตุผลเบื้องหลัง
แยกผลไม้

ไม่มีเงื่อนงำเลย!
Zacharý

5

Mathematica, 55 42 ไบต์

#//.i_:>Tr[Times@@@Split@IntegerDigits@i]&

-13 ไบต์จาก @JungHwan มิน Thanx!

ในกรณีที่มีคนต้องการใช้สิ่งนี้เป็นเครื่องกำเนิดตัวเลขแบบสุ่ม
นี่คือจำนวน 100,000 ครั้งแรก

{{1, 17320}, {2, 4873}, {3, 10862}, {4, 11358}, {5, 10853}, {6, 9688}, {7, 11464}, {8, 10878}, { 9, 12704}}
หรือถ้าคุณเล่นพนันอย่าเอาเงินของคุณไปเป็น 2!


5

Japtap , 17 15 13 ไบต์

e".+"_¬ò¦ x_×

ทดสอบออนไลน์! รับอินพุตเป็นสตริง

ยังไม่พอใจกับคำตอบนี้ ...

คำอธิบาย

e".+"_  ¬ ò¦  x_  ×
e".+"Z{Zq ò!= xZ{Zr*1}}

e".+"                     Repeatedly replace all matches of /.+/ (the entire string)
     Z{               }   Z with this function:
       Zq                   Split Z into chars.
          ò!=               Partition at inequality; that is, split into runs of equal items.
              xZ{    }      Take the sum of: for each item in Z:
                 Zr*1         the item reduced by multiplication (i.e. the product).
                          This procedure is repeated until the same result is yielded twice.
                          Implicit: output result of last expression

คุณสามารถใช้เป็นจำนวนเต็มและระบุจำนวนอินพุตสูงสุดที่อนุญาตขออภัยฉันเปลี่ยนคำตอบหลังจากโพสต์เป็นคำตอบเริ่มต้นสำหรับคำถามนั้น
Magic Octopus Urn

@ MagicOctopusUrn โอ้เฮ้ขอบคุณ ที่จะช่วยประหยัดสองไบต์ต่อไป ...
ETHproductions

1
นอกจากนี้เมื่อx_×รวมกับI'm unsatisfiedทำให้ฉันหัวเราะ ขอบคุณ;)
Magic Octopus Urn

ฉันคิดว่าน่าßจะเป็นวิธีที่จะไปที่นี่ ฉันผิดไป! (อย่างน้อยครึ่ง 5 โมงเช้าก็นั่งรถบัสไปสนามบินสิ!)
Shaggy

"ยังไม่พอใจ" ... ดังนั้น ... คุณจะพอใจในที่สุด?
Zacharý


4

Brachylogขนาด 8 ไบต์

Ḋ|ẹḅ×ᵐ+↰

ลองออนไลน์!

คำอธิบาย

Ḋ          Input = Output = a digit
 |         Or
  ẹ        Split into a list of digits
   ḅ       Group consecutive equal elements together
    ×ᵐ     Map multiply
      +    Sum
       ↰   Recursive call

คุณไม่เคยคาดหวังว่า Brachylog จะเอาชนะเจลลี่ที่นี่ได้ไหม?
Erik the Outgolfer

@EriktheOutgolfer เมื่อ Brachylog ชนะ Jelly ข้อสันนิษฐานแรกของฉันคือคำตอบของ Jelly ไม่ดีที่สุด
Fatalize

ของฉันเช่นกันยกเว้นฉันพยายามทำเช่นนี้ในเยลลี่ด้วย สิ่งนี้ก็คือ 05AB1E ยังคงเต้นอยู่ :)
Erik the Outgolfer

ดี. มันเป็นหนึ่งไบต์และคำตอบของเยลลี่ก็คือฉันใช่ฉันคาดหวังว่า Brachylog จะชนะเยลลี่
Zacharý



2

Husk , 8 ไบต์

ωöṁΠgmis

รับและส่งคืนจำนวนเต็ม ลองออนไลน์!

คำอธิบาย

การมีบิวท์อินสำหรับฐาน 10 หลักน่าจะดี ...

ωöṁΠgmis
ω         Iterate until a fixed point is found
 ö        the composition of the following four functions:
       s   convert to string,
     mi    convert each digit to integer,
    g      group equal adjacent integers,
  ṁΠ       take product of each group and sum the results.

2

JavaScript (ES6), 77 73 67 65 ไบต์

บันทึก 2 ไบต์ขอบคุณ @CraigAyre

f=s=>s>9?f(''+eval(s.replace(/(.)\1*/g,s=>'+'+[...s].join`*`))):s

อย่างไร?

อินพุตsถูกแปลงเป็นนิพจน์เชิงคำนวณด้วย:

s.replace(/(.)\1*/g, s => '+' + [...s].join`*`)

ยกตัวอย่างเช่นจะกลายเป็น1234444999+1+2+3+4*4*4*4+9*9*9

เราประเมินการแสดงออกนี้และทำการเรียกซ้ำด้วยผลลัพธ์จนกว่าจะถูกทำให้เป็นทศนิยมหนึ่งหลัก

กรณีทดสอบ


คุณสามารถบันทึกคู่ของไบต์โดยการเปรียบเทียบกับ 9 ?:f=s=>s>9?f(''+eval(s.replace(/(.)\1*/g,s=>'+'+[...s].join`*`))):s
เครก Ayre

@ CraigAyre ดูเหมือนว่าวิธีการของฉันค่อนข้างซับซ้อนเกินไปแน่นอน ขอบคุณ!
Arnauld


2

Haskell , 103 70 69 ไบต์

import Data.List
until(<10)$sum.map product.group.map(read.pure).show

ลองออนไลน์!


1
until(<10)คุณสามารถร่นว่าเป็นจำนวนมากโดยใช้ นอกจากนี้ยังmap(read.pure)สามารถเคลื่อนย้ายมาก่อนshowซึ่งจะบันทึกวงเล็บ
Ørjan Johansen

ใช่มันดีกว่ามาก!
bartavelle

1
คุณสามารถใช้$แทนวงเล็บด้านนอก
Ørjan Johansen


1

MATL 11 ไบต์

`!UY'^sVtnq

ลองที่MATL Online

คำอธิบาย

        % Implicitly grab input as a string
`       % Do...while loop
  !U    % Convert the string to an array of numbers (the digits)
  Y'    % Perform run-length encoding
  ^     % Raise the digits to the power corresponding to the number of times they
        % occurred consecutively
  s     % Sum the result
  V     % Convert to a string
  tn    % Duplicate and determine the number of characters in the string
  q     % Subtract one, causes the loop to continue until it's a single digit
        % Implicit end of do...while loop and display


1

R, 97 96 ไบต์

a=scan(,"");while(nchar(a)>1){a=paste(sum(strtoi((b<-rle(el(strsplit(a,""))))$v)^strtoi(b$l)))}a

วิธีการที่แตกต่างกันเล็กน้อยกว่าอื่น ๆ คำตอบโดยใช้R

คำตอบนี้ทำให้การใช้ฟังก์ชั่นซึ่งrlecompute[s] the lengths and values of runs of equal values in a vector

-1ไบต์ขอบคุณ @Giuseppe!


1
**เทียบเท่ากับ^
Giuseppe

1

Braingolf 25 ไบต์

!L1-Mv[RG(d&*)&+!L1-Mv>]R

จะเพิ่มลิงค์ TIO เมื่อฉันได้รับ Dennis เพื่อดึงเวอร์ชันล่าสุดเนื่องจากการใช้ตัวดำเนินการโลภใน(...)ลูปปัจจุบันใช้งานไม่ได้กับ TIO

คำอธิบาย

!L1-Mv[RG(d&*)&+!L1-Mv>]R  Implicit input from commandline args
!L1-M                      Push length of input minus 1 to stack2
     v                     Switch to stack2
      [.........!L1-Mv>]   While length of input > 1..
       RG                  Split into digit runs
         (d&*)             Product of digits of each item in stack
              &+           Sum stack
                        R  Return to stack1
                           Implicit output from stack

1

Japt , 19 ไบต์

=ò¦ m¬®×Ãx)<A?U:ßUs

ลองออนไลน์!

คำอธิบาย:

=ò¦ m¬®×Ãx)<A?U:ßUs
=                    // Implicit U (input) =
 ò¦                  //   Split the input into an array of consecutive digit runs
    m¬               //   Split each inner array: ["1","22","333"] -> [["1"],["2","2"],["3","3","3"]]
      ®              //   Map; At each item:
       ×             //     Get the product of each run
        Ã            //   }
         x           //   Sum
           <A        // <10
             ?       // If true:
              U      //   return U
               :     // Else:
                ß    //   Run the program again; Pass:
                 Us  //     U, cast to a string
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.