जेली , 18 13 10 बाइट्स
×⁵RDP$€io-
इसे ऑनलाइन आज़माएं!
13-बाइट समाधान:
×⁵RDP$€iµ’¹¬?
इसे ऑनलाइन आज़माएं!
इनपुट के साथ स्पष्टीकरण N:
׳R create a range from 1 to N * 100 (replace ³ with ⁵ for a faster execution time)
DP$ define a function ($) to get the product of the digits of a number,
€ apply that function to each element in the list,
iµ get the index of the input N in the list (or 0 if it's not there), and yeild it as the input to the next link,
’¹¬? conditional: if the answer is 0, then subtract one to make it -1, otherwise, yeild the answer
18-बाइट समाधान:
D×/
×⁵RÇ€i
Ç⁾-1¹¬?
इसे ऑनलाइन आज़माएं!
D×/ product of digits function, takes input M
D split M into digits,
×/ reduce by multiplication (return product of digits)
×⁵RÇ€i range / index function
×⁵R make a range from 1 to N*10,
Ç€ run the above function on each of the range elements,
i get the index of N in the result, or 0 if it's not there
Ç⁾-1¹¬? main function:
Ç ¬? run the line above and check if the answer is null (0)
⁾-1 if it is, return "-1",
¹ otherwise, return the answer (identity function).
अंतिम लिंक केवल 0 को बदलने के लिए है (जेली का डिफ़ॉल्ट गलत मूल्य, क्योंकि सभी सूचियां एक-अनुक्रमित हैं) -1 के साथ। यदि आप 0 को एक ठीक गलत मान मानते हैं, तो प्रोग्राम 8 बाइट्स है ।
1देना1एक महत्वपूर्ण परीक्षण मामला है।