Skip to content

Instantly share code, notes, and snippets.

@Windows81
Last active February 29, 2020 20:12
Show Gist options
  • Save Windows81/db51ce25ffcece8a0b6d34eac6c945aa to your computer and use it in GitHub Desktop.
Save Windows81/db51ce25ffcece8a0b6d34eac6c945aa to your computer and use it in GitHub Desktop.
Function that solves the Water Jug Riddle
function f(T,t,cn=0,l=[]){if(!s.includes(ch(t))){console.log(cn,t);l.push(t);s.push(ch(t));for(var c=0;c<T.length;c++)for(var C=0;C<T.length;C++){if(C==c)continue;var n=t.slice(0);var d=Math.min(T[c]-n[c],n[C]);n[C]-=d;n[c]+=d;f(T,n,cn+1,l)}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment