Convergenza consecutiva ripetuta della somma dei prodotti digitali


13

Dato un intero positivo n( Esempio:n=1234444999 )

  • Separare in serie consecutive di cifre:
    • [1, 2, 3, 4444, 999]
  • Prendi il prodotto digitale di ogni corsa.
    • [1, 2, 3, 4*4*4*4, 9*9*9] = [1, 2, 3, 256, 729]
  • Somma ...
    • 991
  • Ripeti fino a quando questo non converge in un singolo numero:
    • 1234444999
    • 991
    • 82
    • 10
    • 1
  • Restituisce l'ultimo numero.

Casi test

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

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

Esempio richiesto:

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

Vincente?

È , il conteggio di byte più basso è il vincitore.


Annnnnnnnnnnnnnnnnnnd ... questa NON è la sandbox. Una schifezza. Bene, non posso fare molto ora, scusatemi tutti ._.
Magic Octopus Urn,

11
Sarebbe bene avere casi di test in cui le cifre dello stesso tipo non sono tutte in un blocco consecutivo.
xnor

1
Possiamo prendere input come un elenco di cifre? Alcune lingue non possono supportare numeri interi alti quanto 11122233344455566677788899.
ETHproductions

@ETHproductions puoi indicare il massimo numero intero consentito dalla tua lingua e avere la tua risposta valida se puoi spiegare il limite.
Magic Octopus Urn,

4
La stessa cifra verrà visualizzata in 2 sequenze diverse, ad esempio 33445555666333:?
Mr. Xcoder,

Risposte:



5

Gelatina, 9 byte

DŒgP€SµÐL

Provalo online

Ecco come funziona:

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.

Perché P non vettorializza automaticamente? Sembra strano ...
Esolanging Fruit il

No, P vettorializza automaticamente, quindi non è necessario .
Esolanging Fruit,


Oh, capisco - Œgè incoerente quando c'è un solo gruppo. Qual è il ragionamento alla base di ciò?
Esolanging Fruit,

Nessun indizio!
Zacharý,

5

Mathematica, 55 42 byte

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

-13 byte da @JungHwan Min . Grazie!

nel caso in cui qualcuno voglia usarlo come generatore di cifre casuali,
ecco il conteggio dei primi 100.000 numeri

{{1, 17320}, {2, 4873}, {3, 10862}, {4, 11358}, {5, 10853}, {6, 9688}, {7, 11464}, {8, 10878}, { 9, 12704}}
o se giochi, non mettere i tuoi soldi su 2!


5

Japt , 17 15 13 byte

e".+"_¬ò¦ x_×

Provalo online! Accetta l'input come stringa.

Non sei ancora soddisfatto di questa risposta ...

Spiegazione

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

Puoi anche prenderlo come numero intero e indicare l'input massimo consentito, mi dispiace, ho cambiato la mia risposta dopo averla inviata alla mia risposta predefinita per quella domanda.
Magic Octopus Urn,

@MagicOctopusUrn Oh, ehi, grazie. Ciò consente di risparmiare due byte, comunque ...
ETHproductions

1
Inoltre, il x_×combinato con I'm unsatisfiedmi ha fatto ridere. Grazie ;).
Magic Octopus Urn l'

Pensavo ßpotesse essere la strada da percorrere qui. Mi sbagliavo! (Almeno alle 5 e mezza del mattino, mi sono seduto sull'autobus per l'aeroporto che ero!)
Shaggy,

"Ancora non soddisfatto" ... quindi ... sei soddisfatto finalmente?
Zacharý,


4

Brachylog , 8 byte

Ḋ|ẹḅ×ᵐ+↰

Provalo online!

Spiegazione

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

Non ti saresti mai aspettato che Brachylog superasse Jelly qui, vero?
Erik the Outgolfer,

@EriktheOutgolfer Quando Brachylog batte Jelly, la mia prima ipotesi è che la risposta di Jelly non sia ottimale
Fatalizza il

Anche il mio, tranne che ho provato a farlo anche in Jelly. Il fatto è che 05AB1E batte ancora questo. :)
Erik the Outgolfer,

Bene. è un byte, e la risposta di Jelly è da parte mia, sì, mi aspetto che Brachylog superi Jelly.
Zacharý,



2

Buccia , 8 byte

ωöṁΠgmis

Prende e restituisce un numero intero. Provalo online!

Spiegazione

Avere un built-in per 10 cifre di base sarebbe bello ...

ωöṁΠ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 byte

Salvato 2 byte grazie a @CraigAyre

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

Come?

L'ingresso s viene trasformato in un'espressione aritmetica con:

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

Ad esempio, 1234444999diventa +1+2+3+4*4*4*4+9*9*9.

Valutiamo questa espressione ed eseguiamo una chiamata ricorsiva con il risultato fino a quando non viene ridotta a una singola cifra decimale.

Casi test


Puoi salvare un paio di byte confrontando con 9 ?:f=s=>s>9?f(''+eval(s.replace(/(.)\1*/g,s=>'+'+[...s].join`*`))):s
Craig Ayre,

@CraigAyre Sembra che il mio approccio sia stato un po 'troppo complicato. Grazie!
Arnauld,



1

R , 114 104 byte

n=scan(,'');while(nchar(n)>1){n=el(strsplit(n,''));b=table(n);n=as.character(sum(strtoi(names(b))^b))};n

legge dallo stdin; restituisce la risposta come una stringa.

Provalo online!


È possibile utilizzare pasteinvece di as.character. Il primo impone il suo input nel charactertipo ;-)
Frédéric l'

1

MATL, 11 byte

`!UY'^sVtnq

Provalo su MATL Online

Spiegazione

        % 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 byte

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

Approccio leggermente diverso rispetto al altra risposta utilizzando R .

Questa risposta utilizza la rlefunzione, che compute[s] the lengths and values of runs of equal values in a vector.

-1 byte grazie a @Giuseppe!


1
**equivale a^
Giuseppe,

1

Braingolf, 25 byte

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

Aggiungerò un collegamento TIO una volta che avrò Dennis per estrarre l'ultima versione, come usando gli operatori avidi all'interno (...) loop è attualmente interrotto su TIO

Spiegazione

!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 byte

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

Provalo online!

Spiegazione:

=ò¦ 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
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.