連続したデジタル製品の合計収束


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**

勝った?

それは、最小のバイト数が勝者です。


Annnnnnnnnnnnnnnnnnnd ...これはサンドボックスではありません。くだらない。まあ、私は今できることはあまりない、すみません。
魔法のタコUr

11
同じ種類の数字がすべて連続したチャンクに含まれていないテストケースがあるとよいでしょう。
-xnor

1
入力を数字のリストとして受け取ることはできますか?一部の言語は、の整数をサポートできません11122233344455566677788899
ETHproductions

@ETHproductionsでは、言語で許可されている最大整数入力を指定し、境界を説明できる場合は回答を有効にすることができます。
魔法のタコUr

4
同じ数字のevetは、2つの異なる実行で表示され33445555666333ますか?
ミスターXcoder

回答:


7

05AB1E7 6 5バイト

エミグナにバイトを保存してくれてありがとう!

vSγPO

05AB1Eエンコードを使用します。オンラインでお試しください!


3
あなたのアバターがドージェミームであることを初めて知りました。
魔法のタコUr

@MagicOctopusUrnとあなただけの...私はそれにも気づか製
ソクラテスのフェニックス

あなたは置き換えることができgFv
エミグナ

@Emigna Oohhもちろん!ありがとうございました!:)
アドナン

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が自動的にベクトル化しないのはなぜですか?...奇妙思われる
Esolangingフルーツ

いいえ、Pは自動的にベクトル化されるため、は必要ありません
エソランジングフルーツ

いいえ、Pはベクトル化されません:tio.run
##y0rNyan8

ああ、なるほど- Œgグループが1つしかない場合は一貫性がありません。その背後にある理由は何ですか?
エソランジングフルーツ

まったく手がかりがありません!
ザカリー

5

Mathematica、55 42バイト

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

@JungHwan Minから-13バイト。ありがとう!

誰かがこれをランダムな数字ジェネレータとして使用したい場合のため
に、最初の100.000の数字の集計があります

{{1、17320}、{2、4873}、{3、10862}、{4、11358}、{5、10853}、{6、9688}、{7、11464}、{8、10878}、{ 9、12704}}
またはギャンブルをする場合は、2にお金を入れないでください!


5

Japt17 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

また、整数として受け取って最大許容入力を記載することもできます。申し訳ありませんが、その質問のデフォルトの回答に投稿してから回答を変更しました。
魔法のタコUr

@MagicOctopusUrnああ、ちょっと、ありがとう。とにかく2バイト節約できます
...-ETHproductions

1
また、とx_×組み合わせてI'm unsatisfied私は笑いました。ありがとう;)。
魔法のタコUr

ßはここに行く方法だと思った。私は間違っていた!(少なくとも午前5時5分、私がいた空港へのバスに座っていた!)
シャギー

「まだ満たされていない」...だから...あなたはついに満足していますか?
ザカリー


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がここでゼリーのアウトゴルフをすることを決して期待しないでしょうか?
エリックアウトゴルファー

@EriktheOutgolfer BrachylogがJellyを打ち負かすとき、私の最初の仮定はJellyの答えが最適ではないということです
Fatalize

私もゼリーでこれをやろうとしたことを除いて。実は、05AB1Eはまだこれに勝っています。:)
エリック・ザ・アウトゴルファー

上手。それは1バイトで、Jellyの答えは私によるものです。そう、BrachylogがJellyに勝つと期待しています。
ザカリー



2

、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バイト

@CraigAyreのおかげで2バイト節約

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ます。

この式を評価し、結果が1桁の10進数になるまで再帰呼び出しを行います。

テストケース


9と比較して、数バイト節約できますか?:f=s=>s>9?f(''+eval(s.replace(/(.)\1*/g,s=>'+'+[...s].join`*`))):s
クレイグエアー

@CraigAyre私のアプローチは確かに少し複雑すぎたようです。ありがとう!
アーナルド




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を使用する他の回答とは少し異なるアプローチ。

この回答では、rle関数which を使用していcompute[s] the lengths and values of runs of equal values in a vectorます。

@Giuseppeのおかげで-1バイト!


1
**と同等です^
ジュゼッペ

1

Braingolf、25バイト

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

(...)ループ内で貪欲な演算子を使用することは現在TIOで壊れているため、デニスに最新バージョンを取得させると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.