@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 < n
Return 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]
2
The 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
the clodvestigator
videogame enjoyer. mathematics hobbyist and recovering physicist. software engineer. professional wonk. certified weird movie liker. top-ranked c++ hater. prophet of The Truth. space dandy and kill la kill propagandist. the walking embodiment of "not diagnosed, but somethings wrong". i like animals that wear cowboy hats.
I am not picky about names. Most people here call me catwin, clodboy, clodsire, or Caleb.
header is by @vaporeon_
"i regret ever allowing him here" ~aescling
he/him