Ẇa6ḌạÐṂ⁸Ṫ
Un collegamento monadico.
Provalo online! - Quasi nessun punto in questo link (vedi sotto)!
Come?
Nel vero stile del golfista, questo è veramente inefficiente: colpisce il timeout degli anni '60 in TIO per il test case 365 ! Localmente questo termina in 37s.
Ẇa6ḌạÐṂ⁸Ṫ - Main link: n
Ẇ - all sublists - this has an implicit make_range on it's input
- so, for example, an input of 3 yields [[1],[2],[3],[1,2],[2,3],[1,2,3]]
- the important things are: that it contains both a list of the length of the
- decimal number, and a list 1 shorter; and that it's lists only contain
- non-zero numbers and are monotonically increasing in length.
6 - literal 6
a - and (vectorises), this changes all the values to 6s
- so, the example above becomes [[6],[6],[6],[6,6],[6,6],[6,6,6]]
Ḍ - convert to decimal (vectorises) [ 6, 6,, 6, 66, 66, 666 ]
⁸ - link's right argument, n
ÐṂ - filter keep those with minimal:
ạ - absolute difference (for 366 this keeps 66 AND 666; same goes for 3666; etc.)
Ṫ - tail - get the rightmost result (for 366 keeps 666, since it's longer)
Una patch per far funzionare lo stesso algoritmo entro il limite degli anni '60 per 365 e 366 su TIO è di evitare la vettorializzazione implicita di Ḍ
with Ẇa6Ḍ€ạÐṂ⁸Ṫ
( provalo ), tuttavia questo ora seg-fault per un input di 999 ( Triangle (999) è solo 499.500 ma ognuno è un elenco di numeri interi, per un totale di Tetrahedral (999) = 166.666.500 numeri interi, non efficiente in termini di memoria, almeno in Python).