Tamsayıya liste, 10 8 bayt
TṪạL;³ÆẸ
Negatif olmayan tamsayıların listesini pozitif tamsayılarla eşler. Çevrimiçi deneyin!
Listeye tam sayı, 8 bayt
ÆE©Ḣ0ẋ®;
Pozitif tam sayıları negatif olmayan tam sayı listelerine eşler. Çevrimiçi deneyin!
Arka fon
Let p 0 , p 1 , p 2 , ⋯ artan asal sayıların dizisi olabilir.
Negatif olmayan tamsayılardır, her liste için A: = [a 1 , ⋯, bir n ] , biz harita A için p 0 z (A) p 1 , bir 1 ⋯ p , n bir , n , Z, (A) sayısıdır A'nın son sıfırları .
Yukarıdaki haritayı tersine çevirerek. Bir İçin pozitif tamsayı k , biz benzersiz ardışık asal güçlerin ürünü olarak çarpanlarına n = p 0 α 0 p 1 α 1 ⋯ p n α n , nereye α n > 0 , daha sonra listeyi yeniden α [ 1 , ⋯, α n ] , α 0 sıfır ekleyerek .
Nasıl çalışır
Tam sayıya liste
TṪạL;³ÆẸ Main link. Argument: A (list of non-negative integers)
T Yield all indices of A that correspond to truthy (i.e., non-zero) items.
Ṫ Tail; select the last truthy index.
This returns 0 if the list is empty.
L Yield the length of A.
ạ Compute the absolute difference of the last truthy index and the length.
This yields the amount of trailing zeroes of A.
;³ Prepend the difference to A.
ÆẸ Convert the list from prime exponents to integer.
Listelenecek tam sayı
ÆE©Ḣ0ẋ®; Main link. Input: k (positive integer)
ÆE Convert k to the list of its prime exponents.
© Save the list of prime exponents in the register.
Ḣ Head; pop the first exponent.
If the list is empty, this yields 0.
0ẋ Construct a list of that many zeroes.
®; Concatenate the popped list of exponents with the list of zeroes.
Örnek çıktı
İlk yüz pozitif tam sayı aşağıdaki listelerle eşleşir.
1: []
2: [0]
3: [1]
4: [0, 0]
5: [0, 1]
6: [1, 0]
7: [0, 0, 1]
8: [0, 0, 0]
9: [2]
10: [0, 1, 0]
11: [0, 0, 0, 1]
12: [1, 0, 0]
13: [0, 0, 0, 0, 1]
14: [0, 0, 1, 0]
15: [1, 1]
16: [0, 0, 0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