Jöle , 16 14 bayt
2 bayt kaydettiğiniz için teşekkürler Dennis!
ÆḌḊ,Ṗ߀€+U$FṂo
Çevrimiçi deneyin!
Mantık açıklaması
Bir numara Verilen n :
- Eğer öyleyse
1, cevap 1. Aksi takdirde:
Temsilidir ya olduğu a + bveya a × bnerede ave bifadelerdir.
Tüm olası değerleri göz önünde bulundurun ave b:
- Eğer temsil
a + b, öyleyse ave bmenzilde [1 .. n-1].
- Temsili ise
a × b, ave daha büyük olan buygun bölenler nise 1.
Her iki durumda da liste [[<proper divisors of n larger than 1>], [1, 2, ..., n-1]]hesaplanır ( ÆḌḊ,Ṗ), mevcut bağlantıyı her numara üzerinde ߀€eşleştirin, doğru çiftleri bir araya getirin ( +U$) ve minimum değeri ( FṂo) alın.
Kod açıklaması
ÆḌḊ,Ṗ߀€+U$FṂo Main link. Assume n = 10.
ÆḌ Proper divisors. [1,2,5]
Ḋ Ḋequeue, remove the first element. [2,5]
,Ṗ Pair with Ṗop. Auto convert n = 10 to range
[1,2,3,4,5,6,7,8,9,10] and remove the last element
10, get [1,2,3,4,5,6,7,8,9].
߀€ Apply this link over each element.
+U$ Add with the Upend of itself.
FṂ Flatten and get the Ṃinimum element.
o Logical or with n.
If the list is empty, minimum returns 0 (falsy), so logical or
convert it to n.