Last active
April 18, 2019 22:32
-
-
Save wmjd/da6eeb32c99ddcff74541c185d9f6134 to your computer and use it in GitHub Desktop.
Revisions
-
wmjd revised this gist
Apr 18, 2019 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -62,13 +62,13 @@ function isIncreasingIfRemoveOne(next, prev, dec){ console.log(isIncreasingIfRemoveOne(1,0,0)); //current favorite : ) const isIncIfRemOne = (next, prev, dec) => (dec > 1) ? "reject" : (arr.length === next) ? "accept" : (arr[next] < arr[prev]) ? isIncIfRemOne(next+1, prev, dec+1) : isIncIfRemOne(next+1, next, dec) ; console.log(isIncIfRemOne(1,0,0)); -
wmjd revised this gist
Apr 18, 2019 . 1 changed file with 8 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -62,10 +62,13 @@ function isIncreasingIfRemoveOne(next, prev, dec){ console.log(isIncreasingIfRemoveOne(1,0,0)); //current favorite : ) const v4 = (n, p, d) => (d > 1) ? "reject" : (arr.length === n) ? "accept" : (arr[n] < arr[p]) ? v4(n+1,p,d+1) : v4(n+1,n,d) ; console.log(v5(1,0,0)); -
wmjd revised this gist
Apr 18, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -65,7 +65,7 @@ console.log(isIncreasingIfRemoveOne(1,0,0)); const v5 = (n, p, d) => (d > 1) ? "reject" : (arr.length === n) ? "accept" : (arr[n] < arr[p]) ? v5(n+1,p,d+1) : v5(n+1,n,d); console.log(v5(1,0,0)); -
wmjd revised this gist
Apr 18, 2019 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -62,10 +62,10 @@ function isIncreasingIfRemoveOne(next, prev, dec){ console.log(isIncreasingIfRemoveOne(1,0,0)); //current favorite : ) const v5 = (n, p, d) => (d > 1) ? "reject" : (arr.length === n) ? "accept" : (arr[n] < arr[p]) ? v5(n+1,p,d+1) : v5(n+1,n,d); console.log(v5(1,0,0)); -
wmjd revised this gist
Apr 18, 2019 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -59,4 +59,13 @@ function isIncreasingIfRemoveOne(next, prev, dec){ } } console.log(isIncreasingIfRemoveOne(1,0,0)); //current favorite : ) const v4 = (n, p, d) => (d > 1) ? "reject" : (arr.length === n) ? "accept" : (arr[n] < arr[p]) ? v4(n+1,p,d+1) : v4(n+1,n,d); console.log(v4(1,0,0)); -
wmjd revised this gist
Apr 18, 2019 . 1 changed file with 23 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,4 +37,26 @@ const bar = (i, dec) => (i === arr.length) ? "succeed" : bar(i+1, (arr[i+1] < arr[i]) ? dec+1 : dec); console.log(bar(0,0)); /* v4 this is a soln to a slightly different problem. for example, [0,1,2,0,1] only decreases once but removing one elt won't make strictly increasing */ function isIncreasingIfRemoveOne(next, prev, dec){ if(dec > 1){ console.log(next,prev,dec); return "reject" ; } if(next === arr.length){ return "accept" ; } if(arr[next] < arr[prev]){ return isIncreasingIfRemoveOne(next+1, prev, dec+1) ; }else{ return isIncreasingIfRemoveOne(next+1, next, dec) ; } } console.log(isIncreasingIfRemoveOne(1,0,0)); -
wmjd revised this gist
Apr 18, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ //see if sequence of nums is in increasing order, but seq is allowed to decrease once. //some shared stuff first: var arr = [0,1,2,3,5,4,5,7]; //currently these two functions are only used in v1 (v2-3 prints value of entire function) -
wmjd revised this gist
Apr 18, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ //see if sequence of nums are in increasing order, but seq is allowed to decrease once. //some shared stuff first: var arr = [0,1,2,3,5,4,5,7]; //currently these two functions are only used in v1 (v2-3 prints value of entire function) -
wmjd revised this gist
Apr 18, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ //see if sequence of nums are in increasing order, but it is allowed to decrease once. //some shared stuff first: var arr = [0,1,2,3,5,4,5,7]; //currently these two functions are only used in v1 (v2-3 prints value of entire function) -
wmjd revised this gist
Apr 18, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ //some shared stuff first: var arr = [0,1,2,3,5,4,5,7]; //currently these two functions are only used in v1 (v2-3 prints value of entire function) const s = () => console.log("success"); const f = () => console.log("failure"); -
wmjd revised this gist
Apr 18, 2019 . 1 changed file with 18 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,32 +5,35 @@ const s = () => console.log("success"); const f = () => console.log("failure"); //v1 imperative style function exeImperative(){ let dec = 0; for(var i = 0; i < arr.length -1; i++){ if(arr[i+1] < arr[i]){ if(++dec > 1){break ;} } } if(i === arr.length -1){ s(); }else{ f(); } } exeImperative(); //v2 transformed to functional style: recursion, no (re)assignments const foo = function(i, dec){ if(dec > 1){return "fail"} if(i === arr.length){return "succeed"} if(arr[i+1]<arr[i]){return foo(i+1, dec+1)} else{return foo(i+1, dec)} }; console.log(foo(0,0)); //v3 transformed to single statement : ) const bar = (i, dec) => (dec > 1) ? "fail" : (i === arr.length) ? "succeed" : bar(i+1, (arr[i+1] < arr[i]) ? dec+1 : dec); console.log(bar(0,0)); -
wmjd revised this gist
Apr 18, 2019 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,19 +18,19 @@ if(i === arr.length -1){ } //v2 transformed to functional style: recursion, no (re)assignments const foo = function(i, dec){ if(dec > 1){return f()} if(i === arr.length){return s()} if(arr[i+1]<arr[i]){return foo(i+1, dec+1)} else{return foo(i+1, dec)} }; foo_intermediate(0,0); //v3 transformed to single statement : ) const bar = (i, dec) => (dec > 1) ? f() : (i === arr.length) ? s() : bar(i+1, (arr[i+1] < arr[i]) ? dec+1 : dec); bar(0,0); -
wmjd revised this gist
Apr 18, 2019 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,8 +8,7 @@ const f = () => console.log("failure"); let dec = 0; for(var i = 0; i < arr.length -1; i++){ if(arr[i+1] < arr[i]){ if(++dec > 1){break ;} } } if(i === arr.length -1){ -
wmjd revised this gist
Apr 18, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ if(i === arr.length -1){ f(); } //v2 transformed to functional style: recursion, no (re)assignments const foo_intermediate = function(i, dec){ if(dec > 1){return f()} if(i === arr.length){return s()} -
wmjd revised this gist
Apr 18, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,7 +28,7 @@ const foo_intermediate = function(i, dec){ foo_intermediate(0,0); //v3 transformed to single statement : ) const foo = (i, dec) => (dec > 1) ? f() : (i === arr.length) ? s() : -
wmjd revised this gist
Apr 18, 2019 . 1 changed file with 20 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,25 +4,7 @@ var arr = [0,1,2,3,5,4,5,7]; const s = () => console.log("success"); const f = () => console.log("failure"); //v1 imperative style let dec = 0; for(var i = 0; i < arr.length -1; i++){ if(arr[i+1] < arr[i]){ @@ -34,4 +16,22 @@ if(i === arr.length -1){ s(); }else{ f(); } //v2 transformed to functional style: recursion, no assignments const foo_intermediate = function(i, dec){ if(dec > 1){return f()} if(i === arr.length){return s()} if(arr[i+1]<[i]){return foo(i+1, dec+1)} else{return foo(i+1, dec)} }; foo_intermediate(0,0); //v3 transformed to single expression : ) const foo = (i, dec) => (dec > 1) ? f() : (i === arr.length) ? s() : foo(i+1, (arr[i+1] < arr[i]) ? dec+1 : dec); foo(0,0); -
wmjd revised this gist
Apr 18, 2019 . No changes.There are no files selected for viewing
-
wmjd created this gist
Apr 18, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ //some shared stuff first: var arr = [0,1,2,3,5,4,5,7]; const s = () => console.log("success"); const f = () => console.log("failure"); ///////////////////////////////////////////////// const foo = (i, dec) => (dec > 1) ? f() : (i === arr.length) ? s() : foo(i+1, (arr[i+1] < arr[i]) ? dec+1 : dec); foo(0,0); ///////////////////////////////////////////////// const foo_intermediate = function(i, dec){ if(dec > 1){return f()} if(i === arr.length){return s()} if(arr[i+1]<[i]){return foo(i+1, dec+1)} else{return foo(i+1, dec)} }; foo_intermediate(0,0); ///////////////////////////////////////////////// let dec = 0; for(var i = 0; i < arr.length -1; i++){ if(arr[i+1] < arr[i]){ dec++; if(dec > 1){break ;} } } if(i === arr.length -1){ s(); }else{ f(); }