@murz google's random number generator
@murz 5, because I ran a random number generator from 3-5 and it picked 5
@aschmitz vaporeon showed me a snippet of code from unix source that used the variable "gorp" and i thought it was funny so now i use it
@aschmitz I had no idea it was a word lol
@vaporeon_ never in production code lol
@vaporeon_ it's even worse than you think! javascript has what is effectively a preprocessing phase where it looks for every single value initialized as a var and initializes them, and then the interpreter runs on the code like you would expect
this means you can use a variable before it is declared if you declare it with var! real javascript code out in the wild actually does this!!!!
@vaporeon_ @aescling no clue i just think the idea of storing project versions on laserdisc funny
@aescling @vaporeon_ with let the algo ran the test cases ~700ms and with var it shaved ~100ms
@aescling @vaporeon_ ....it runs faster with this change
@soft PREACH
@vaporeon_ oooooh I could have done for (var min = Infinity, j = 1, res; j <= nums[i]; ++j) res = 1 + jump(nums, i + j, gorp), min = res < min ? res : min;
javascript variables declared with var and not block scoped, so min is available outside of the for loop teehee
@aescling @vaporeon_ I just ran it and what is here is correct
@vaporeon_ here is another hack with a "beautiful" one liner:
Problem Statement
You are given a 0-indexed array of integers nums of length n. You are initially positioned at nums[0].
Each element nums[i] represents the maximum length of a forward jump from index i. In other words, if you are at nums[i], you can jump to any nums[i + j] where:
0 <= j <= nums[i] andi + j < nReturn the minimum number of jumps to reach nums[n - 1]. The test cases are generated such that you can reach nums[n - 1].
Example
[2,3,1,1,4]2The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.Code
const jump = (nums, i = 0, gorp = {}) => {
if (i === nums.length - 1) return 0;
if (i > nums.length - 1 || nums[i] === 0) return Infinity;
if (gorp[i] !== undefined) return gorp[i];
let min = Infinity;
for (let j = 1, res; j <= nums[i]; ++j) res = 1 + jump(nums, i + j, gorp), min = res < min ? res : min;
return gorp[i] = min;
};
@coriander @wohali I was gonna write this comment too, lol
@onfy whoa new pfp
@vaporeon_ you store all versions of your software on laserdisc
secret do not open
@coriander break stuff
kept afloat by big ideas.
you can call me Caleb or Clodsire. i also go by clodboy and catwin. i am not picky about names (unless its one amy made up)
videogame enjoyer. mathematics hobbyist and recovering physicist. software engineer. professional wonk. prophet of The Truth. the walking embodiment of "not diagnosed, but somethings wrong". i like animals that wear cowboy hats.
number of fat cock awards received: 56
pfp is by @The_T
header is by @vaporeon_
"i regret ever allowing him here" ~aescling
"oh you're one of those weird movie likers" ~Ti
"i know your taste in movies well enough to discount your opinion" ~globin
"caleb is the only person on this websites who truly understands what the report button is for: 'i don't like this post'" ~holly
30+
straight
he/him