เยลลี่ , 16 14 ไบต์
ขอบคุณเดนนิสที่ช่วยประหยัด 2 ไบต์!
ÆḌḊ,Ṗ߀€+U$FṂo
ลองออนไลน์!
คำอธิบายตรรกะ
รับตัวเลขn :
- ถ้าเป็นคำตอบคือ
1 1มิฉะนั้น:
การเป็นตัวแทนเป็นอย่างใดอย่างหนึ่งa + bหรือa × bที่ไหนaและbมีการแสดงออก
พิจารณาคุณค่าที่เป็นไปได้ทั้งหมดaและb:
- หากตัวแทนเป็น
a + bแล้วaและอยู่ในช่วงb[1 .. n-1]
- หากตัวแทนคือ
a × b, aและbเป็นตัวหารที่เหมาะสมของขนาดใหญ่กว่าn1
ในทั้งสองกรณีรายการ[[<proper divisors of n larger than 1>], [1, 2, ..., n-1]]จะคำนวณ ( ÆḌḊ,Ṗ) แมปลิงค์ปัจจุบันเหนือแต่ละหมายเลข߀€เพิ่มคู่ที่ถูกต้องเข้าด้วยกัน ( +U$) และรับค่าต่ำสุด ( FṂo)
คำอธิบายรหัส
ÆḌḊ,Ṗ߀€+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.