Sunday, September 1, 2013

My Solution to the Coconuts and Monkey Problem

This applies to the problem located here http://orion.math.iastate.edu/burkardt/puzzles/coconut_solution.html.  I guess I could have made the function recursive but I want to move onto other things.  This was done in java.

public class main {
public static void main(String[] args) {
// TODO Auto-generated method stub
float total = 0;
math_functions mf = new math_functions();
for(float x=20000 ; x>0 ; x--){
total = (mf.coconuts(mf.coconuts(mf.coconuts(mf.coconuts(mf.coconuts(mf.coconuts(x)))))));
if(total%1 == 0 && total > 0){
System.out.println("total left " + total + " starting coconuts " + (x));
//break;
}
}
}
public float coconuts(float x) { float total = (float)(4*((x/5)-.2)); if(total%1 != 0){ return 0; }else{ return total; } }

No comments:

Post a Comment