มีกี่อัน?


16

ในงานนี้รหัสของคุณจะได้รับจำนวนเต็มnเป็นอินพุต รหัสของคุณควรส่งออกจำนวนทวีคูณของที่มากที่สุดซึ่งสามารถต่อกันได้ (ในฐาน ) เพื่อสร้าง (โดยไม่มีศูนย์นำหน้า) ตัวอย่างเช่นถ้าคุณได้รับเป็นอินพุต3103n26042

26042×3=78126

และสามารถทำได้โดยการเชื่อมโยง ,และ6เพื่อให้คุณเอาท์พุท378126781263

อนุญาตมาตรฐาน IO แบบใดก็ได้ รู้รอบควรตั้งเป้าที่จะลดจำนวนไบต์ในรหัส


นี่คือรายการ6562รายการแรกในลำดับนี้เริ่มต้นด้วยศูนย์:

1,1,1,1,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,1,1,1,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2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,2,2,2,2,2,2,3,3,3,3,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,2,2

8
มันจะดีที่จะมีตัวอย่างบางส่วนในรูปแบบn -> f(n)ที่f(n)เป็นคำตอบ ตามที่เป็นอยู่ตอนนี้ฉันไม่สามารถบอกได้ว่ารายการ 6561 รายการของคุณเป็นดัชนี 0 หรือดัชนี 1 รายการ
สูงสุด

@maxb มีตัวอย่างมากเกินไปที่จะทำรูปแบบนั้น รายการของฉันไม่มีการทำดัชนี
โพสต์ Rock Garf Hunter

2
แน่นอน แต่บางคนเลือกน้อยจะดีมากนอกเหนือจากตัวอย่างแรก และจากสิ่งที่ฉันเห็นเราได้รับอนุญาตให้แบ่งหมายเลขที่เราต้องการ? ดังนั้นจึงจำเป็นต้องมีการใช้กำลังดุร้าย (ในบางภาษา) เพื่อค้นหาจำนวนทวีคูณสูงสุดของ 3? นอกจากนี้คุณกำหนด 0 เป็นผลคูณของ 3 หรือไม่ จากคำถามของคุณดูเหมือนว่า 3n
สูงสุด

@maxb มีสองเทคนิคที่สามารถใช้เพื่อหาวิธีแก้ปัญหาด้วยวิธีที่สั้นกว่าและเร็วกว่า (คำใบ้ 3 เป็นพิเศษ) และใช่ 0 คือผลคูณของ 3 ฉันไม่รู้ว่ามันจะเป็นอย่างไร
โพสต์ Rock Garf Hunter

คำตอบ:


9

Haskell , 51 ไบต์

f n=sum[1|x<-scanr(:)"0".show$3*n,read x`mod`3<1]-1

ลองออนไลน์!

แนวคิดหลักมีดังต่อไปนี้: รับหลาย ๆ 3 (เรียกมันว่า3n ) วิธีที่ดีที่สุดในการเขียนเป็นการวางเคียงกันของทวีคูณของ 3 คือการเริ่มต้นจากจุดสิ้นสุด (หรือจุดเริ่มต้น) และเลือกทวีคูณ 3 อย่างตะกละตะกลาม ตัวอย่างเช่นถ้า3n=78126ดังนั้นเราจะได้รับ (เริ่มต้นจากจุดสิ้นสุด) a 6จากนั้น12และสุดท้ายเป็น78 : 78|12|6 . โปรดทราบว่านี่เป็นไปได้เพราะตัวเลขคือผลคูณของ 3 iff ผลรวมของหลักคือผลคูณของ 3 นอกจากนี้โปรดทราบว่าหากเราต่อกันสองทวีคูณของ 3 เราจะได้ผลคูณ 3 ดังนั้น6,12|6,78|12|6คือทวีคูณของ 3

ดังนั้นคำตอบสามารถพบได้โดยพิจารณารายการของคำต่อท้ายของ3n (เช่น[78126,8126,126,26,6] ) และนับทวีคูณของ 3


9

Retina , 11 ไบต์ของละติน -1

v`.3*[012¶]

ลองออนไลน์!

Retina ใช้งานได้กับสตริงแทนที่จะเป็นจำนวนเต็มดังนั้นฉันจึงใช้ตัวเลขตามที่ปรากฏในไฟล์ (ตัวเลขตามด้วยการขึ้นบรรทัดใหม่)

ขั้นตอนวิธี

โซลูชันเกือบทั้งหมดที่นี่มีการคูณด้วย 3 แต่ฉันคิดว่ามันน่าสนใจที่จะลองแก้ปัญหาโดยที่ไม่ทำ เรารู้อยู่แล้วจากอัลกอริทึมที่คนส่วนใหญ่ใช้ที่เราจำเป็นต้องระบุหมายเลขของคำต่อท้าย 3 nที่หารด้วย 3 ตอนนี้ได้รับปัจจัยของn (พูดs ), 3 sจะปรากฏเป็นคำต่อท้าย 3 nถ้าคูณs × 3 ไม่ได้ใส่เลขหลักก่อนต่อท้าย ในขณะเดียวกันถ้าคูณs × 3 จะดำเนินการแล้วต่อท้ายที่สอดคล้องกันของ 3 nจะไม่หารด้วย 3 (เนื่องจากรากดิจิตอลของ 3 * s * หารด้วย 3 - 3 หาร (10-1) และเรากำลังทำงานในฐาน 10 - และส่วนต่อท้ายที่สอดคล้องกันของ 3 * n * จะเท่ากับ 3 * s * แต่ไม่มีส่วนนำ1หรือ2ไม่หารด้วย 3)

เราจะต้องปรับความเป็นไปได้ที่ 3 * n * มีตัวเลขมากกว่าnจึงหมายความว่า 3 * n * มีคำต่อท้ายพิเศษที่ไม่ตรงกับคำต่อท้ายของn คำต่อท้ายนี้เป็นจำนวนเต็ม 3 * n * และจะหารด้วย 3 เสมอ (สำหรับเหตุผลที่ชัดเจน) ดังนั้นหากการคูณn × 3 มีเราต้องบวก 1 เข้าไปในผลลัพธ์ เราสามารถทราบได้ว่าถ้าn × 3 ไม่ได้พกมันจะมีส่วนร่วม 1 กับผลลัพธ์โดยใช้อัลกอริทึมไร้เดียงสาในขณะที่ถ้ามันไม่มันจะไม่; และเราสามารถทำการปรับเปลี่ยนนี้ได้อย่างง่ายดายโดยการนับ "คำต่อท้ายที่แสดงถึงจำนวนทั้งหมดn " โดยไม่มีเงื่อนไขแทนการตรวจสอบการพกพา เท่า (และเล็กน้อยกะทัดรัด) ที่เราสามารถทำได้โดยไม่มีเงื่อนไขไม่ได้ นับคำต่อท้ายนี้และนับคำต่อท้ายอื่นแทน (คำต่อท้ายที่ว่างเปล่าสะดวก) เพราะมันจะมาถึงผลรวมเดียวกัน

เราจะตรวจสอบว่าการคูณด้วย 3 จะดำเนินการได้อย่างไร ถ้าหลักแรกของตัวเลขมากกว่า 3 ก็ต้อง; ถ้ามันน้อยกว่า 3 มันก็ทำไม่ได้ หากเป็น 3 ไม่ว่าจะมีหรือไม่ก็ตามจะขึ้นอยู่กับตัวเลขถัดไปของตัวเลขในลักษณะเดียวกัน หากจำนวนนั้นประกอบด้วย 3 ทั้งหมดการคูณจะไม่เกิดขึ้น (มันจะหยุดสั้น ๆ ที่ตัวเลขซึ่งประกอบด้วยทั้งหมด 9 วินาที) ดังนั้นอัลกอริทึมที่เราต้องการคือ "นับจำนวนคำต่อท้ายที่เหมาะสมที่เริ่มต้นด้วย 0 หรือมากกว่า 3 วินาทีตามด้วย 0, 1, 2 หรือจุดสิ้นสุดของสตริง; บวกหนึ่งคำต่อท้ายพิเศษ"

คำอธิบาย

This algorithm ends up longer than the consensus algorithm in most languages, so I'm submitting it in Retina, a language where it turns out to be shorter than the more usual method (and a similar length to golfing languages).

v`.3*[012¶]
v`            {Count the number of} points within the input from which you can
  .             ignore one character,
   3*           and skip past any number (including zero) of 3s,
     [012¶]     to find 0, 1, 2, or the newline at the end of the input.

The requirement to ignore one character before we start looking means that the improper suffix consisting of the whole number cannot be counted (as the suffixes that we actually look at will be the ones starting one character to the right of where Retina starts, and thus not at the first character). However, the improper suffix consisting only of the newline at the end of the number will always be counted, thus giving us the one extra suffix we need.


This was the algorithm I had in mind when I wrote the question. I'm glad to see someone used it!
Post Rock Garf Hunter

@WW: This answer was more a case of "this is an interesting algorithm, let's find a language where it's efficient" than "this is an interesting language, let's find the best algorithm in it". (Although Retina is an interesting language anyway, as it happens!) I guess this is a weird side effect of the "competition per-language"; it means that you can make an answer "better", in some sense, by translating it to a language which doesn't deal with translations of competing answers well.
ais523

I believe [¶-2] saves a byte since you should be able to assume the input consists only of numeric digits and the newline.
FryAmTheEggman


3

Perl 6, 54 28 bytes

-14 bytes thanks to nwellnhof!

{+grep *%%3,[\~] .comb}o*×3

Try it online!

This counts how many prefixes of the number times three are divisible by 3.

Explanation:

{                     }o*×3  # Pass the input times 3 into the code block
            [\~] .comb   # Get all the prefixes of the number
  grep     , # Filter from that
       *%%3  # All numbers divisible by 3
 +   # Return the length of the list

Shaved off another byte.
nwellnhof

@nwellnhof I didn't realise you could combine with Whatever code. Neat!
Jo King

3

05AB1E, 14 12 7 6 bytes

3*η3ÖO

-5 bytes creating a port of @BMO's Husk answer.
-1 byte thanks to @Nitrodon by changing suffixes to prefixes.

Try it online or verify the first 1000 items.

Explanation:

3*        # Multiply the (implicit) input by 3
          #  i.e. 26042 → 78126
  η       # List of prefixes
          #  i.e. 78126 → ["7","78","781","7812","78126"]
   3Ö     # Check for each if its divisible by 3
          #  i.e. ["7","78","781","7812","78126"] → [0,1,0,1,1]
     O    # And take the sum (which is implicitly output)
          #  i.e. [0,1,0,1,1] → 3

Old 12-bytes answer:

3*.œʒ3ÖP}€gà

Or alternatively €gà can be éθg.

Try it online or verify the first 1000 items

Explanation:

3*             # Multiply the (implicit) input by 3
               #  i.e. 26042 → 78126
             # Take all possible partitions of this number
               #  i.e. 78126 → [["7","8","1","2","6"],["7","8","1","26"],["7","8","12","6"],
               #                ...,["781","26"],["7812","6"],["78126"]]
    ʒ   }      # Filter these partitions by:
     3ÖP       #  Only keep partitions where every number is divisible by 3
               #   i.e. ["7","8","1","2","6"] → [0,0,0,0,1] → 0
               #   i.e. ["78","12","6"] → [1,1,1] → 1

               #(option 1:)
         g    # Take the length of each remaining partition
               #  i.e. [["78","12","6"],["78","126"],["7812","6"],["78126"]] → [3,2,2,1]
           à   # And take the max (which we output implicitly)
               #  i.e. [3,2,2,1] → 3

               #(option 2:)
         é     # Sort the remaining partitions by length
               #  i.e. [["78","12","6"],["78","126"],["7812","6"],["78126"]]
               #   → [["78126"],["78","126"],["7812","6"],["78","12","6"]]
          θ    # Take the last one (the longest)
               #  i.e. [["78126"],["78","126"],["7812","6"],["78","12","6"]]
               #   → ["78","12","6"]
           g   # And take its length (which we output implicitly)
               #  i.e. ["78","12","6"] → 3

1
Using prefixes instead of suffixes gives the same result in one fewer byte.
Nitrodon

@Nitrodon Thanks! :) I knew about the 1-byte prefixes builtin, but didn't realize the challenge works by using prefixes instead of suffixes as well.
Kevin Cruijssen


2

APL (Dyalog Unicode)ขนาด 14 ไบต์

+/0=3|+\⍎¨⍕3×⎕

ลองออนไลน์! หรือตรวจสอบ 1,000 รายการแรก

Explanaition

+/0=3|+\⍎¨⍕3×⎕
               prompt for input
           3×   multiply by 3
        ⍎¨⍕     convert the number to a vector of digits
      +\        take the cumulative sum
    3|          find each term modulo 3
+/0=            count those that equal 0

วิธีนี้ใช้งานได้เพราะตัวเลขหารด้วยสามถ้าหากผลรวมของตัวเลขหารด้วยสาม



2

Haskell , 44 ไบต์

g.(*3).max 1
g 0=0
g n=0^mod n 3+g(div n 10)

ลองออนไลน์!

ใช้การสังเกตของ Delfad0rว่าผลลัพธ์คือจำนวนของส่วนต่อท้าย (เท่ากับคำนำหน้า) ของ 3n ที่เป็นทวีคูณของ 3 วิธีนี้ค้นหาคำนำหน้าทางคณิตศาสตร์โดยการหารพื้นซ้ำ ๆ 10 โดยแทนที่จะใช้การแทนสตริง นี่0^เป็นวิธีคำนวณทางคณิตศาสตร์สั้น ๆ1หากเลขชี้กำลังmod n 3เป็นศูนย์และให้สร้างเป็น0อย่างอื่น

บรรทัดแรกคือฟังก์ชั่นหลักซึ่งเพิ่มอินพุตสามเท่าก่อนที่จะส่งผ่านไปยังฟังก์ชันตัวช่วยgซึ่งถูกกำหนดแบบเรียกซ้ำ การmax 1แฮ็คเพื่อให้f(0)เท่ากับ 1 เนื่องจากเราต้องจัดการกับศูนย์เหมือนสตริง'0'แทนที่จะเป็นสตริงว่าง


2

MathGolf , 15 14 ไบต์

3*▒0\Ƨ_3÷\;]Σ

ลองออนไลน์!

-1 ไบต์ขอบคุณ JoKing

คำอธิบาย

3*                Multiply the input by 3
  ▒               Convert to a list of digits
   0\             Push a zero and swap the top two elements
     Æ            Execute the next 5 characters for each block
      §           Concatenate
       _          Duplicate
        3÷        Check divisibility by 3 (returns 0 or 1)
          \       Swap top two elements
           ;      Discard TOS (the last swap
            ]Σ    Wrap the entire stack in an array and output its sum

ฉันไม่รู้ว่านี่เป็นวิธีแก้ไขปัญหาที่ถูกต้องหรือไม่ แต่เป็นการเลียนแบบโซลูชัน JS ของ Arnauld หากฉันไม่ถูกต้องฉันจะพยายามแก้ไข



@ โจกิ้งฉันจะทำสิ่งที่รหัสของคุณแล้วฉันจะอัปเดตพร้อมคำอธิบาย (ฉันรู้ว่ามันทำอะไร แต่ไม่ใช่ว่าทำไมมันใช้งานได้)
maxb

1

Pyth, 16 15 ไบต์

lef!.E%vT3./`*3

ลองออนไลน์ได้ที่นี่

lef!.E%vT3./`*3Q   Implicit: Q=eval(input())
                   Trailing Q inferred
            `*3Q   Input * 3
            `      Convert to string
          ./       Take divisions into disjoint substrings
  f                Filter the above using:
       vT            Convert each back to integer
      %  3           Mod 3
    .E               Are any non-0?
   !                 Logical NOT
le                 Take the length of the last value
                   As the substring sets are generated in order of number of 
                   substrings, the last value is guaranteed to be the longest

1

ภาษาการเขียนโปรแกรมของเช็คสเปียร์ , 376 ไบต์

T.Ajax,.Page,.Act I:x.Scene I:x[Enter Ajax and Page]Ajax:Listen tothy!You be the sum ofthe sum ofyou you you!Scene V:x.Page:You be the sum ofyou the quotient betweena cat the sum ofa cat the remainder of the quotient betweenI the sum ofa big cat a cat!Ajax:You be the quotient betweenyou twice the sum ofa big big cat a cat!Be you nicer zero?If solet usscene V.Page:Open heart

ลองออนไลน์!

ฉันสงสัยว่า1/(1+I/3)เคล็ดลับดีกว่าการควบคุมโฟลว์หรือไม่


คุณไม่จำเป็นต้องxหลังจากฉาก ลองออนไลน์!
Jo King

1

Java 10, 66 ไบต์

n->{int m=1,r=n<1?1:0;for(n*=3;m<n;m*=10)r+=n%m%3<1?1:0;return r;}

ลองออนไลน์

คำอธิบาย:

ใช้การรวมกันของคำตอบแบบ Huskของ@BMO (ตรวจสอบจำนวนหารคำนำหน้าว่าหารด้วย 3) และJavaScript (ES6) ของ@Arnauldคำตอบ (ทวีคูณเป็นจำนวนเต็ม 10 ทุกการวนซ้ำและรับค่านำหน้าด้วยโมดูโลของเลขจำนวนเต็มนี้) .

n->{             // Method with integer as both parameter and return-type
  int m=1,       //  Modulo-integer, starting at 1
      r=         //  Result-integer, starting at:
        n<1?     //   If the input is the edge-case 0:
         1       //    Start it at 1
        :        //   Else:
         0;      //    Start it at 0
  for(n*=3;      //  Multiply the input by 3
      m<n;       //  Loop as long as `m` is still smaller than `n`
      m*=10)     //    After every iteration: Multiply `m` by 10
    r+=n%m       //   If `n` modulo-`m` (to get a suffix),
          %3<1?  //   is divisible by 3:
        1        //    Increase the result-sum by 1
       :         //   Else:
        0;       //    Leave the result-sum the same by adding 0
  return r;}     //  Return the result-sum



1

Python 2 , 48 ไบต์

n=input()*3;p=n<1
while n:p+=n%3<1;n/=10
print p

ลองออนไลน์!

คล้ายกับคำตอบของ ovsแต่รับทั้งคำนำหน้า mod 3 โดยไม่ต้องสะสมมากกว่าหลักสุดท้าย เอาต์พุตTrueเป็น 1 เมื่ออินพุต 0


Python 3 , 42 ไบต์

f=lambda n:n>=1and(n%1<1/3)+f(n/10)or n==0

ลองออนไลน์!

ความคิดของการใช้ประโยชน์จากการแก้ปัญหาที่ดีมากของ ais523 แบ่งพื้นของอินพุตอย่างซ้ำ ๆ 10 จนกว่าจะเป็นศูนย์และนับว่าส่วนที่เป็นเศษส่วนน้อยกว่า 1/3 ในอินพุตที่มีขนาดใหญ่มากความแม่นยำลอยในที่สุดก็จะมีปัญหา n=0กรณีที่มีการจัดการกับor n==0ทำให้มันกลับ True สำหรับ 1. รหัสสามารถทำงานในหลาม 2 ถ้าใส่เป็นลอยถ้าเราเขียนn%1<1/3เป็นn%1*3<1ซึ่งเป็นระยะเวลาเดียวกัน


1

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

×3DÄ3ḍS

ลองออนไลน์!

มันทำงานอย่างไร

×3DÄ3ḍS  Main link. Argument: n

×3       Compute 3n.
  D      Decimal; convert 3n to the array of its digits in base 10.
   Ä     Accumulate; take the cumulative sum.
         Note that an integer and its digit sum are congruent modulo 3.
    3ḍ   Test each partial digit sum for divisibility by 3.
      S  Take the sum of the Booleans, counting the multiples of 3.

0

Stax , 8 ไบต์

αNΘ╠╠1d}

เรียกใช้และแก้ไขข้อบกพร่อง

คลายกล่อง ungolfed และแสดงความคิดเห็นมันมีลักษณะเช่นนี้

3*      triple input
E       convert to array of decimal digits
:+      get all prefix sums
F       for each prefix sum
  3%!   is it a multiple of 3?
  +     add to running total

เรียกใช้อันนี้




โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.