Open Side Menu Go to the Top
Register
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

11-01-2016 , 02:00 PM
Quote:
Originally Posted by daveT
Simple? Probably not, lol.

I'm pretty sure this can be solved with linear algebra, which, don't hold me to this, would make it around nlogn. As I understand it, there is no way to do matrix calculations any faster than that, but Linear Algebra is my worst math and matrices are my worst data structures.

The point of the sort is to create a seed of values, and prevent you from checking how each value works. The problem is that, no matter what you try, you can end up with some brute force at the end, given some combination of values.
Are we actually talking about the same problem?

https://codefights.com/challenge/Qjts7cukDvYpDW4Bc

What size would that matrix be anyway, and what exactly is n in your notation?

Going by the comments the best solutions seem to be O(a.len * (b.len-a.len)) runtime, I guess that's just some clever variation of the stuff i posted.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 02:48 PM
Cleaned it up a bit, this is the best i can do with that approach:
Spoiler:
Code:
static int closestSequence2(int[] a, int[] b) {
  int[] cache = new int[b.length-a.length+1];
  for(int i=a.length-1;i>=0;i--){
    int r = Integer.MAX_VALUE;
    for(int j=cache.length-1;j>=0;j--){
      r=Math.min(Math.abs(a[i]-b[j+i]) + cache[j], r);
      cache[j]=r;
    }
  }
  return cache[0];    
}

This is O(a.len * (b.len-a.len)) runtime and O(b.len-a.len) memory.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 03:07 PM
I'm only considering B as N in the notation. The equation for the matrix would probably be M * B = C where size(M) = AxB. Once again, not my most awesome subject.

The runtime they call the best solution doesn't even make sense. If len(a) = len(b), then you have O(a * 0), which I'm pretty sure isn't a valid runtime.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 03:11 PM
If your matrix is size AxB then filling it is already higher complexity than the entire solution posted above, no?

Runtime is technically O(a * (b-a+1)) i guess

Spoiler:
10/10
All tests passed
Sample tests: 5/5
Hidden tests: 5/5
Score: 300/300
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 04:09 PM
The runtime, once again, makes no sense. Think of these situations:

a.len = b.len; a * (b - a + 1) = a
b.len = 1; a * (1 - a + 1) => do fuzzy math by dropping the constants => a * a.

The above is saying this:

a = [1]
b = [1, 2, 3, 4, 5, 6, 7, 8]

is slower than this:

a = [1, 2, 3, 4, 5, 6]
b = [1, 2, 3, 4, 5, 6, 7, 8]

I think this may be a variation on the Longest Common Sequence Problem: https://en.wikipedia.org/wiki/Longes...quence_problem

I never heard of LCS before, but I guess it is a major thing.

Another part of me thinks there is a bit of knapsack going on here as well. That can be optimized using bisection search.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 04:11 PM
Quote:
Originally Posted by clowntable
I'm drinking the Elixir coolaid and it tastes fantastic (currently working through the exercism.io stuff). Don't know why it took me so long. Pipe operator is elite (hi Closure folks) and I can finally use some of the old Prolog magic. The design of the web framework I'm learning simultaneously (Phoenix) aligns very well with the way I think so that's nice. Performance seems to be excellent as well...yay?!

I very much feel like this is it. New language for all side projects that don't strictly require another one (like when working with a game engine etc.).
I recently built an internal tool with Elixir/Phoenix and came away with similar impressions.

Really fun and fast language and framework. You can see the rails inspiration but it feels like the combination of the language and the framework force developers into better design

I ran into some trouble with authentication because it didn't seem like there was a fully featured library that isn't oauth, but the ecosystem seemed pretty great other than that.

As we build more microseconds I'm definitely going to push to implement in elixir where we can.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 04:23 PM
Quote:
Originally Posted by daveT
The above is saying this:

a = [1]
b = [1, 2, 3, 4, 5, 6, 7, 8]

is slower than this:

a = [1, 2, 3, 4, 5, 6]
b = [1, 2, 3, 4, 5, 6, 7, 8]
Huh?

Case A: 1*(8-1+1) = 9
Case B: 6 *(8-6+1) = 18

I'm a bit confused what we are arguing though, the code is posted right above and it's only a bunch of lines. Are you saying the code doesn't always find the correct answer, or that the runtime is different than stated?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 04:38 PM
The initial claim is this:

Quote:
Originally Posted by suzzer99
Interesting looking coding challenge that showed up on my FB feed with the clickbait title "94% of coders can't do this w/o using brute force":
Unless I'm grossly misunderstanding your solution... which apparently is a pattern over these past 2 days.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 04:48 PM
Yeah, this isn't a brute force solution to the problem. Brute forcing would be to generate all possible b' subsequences (that's choose(b, a) subsequences) and evaluating every single one.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 11:56 PM
I'm ****ing done with sublime. 45 minutes of trying to get eslint working, googling - weird answers, config files all over the place, global vs. local. This **** should just work like it does with Atom, Webstorm or VS Code.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2016 , 12:04 AM
wat? use gulp. I don't do sublime build anything, that's not what its good for.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2016 , 01:20 AM
Well now I'm back to sublime. No way to open multiple folders in one window in VS Code - total dealbreaker. https://visualstudio.uservoice.com/f...=1&per_page=20
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2016 , 01:20 AM
Quote:
Originally Posted by Grue
wat? use gulp. I don't do sublime build anything, that's not what its good for.
Gulp is better for real-time linting/hinting as you type than Sublime?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2016 , 09:27 AM
I use sublime but don't use any its build stuff, I have gulp watch -> lint for on the fly linting with notifying. Simplified version:

Code:
let file;

gulp.task('watch', () => {
	gulp.watch(['./src/frontend-scripts/**/*.js*', './routes/**/*.js', './__test__/*.js'], e => {
		file = `./${e.path.split('/Users/xxx/repo/')[1]}`;
		gulp.start('lint');
	});
});

gulp.task('lint', () => {
	return gulp.src(file)
		.pipe(eslint())
		.pipe(plumber())
		.pipe(eslint.format())
		.pipe(eslint.failAfterError())
		.on('error', () => {
			notifier.notify({title: 'ESLint Error', message: ' '});
		});
});
Works pretty well. I also have a lint-all task which runs on startup.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2016 , 11:50 AM
That's not the same as in-editor linting though.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2016 , 01:15 PM
fair enough but using node-notify it pops up when there's issues and I just glance at other screen
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2016 , 02:09 PM
Still not the same, especially when 90% of the time you're working on a laptop with a 13% screen.

Now my sublime jshint is broken after all the ****ing around with es lint. AWESOME. Once I get this working I'm never touching it again. If I need es lint I will use a different editor.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2016 , 02:24 PM
Quote:
Originally Posted by suzzer99
Still not the same, especially when 90% of the time you're working on a laptop with a 13% screen.
noob
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2016 , 02:32 PM
I have two thunderbolts on my desk in my bedroom. I just prefer to hang out in the living room, or in a coffee shop - unless I really need the screen real estate for some task.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2016 , 03:15 PM
Non ultrawide peasants ITT.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2016 , 03:30 PM
I'm picturing a 13% screen as a screen where it's like a giant bezel with a tiny monitor. Like those toy kid computers they used to make (maybe still do for all I know)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2016 , 04:27 PM
Heh - 13" obviously.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2016 , 05:31 PM
Quote:
Originally Posted by Grue
Non ultrawide peasants ITT.
80 chars FTW
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2016 , 09:52 PM
esh no IDE for js in 2016? do you type out your imports you pleb
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-02-2016 , 10:18 PM
need some quick help. im using juypter (iPython) and i have text file that i used re to split into words, they are all in a list now. i need to come up with a data frame (i guess?) where it has each word and the corresponding frequency. thing is i cant use iteration. i can use numpy or pandas to do iteration for me, but i cant do iteration myself.

im thinking about using "apply" but wtf i have no idea what im doing... i hate python. i suck at it. any ideas? lol
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote

      
m