Open Side Menu Go to the Top

10-29-2016 , 09:47 PM
Dang just realized that would get us the shortest distance between any of the subsequences or a. Wonder if it can be adjusted for the problem, but it does make me question if there isn't a better solution.

Sent from my SM-G900R4 using Tapatalk
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
10-30-2016 , 02:16 AM
Quote:
Originally Posted by Prickly Pear
I thought about greedy solutions for a while before realizing its a weird twist on the https://en.wikipedia.org/wiki/Edit_distance which has dynamic programming solutions.
I don't think this can be right. The big O suggest brute force (disregarding the memoization).

So, if I understand this question correctly, lol, then I think I have a solution that doesn't require memoization:

Spoiler:
Order both lists, then start at A[0].

Bisection search on B:
starting at the beginning, find the difference. Go to the end, find the difference, then middle, bisect until you have no movement on epsilon, save epsilon in a list.

Go to A[1]:

Bisection on B where you left off on the last iteration + 1 index. Bisect as described above.

Repeat until A is complete then add up all the numbers in the epsilon list.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-30-2016 , 02:30 AM
Quote:
Originally Posted by tomatoe
if anyone here is solid with linux and ruby ill pay you to help me get a ruby gem installed now which is failing. PM me please
what's the gem?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-30-2016 , 06:19 AM
Quote:
Originally Posted by Wolfram
Convenience (working on the code from any machine) and for cloud backup in case my local hdd crashes or I want to re-install my OS and can't be bothered with local backups.

I don't have my own server to store this on.
Gitlab also has free private repositories:
https://about.gitlab.com/gitlab-com/
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-30-2016 , 11:02 AM
Quote:
Originally Posted by daveT
I don't think this can be right. The big O suggest brute force (disregarding the memoization).

So, if I understand this question correctly, lol, then I think I have a solution that doesn't require memoization:

Order both lists...
You can't reorder the lists. You are looking for the ordered subsequence of the longer list and comparing that to the (original, ordered) smaller sequence.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-30-2016 , 12:57 PM
I cry uncle on it. I think the Levenshtein distance strategy is probably the correct way then, but alas, this one is above my head. Sorry.

I'd like to know who the 6% are the post is referring to.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-30-2016 , 03:25 PM
I'm sure gaming mouse will stop by with a 1 liner solution any minute.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-30-2016 , 05:28 PM
Regarding that distance problem, pretty sure you can do this in O(a.len*b.len).

Spoiler:

Basic idea is that you need to store the minimum distance for each possible index combination in the a and b sequences. Basically if you are at position idx_a in a and idx_b in b, what's the minimum score for the remaining sequences, store that value in cache[idx_a][idx_b].

1) Start building that cache with the last position idx_a = a.length, we just iterate over b and have a trivial abs to calculate the remaining score.
2) Then go ahead with idx_a = a.length-1, i think this is again just O(b.length), since we only need to iterate over the b values and add the already cached remainder.
3) Repeat 2) until you reach idx_a=1

Seems like O(a.len*b.len) overall.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-30-2016 , 08:39 PM
Not exactly pretty, but this works in Java:
Spoiler:
Code:
static int closestSequence2(int[] a, int[] b) {
  int[][] cache = new int[a.length+1][b.length+1];
  for(int i=0;i<cache.length-1;i++)
    Arrays.fill(cache[i],10000000);
    
  for(int i=a.length-1;i>=0;i--)
    for(int j=b.length-1;j>=i;j--)
      cache[i][j]=Math.min(Math.abs(a[i]-b[j]) + cache[i+1][j+1], cache[i][j+1]);
  return cache[0][0];    
}


Looks like we don't actually need the O(a*b) cache, adjusting to O(b) memory seems pretty straightforward. Too lazy now though

Last edited by plexiq; 10-30-2016 at 09:04 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-30-2016 , 10:22 PM
Quote:
Originally Posted by suzzer99
casper went several years without any update to their software or site. Looks like they have finally updated so I guess it's back in business? The great thing about casper is that it played nice with phantomjs, which protractor never did (even though it sort of claimed to). And the great thing about phantom is it's headlessness - which allows it to run on our linux test servers. We had to go through all kinds of hoops to test using chrome on a windows server as part of our CI/CD flow.

Selenium is more brute force. But it's battle tested and works pretty well.
There is only one issue I've found with casperjs. You can listen in on the original requests (the one's being issued by the url you're currently on) but you can't extract the response body. There was a huge long github issue on just that and it seems that populating the response body caused all sorts of errors to get thrown. From what I can tell, they were trying to populate the response body regardless of what kind of request it is. So that was the case for images, svg, w/e. In reality, the only time you would actually want the response body is in the case of retrieving json from the server. We actually have a guy at work that is pretty knowledgeable in low level languages so I think he might be able to patch it so that, in the case of setting the header

Code:
 Content-Type : Application/json
we would be able to read the response body.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-31-2016 , 06:18 PM
Is there any reason not to use Bandwidth instead of Twilio? It sounds like Twilio uses Bandwidth behind the scenes anyway, and charges a 50% premium. Is it just that Twilio has the Silicon Valley hype?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 01:17 AM
Quote:
Remote Contract/ React, Redux, Flux, Yarn, Elm (Not HBO but similar)
title of email I got today. wtg with requiring yarn knowledge 2 weeks after it was released. jfc.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 02:49 AM
As I've heard it: someone says "oh, and we might use yarn in the future so it would be nice if they knew that" and the clueless guy who actually writes the job descriptions just throws everything as a requirement.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 05:48 AM
plexiq, can you make this Fast?

Code:
		static double[] Slow(double[] pb, double[] pc)
		{
			int n = pb.Length;
			double[] ev = new double[n];

			for (int a = 0; a < n; a++)
			{
				for (int b = 0; b < n; b++)
				{
					for (int c = 0; c < n; c++)
					{
						if (a == b || a == c || b == c) continue;
						if (a > b && a > c) ev[a] += pb[b] * pc[c];
						if (a < b || a < c) ev[a] -= pb[b] * pc[c];
					}
				}
			}

			return ev;
		}
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 06:34 AM
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.).

Last edited by clowntable; 11-01-2016 at 06:43 AM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 06:38 AM
@skario
I think this should be possible in O(n²) instead of the current O(n³). How large is n in practice?

Also, what game is this for? Doesn't look like poker
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 07:30 AM
Quote:
Originally Posted by plexiq
@skario
I think this should be possible in O(n²) instead of the current O(n³). How large is n in practice?

Also, what game is this for? Doesn't look like poker
O(n) and poker .
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 07:42 AM
Like, 1-card poker? How are your p's independent otherwise?

I know O(n) is possible for 2 ranges with card removal, but this looks like a 3 player evaluation without card removal? O(n²) definitely works, do you have this with O(n) already?

Edit: Ahh, i think i have it for O(n) too - give me a minute.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 08:13 AM
There you go, O(n).

Code:
  static double[] cumulative(double[] d){
    double[] r = d.clone();
    for(int i=1;i<r.length;i++)
      r[i]+=r[i-1];
    return r;
  }
  
  static double[] fast(double[] pb, double[] pc){
    int n = pb.length;
    double[] wmax = new double[n];
    double[] wmin = new double[n];
    
    double[] pcc = cumulative(pc);
    double[] pbc = cumulative(pb);
    
    for (int i = 1; i < n; i++){  
      wmax[i]+=pb[i]*pcc[i-1];
      wmax[i]+=pc[i]*pbc[i-1];
    }
    for (int i = 0; i < n-1; i++){  
      wmin[i]+=pb[i]*(pcc[n-1]-pcc[i]);
      wmin[i]+=pc[i]*(pbc[n-1]-pbc[i]);
    }
    
    double[] wmaxc = cumulative(wmax);
    double wtotal = wmaxc[n-1];
    
    double[] ev = new double[n];
    for(int a=0;a<n;a++){
      if(a>0)
        ev[a]+=(wmaxc[a-1]);
      if(a<n-1)
        ev[a]-=(wtotal-wmaxc[a])*(1.0-wmin[a]/(wtotal-wmaxc[a]));
    }
    
    return ev;
  }
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 08:40 AM
Quote:
Originally Posted by plexiq
Regarding that distance problem, pretty sure you can do this in O(a.len*b.len).

Spoiler:

Basic idea is that you need to store the minimum distance for each possible index combination in the a and b sequences. Basically if you are at position idx_a in a and idx_b in b, what's the minimum score for the remaining sequences, store that value in cache[idx_a][idx_b].

1) Start building that cache with the last position idx_a = a.length, we just iterate over b and have a trivial abs to calculate the remaining score.
2) Then go ahead with idx_a = a.length-1, i think this is again just O(b.length), since we only need to iterate over the b values and add the already cached remainder.
3) Repeat 2) until you reach idx_a=1

Seems like O(a.len*b.len) overall.
The post asked for something that isn't brute-force. I've thought of it more, and the best I can come up with is nlog(n) amortized, (n^2) worst case.

Spoiler:
As with the previous idea, start by sorting B, then convert to set, bisection search over A until you minimize epsilon >> 0.

Take the results from the bisection and store it in an array of candidates (C).

Scan over original B, checking at B.indexOf(C[0]) < B.indexOf(C[1]) < B.indexOf(C[n]).

If any of the checks are false, redo the bisection with a new lower bound, starting at the offending element of C. Check the indices of the new candidates on B.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 08:48 AM
Brute forcing all b' candidates has a complexity of choose(b.len, a.len), the (n^2) i posted is a long way from that

I honestly don't see where you are going w/ the sort since you need to keep the initial ordering fixed. Can you post a simple implementation that passes on the challenge site?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 08:54 AM
Well done, you are the second to get it (and I asked some smart guys).
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 09:32 AM
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 have no idea what any of this means but in a similar spirit, learning Angular 2 forced me into learning RxJS and it's great. Observables ftw.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 12:48 PM
Quote:
Originally Posted by Grue
title of email I got today. wtg with requiring yarn knowledge 2 weeks after it was released. jfc.
my favorite was a junior dev position that required 5 years of java 8 experience.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
11-01-2016 , 01:51 PM
Quote:
Originally Posted by plexiq
Brute forcing all b' candidates has a complexity of choose(b.len, a.len), the (n^2) i posted is a long way from that

I honestly don't see where you are going w/ the sort since you need to keep the initial ordering fixed. Can you post a simple implementation that passes on the challenge site?
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.

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.).
Sounds really fun. I've been meaning to learn some Erlang at some point (well... been asked to learn Erlang many times, lol). Just not in the mood to learn anything newfangled or unpopular these days since I know too many already, but I'm glad Elixer works well with a Prolog mind.

How do pipe operators convert to closures in an immutable language?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m