+ 8

CHALLENGE: Friedman Number

A relative integer is a Friedman number if there is an expression using all of its digits equal to it. The mathematical operations allowed in this expression are: The four basic arithmetic operations: (+, -, /, *) Eventually, other operations such as: exponentiation, factorial, square root, root n-th For example: 374 is a Friedman number in base 10 because it is possible to write it in the form 73 + 4. Another example: 127 = -1 + 2 ^ 7 Parentheses are allowed, but only to change the order of operations: for example, 1024 = (4 - 2) 10. The use of parentheses without operators would result in trivial Friedman numbers like 24 = (24). Initial zeros are also not allowed for the same reason: 001729 = 1700 + 29. So the challenge is : Build a program that takes a number and display if this last one is a Friedman number or not. Good luck.

22nd Jan 2018, 7:23 PM
Med Arezki
Med Arezki - avatar
10 Respostas
+ 5
@1of3 Yes, you can use it. The allowed operations are +,/,-,* and exponentiation,factorial,square root and root n-th. By the way: The second example define also what is an ordered Friedman Number, that means without changing the order of the digits. 25 is a Friedman Number, 25=5^2. Good luck.
22nd Jan 2018, 7:52 PM
Med Arezki
Med Arezki - avatar
+ 5
hm. but what if you can use all digits only once? otherwise any number can be build very easy. for example like 1+1+...+1 where 1 is n^(n-n) or something like that.
22nd Jan 2018, 10:13 PM
Alexy Gvozdyov
Alexy Gvozdyov - avatar
+ 4
@VcC Yes, yes ! It works. Bright, bravo, you did it !
22nd Jan 2018, 9:34 PM
Med Arezki
Med Arezki - avatar
+ 2
Not yet one liner but does the job. Easy to add any function https://code.sololearn.com/cXHQF3Zz8M3i/?ref=app
22nd Jan 2018, 9:14 PM
VcC
VcC - avatar
+ 2
Here is an ultrafast probabilistic algorithm: f=lambda n: True Because most number are Friedman. You should only allow ops on digits not using '73' for 374
22nd Jan 2018, 9:43 PM
VcC
VcC - avatar
+ 1
I have an idea. But you used exponentiation in your second example, while you only said four basic arithmetic operations before. Is that in or out?
22nd Jan 2018, 7:35 PM
1of3
1of3 - avatar
+ 1
@Alex Gvozdyov, Yes, all digits are used only once I believe
26th Jan 2018, 6:06 AM
Lindsay Linjie Chen
Lindsay Linjie Chen - avatar
+ 1
My try in python use exhaustive permutations, and I cannot exclude the repetition...so it works but it reaches time limit for complicated numbers
26th Jan 2018, 6:08 AM
Lindsay Linjie Chen
Lindsay Linjie Chen - avatar
26th Jan 2018, 6:12 AM
Lindsay Linjie Chen
Lindsay Linjie Chen - avatar
+ 1
Let me say again: Great challenge. I learned something about iterators. Not done yet, those special rules for concatenation of digits are hard. Basically the tokens that can be operated on is any choice of digits from the original number with length strictly smaller than original number's.
27th Jan 2018, 2:53 AM
1of3
1of3 - avatar