West of Loathing is a computer duty playing video game by Asymmetric Publications. It has actually a mystical American Wild West setting, but much more importantly it additionally has really clever, funny writing. That cleverness that the writing additionally extends right into some that the game’s puzzles. For example, yes a mathematics puzzle in West that Loathing that looks choose this: rotate the #3 bolt. <2>Turn the #5 bolt. <3> turn the #7 bolt. <4> leaving it alone because that now" />

The three bolts you can manipulate add different amounts of weight. The first option (the #3 bolt) to add 411 lbs., the second option (the #5 bolt) adds 295 lbs., and also the last option (the #7 bolt) add to 161 lbs. If you add up enough weight the it over 3200 lbs. Then it resets come zero, and also crucially you can not undo weights girlfriend have included nor deserve to you reset to zero on your own. This is a disincentive come randomly guessing to try and discover a solution because working your way through guesses is an extremely tedious. Instead I tabbed the end of the game and wrote a quick script to reach the solution.

You are watching: West of loathing soup

The very first step i take is to number out what i’m trying come solve. Luckily, that component is straightforward.

(x * 411) + (y * 295) + (z * 161) = 3200

In addressing for x, y, and z the is likewise helpful to have an idea the the possible range that variables. 3200 split by 161 is around 19.8. Therefore we know that the feasible answers for x, y, and z are in between 0 and 19, with the lower end of the spectrum being an ext likely. Finally, us can likewise observe the x and also y have to add up come a number divisible through 5. We understand that since it is impossible to come at the worth of 3200 if the #3 and also #7 bolts are an unified in together a means that the value of the weight ends with a digit choose 3. There room other monitorings that might be made around the problem, but I felt prefer that was sufficient information to handle the problem.

When composing a role that performs a many of different things, I an initial like come articulate in level English what ns trying to execute so i don’t acquire lost in the weeds. This is what I come up with:

take a sum of x and also z that is divisible by 5. Advice all possible permutations of that sum to x and also z (5x, 0z), (4x, 1z), (3x, 2z), etc. Because that each instance, carry out the (x411) + (y295) + (z*161) formula in a loop wherein y is incrementing. If that is equal to 3200 publish the worths of x y and z.

When described that way, writing a role doesn’t seem too complicated.

See more: Space And Rocket Auto Sales, Cars For Sale In Meridianville, Al

You have actually a parameter that is the amount of x and y. Over there is a loop the assigns different values come x and also z. Nested in the loop is secondary loop that increments y. There is an if problem that executes when the value of the formula is same to 3200.

With every one of that in psychic this is what I come up with:

function solveProblem(xzSum) { because that (let i=xzSum; i >= 0; i--) { allow x = i; allow z = xzSum - i; for (let j=0; j
Sure enough, if you run this you get this output:

The answer is: 4 2 6

And if you dual check the on a calculator, the math checks out. This is a brute pressure solution to fixing the problem, and there room some inefficiencies involved. Because that example, in the second loop i let it operation 11 times through the reasoning that 295*10.8 is roughly equal come 3200. Yet that method there will certainly be lot of of instances that checking services that plainly exceed scope. If this to be a more complex problem that involved assessing a lot larger selection for the possibility an are that would be a problem, and also I would think an ext carefully about what i’m trying come evaluate. Yet for detect the solution to a puzzle with a reasonably small selection of number to evaluate because that a video game that ns was looking front to getting ago to, this was method that i was happy come live with!