Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,24 @@
fcn monkey_coconuts(sailors=5){
nuts,wakes:=sailors,List();
while(True){
n0:=nuts; wakes.clear();
foreach sailor in (sailors + 1){
portion, remainder := n0.divr(sailors);
wakes.append(T(n0, portion, remainder));
if(portion <= 0 or remainder != (sailor != sailors).toInt()){
nuts += 1;
break;
}
n0 = n0 - portion - remainder;
}
fallthrough{ break }
}
return(nuts, wakes)
}
foreach sailors in ([5..6]){
nuts, wake_stats := monkey_coconuts(sailors);
println("For %d sailors the initial nut count is %,d".fmt(sailors, nuts));
println("On each waking, the nut count, portion taken, and monkeys share are:\n ",
wake_stats.concat("\n "));
}

View file

@ -0,0 +1,16 @@
fcn total(n, nuts){
nuts *= n;
foreach k in (n){
if (nuts % (n-1)) return(0);
nuts += nuts / (n-1) + 1;
}
nuts;
}
println("sailers: original pile, final share");
foreach n,x in ([2..9],[1..]){
if(t := total(n, x)){
print("%d: %d\t%d\n".fmt(n, t, x));
break;
}
}