MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How do you plan to solve this problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117319] Re: How do you plan to solve this problem
  • From: Achilleas Lazarides <achilleas.lazarides at gmx.com>
  • Date: Tue, 15 Mar 2011 06:03:35 -0500 (EST)

Hi,

This isn't a very elegant way to go about it but, since nobody has answered, I will.

If you run the code below, and then execute
ops = {Times, Plus, Subtract, Divide}
nums = {2, 3, 4, 5, 7, 13, 14, 16, 17, 20, 22, 25, 32, 42}
ord = Range[Length@nums]
(*the first element is identity to simplify the logic later*)
oplist \
= {Identity}~Join~RandomChoice[ops, Length@nums - 1]

out = NestList[
   	takeMCstep[
     138, #\[LeftDoubleBracket]1\[RightDoubleBracket], #\
\[LeftDoubleBracket]2\[RightDoubleBracket], nums, ops] &,
   	{oplist, ord},
   	10000];

then you will (probably, you may need to run it a couple of times) get the answer, as demonstrated by

ev = Map[evalops[#\[LeftDoubleBracket]1\[RightDoubleBracket], #\
\[LeftDoubleBracket]2\[RightDoubleBracket], nums] &, out];
ev // Last // N
ev // ListPlot

I admit that I have not tried it on your problem (I wrote it, then forgot about it and now don't have much time to check whether it works with reals etc).

If you're still reading replies, let me know and I will explain how this works (it basically uses a Metropolis algorithm). It's probably not very transparent.

As I said before this isn't a hugely elegant solution, and also it is not deterministic. It's just the first thing that came to mind (this probably is not a compliment to my mind). There surely exist much better ways of doing it.

===========================================================

ClearAll[swap];
swap[lst_,{p1_,p2_}]:=ReplacePart[lst,
		{p1\[Rule]lst\[LeftDoubleBracket]p2\[RightDoubleBracket],p2\[Rule]lst\[LeftDoubleBracket]p1\[RightDoubleBracket]}]

ClearAll[evalops];
(*first element of opslst is Identity*)
evalops[opslst_,ord_,nums_]:=Module[
	{curval},
	curval=First@nums;
	Do[curval=opslst\[LeftDoubleBracket]p\[RightDoubleBracket][curval,nums\[LeftDoubleBracket]ord\[LeftDoubleBracket]p\[RightDoubleBracket]\[RightDoubleBracket]],
		{p,2,Length@nums}];
	curval]

ClearAll[randomizeOrder];
randomizeOrder[ordlst_]:=swap[ordlst,
	RandomInteger[
		{1,Length@ordlst},2]]

ClearAll[randomizeOps];
(*never touch the first element*)
randomizeOps[oplst_,allowedOps_]:=ReplacePart[oplst,
		{RandomInteger[{2,Length@oplst}]\[Rule]RandomChoice[ops]}]

ClearAll[takeMCstep];
takeMCstep[goal_,opslst_,ord_,nums_,allowedops_]:=Module[
	{curres,newres,newops,neword,p},
	curres=evalops[opslst,ord,nums];
	newops=randomizeOps[opslst,allowedops];
	neword=randomizeOrder[ord];
	newres=evalops[newops,neword,nums];

	Switch[Abs[newres-goal],
		0,{newops,neword},
		_,(p=Abs[curres-goal]/Abs[newres-goal];
			If[RandomReal[]<p,
				{newops,neword},
				{opslst,ord}])]]

====================================================================

On Mar11, 2011, at 10:32 AM, Herman Kuun wrote:

> Any ideas how to solve this problem?
>
> You are given a set of integers
> {2, 3, 4, 5, 7, 13, 14, 16, 17, 20, 22, 25, 32, 42}
> to produce a result of
> 117081295.59
>
> You only allowed to use the integer set of numbers.
> Each integer can only be used once.
> All integers must be used.
>
> What methodologies or functions best support investigating such a task?
>
> Best
> Herman


  • Prev by Date: Re: what's new in 8.0.1?
  • Next by Date: Re: Joining points of ListPlot
  • Previous by thread: How do you plan to solve this problem
  • Next by thread: Solve::ivar: xxx is not a valid variable. >>