Guest Posted September 27, 2007 Report Share Posted September 27, 2007 You have few calculator functions: + : add - : subtract * : mutiply / : divide % : get remainders from divide ** : power Notation: 1.f(x) = {1,2,3,4} means f(1)=1, f(2)=2, f(3)=3, f(4)=4. 2.cost = 1 means the function uses one operator. So, please find all 24 functions of 4! with minimum of operations. That is, f1(x)={1,2,3,4} f1(x)=x (cost = 0) f2(x)={1,2,4,3} f2(x)=? f3(x)={1,3,2,4} f3(x)=? f4(x)={1,3,4,2} f4(x)=? f5(x)={1,4,2,3} f5(x)=? f6(x)={1,4,3,2} f6(x)=? f7(x)={2,1,3,4} f7(x)=? f8(x)={2,1,4,3} f8(x)=? f9(x)={2,3,1,4} f9(x)=? f10(x)={2,3,4,1} f10(x)=? f11(x)={2,4,1,3} f11(x)=? f12(x)={2,4,3,1} f12(x)=? f13(x)={3,1,2,4} f13(x)=? f14(x)={3,1,4,2} f14(x)=? f15(x)={3,2,1,4} f15(x)=? f16(x)={3,2,4,1} f16(x)=? f17(x)={3,4,1,2} f17(x)=? f18(x)={3,4,2,1} f18(x)=? f19(x)={4,1,2,3} f19(x)=? f20(x)={4,1,3,2} f20(x)=? f21(x)={4,2,1,3} f21(x)=? f22(x)={4,2,3,1} f22(x)=? f23(x)={4,3,1,2} f23(x)=? f24(x)={4,3,2,1} f24(x)=5-x (cost = 1) Note: 1.it does not allow recursive function calls. 2.power operator costs 2 and others cost 1. *3.divide operator gets the floor of the divide result. that is, 3/2 => 1 Quote Link to comment Share on other sites More sharing options...
0 bonanova Posted September 27, 2007 Report Share Posted September 27, 2007 Cute puzzle. I think I have the idea. Here's a start, more to come after I get some zzzzzzzzzzz's. ---------------------------------------------------------- f1(x)={1,2,3,4} f1(x)= x cost = 0 f2(x)={1,2,4,3} f2(x)=? f3(x)={1,3,2,4} f3(x)=? f4(x)={1,3,4,2} f4(x)=? f5(x)={1,4,2,3} f5(x)=? f6(x)={1,4,3,2} f6(x)=? 4-(x+2)%4 cost=3 ---------------------------------------------------------- f7(x)={2,1,3,4} f7(x)=? f8(x)={2,1,4,3} f8(x)=? 4-(x+1)%4 cost=3 f9(x)={2,3,1,4} f9(x)=? f10(x)={2,3,4,1} f10(x)=? 1+x%4 cost=2 f11(x)={2,4,1,3} f11(x)=? f12(x)={2,4,3,1} f12(x)=? ---------------------------------------------------------- f13(x)={3,1,2,4} f13(x)=? f14(x)={3,1,4,2} f14(x)=? f15(x)={3,2,1,4} f15(x)=? 4-x%4 cost=2 f16(x)={3,2,4,1} f16(x)=? f17(x)={3,4,1,2} f17(x)=? 1+(x+2)%4 cost=3 f18(x)={3,4,2,1} f18(x)=? ---------------------------------------------------------- f19(x)={4,1,2,3} f19(x)=? 1+(x+2)%4 cost=3 f20(x)={4,1,3,2} f20(x)=? f21(x)={4,2,1,3} f21(x)=? f22(x)={4,2,3,1} f22(x)=? f23(x)={4,3,1,2} f23(x)=? f24(x)={4,3,2,1} f24(x)= 5-x cost = 1 ---------------------------------------------------------- Quote Link to comment Share on other sites More sharing options...
0 Guest Posted September 27, 2007 Report Share Posted September 27, 2007 Great~ You solve the first 6 via "shift" and "make circle" them. You still need to use "*" or "/" to "expand" and "compress" the distance for others. Quote Link to comment Share on other sites More sharing options...
Question
Guest
You have few calculator functions:
+ : add
- : subtract
* : mutiply
/ : divide
% : get remainders from divide
** : power
Notation:
1.f(x) = {1,2,3,4} means f(1)=1, f(2)=2, f(3)=3, f(4)=4.
2.cost = 1 means the function uses one operator.
So, please find all 24 functions of 4! with minimum of operations. That is,
f1(x)={1,2,3,4} f1(x)=x (cost = 0)
f2(x)={1,2,4,3} f2(x)=?
f3(x)={1,3,2,4} f3(x)=?
f4(x)={1,3,4,2} f4(x)=?
f5(x)={1,4,2,3} f5(x)=?
f6(x)={1,4,3,2} f6(x)=?
f7(x)={2,1,3,4} f7(x)=?
f8(x)={2,1,4,3} f8(x)=?
f9(x)={2,3,1,4} f9(x)=?
f10(x)={2,3,4,1} f10(x)=?
f11(x)={2,4,1,3} f11(x)=?
f12(x)={2,4,3,1} f12(x)=?
f13(x)={3,1,2,4} f13(x)=?
f14(x)={3,1,4,2} f14(x)=?
f15(x)={3,2,1,4} f15(x)=?
f16(x)={3,2,4,1} f16(x)=?
f17(x)={3,4,1,2} f17(x)=?
f18(x)={3,4,2,1} f18(x)=?
f19(x)={4,1,2,3} f19(x)=?
f20(x)={4,1,3,2} f20(x)=?
f21(x)={4,2,1,3} f21(x)=?
f22(x)={4,2,3,1} f22(x)=?
f23(x)={4,3,1,2} f23(x)=?
f24(x)={4,3,2,1} f24(x)=5-x (cost = 1)
Note:
1.it does not allow recursive function calls.
2.power operator costs 2 and others cost 1.
*3.divide operator gets the floor of the divide result. that is, 3/2 => 1
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.