Open Side Menu Go to the Top

01-31-2015 , 05:26 PM
Well this problem was in JavaScript, which our candidate was supposed to be an expert in. In JS creating a 2D array (which I believe is actually a 1D array of 1D arrays under the covers) is super simple.

Let's say you want to populate each element of the n x n grid with a random integer from 1 to the maximum number of cells. Without optimizing for anything but clarity:

Code:
var n=20;

var my2dArray = [];

for (i=0; i<n; i++) {

  my2dArray[i] = [];

  for (j=0; j<n; j++) {
    my2dArray[i][j] = Math.ceil(Math.random() * (n*n));
  }
}
The random part is where it gets a little tricky. And then it gets really tricky if you demand that the random numbers be unique within the grid. But like i said we've had people get stuck just trying to conceptually create a 2d array that represents a square grid.

The last guy who got stuck creating the grid actually got the random number part. Maybe he just somehow never worked with a 2d array? I guess creating an array from scratch is a fairly rare task for a front-end JS dev working in frameworks?

Last edited by suzzer99; 01-31-2015 at 05:40 PM.
** 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 **
01-31-2015 , 05:28 PM
Jfc this thread makes me want to get a programming job ASAP.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-31-2015 , 05:44 PM
Starting to feel like we learned pretty much all the core things of programming in one semester, and now the others will focus on extrapolating OOP awesomeness into interesting ways or something. Cuz that's about as simple as it is in cpp. Don't get the fuss.

Last edited by Anais; 01-31-2015 at 05:44 PM. Reason: Which I guess is the whole point
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-31-2015 , 06:08 PM
Code:
fb = {3: "fizz", 5: "buzz"}

def make_fizz(x):
    ans = ''.join([k[1] for k in fb.items() if x % k[0] == 0])
    if ans == '':
        return str(x)
    else:
        return ans


def recur(s, e, ans = []):
    if s == e:
        return ans
    else:
        ans.append(make_fizz(s))
        return recur(s = s + 1, e = e, ans = ans)
                 
def fizz_buzz(s, e):
    ans = recur(s, e + 1)
    for i in ans:
        print(i)
       
fizz_buzz(1, 100)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-31-2015 , 06:18 PM
Quote:
Originally Posted by adios
Fair enough.



Seems to me, FWIW, that you have a "big picture" idea and you want to refine it to the point where you can feel confident in proceeding with code development. If so, this is more in the realm of developing an architecture in my view. For instance you mentioned multi-threading in another post. How do you know you need that? Maybe multi-processing would be better? Could you possibly model algorithm's in Python and then implement them in C++? How will data flow through the system in an efficient manner? Maybe some off the shelf software could be used. I am just throwing out things to consider FWIW. Akin to architecting what the stream and platform providers did.

I don't think you are out to rip anyone off.
yeah, that's pretty close to being on the mark. i don't know maybe multiprocessing would be better, i have no idea.

i'm absolutely dog**** with python so yes you could do it but no i probably couldn't. the problem i've always had with python is that it's so easy i'm like "oh yeah i know this, this is easy" until you actually run into some code that's tricky, at which point i go "jesus, i suck, i should actually learn python." then i go out and learn just enough to figure out my problem, and then i'm back to thinking "oh yeah i totally know python ****'s easy"
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-31-2015 , 06:37 PM
Code:
#include <iostream>
using namespace std;
char * FizzStr     = "Fizz";
char * BizzStr     = "Bizz";
char * FizzBizzStr = "FizzBizz";
char * FizzBizzData[] = {
   "",
   "1",  "2", FizzStr, "4", BizzStr, FizzStr, "7", "8", FizzStr, BizzStr,"11", FizzStr,"13","14", FizzBizzStr,
   "16","17", FizzStr,"19", BizzStr, FizzStr,"22","23", FizzStr, BizzStr,"26", FizzStr,"28","29", FizzBizzStr,
   "31","32", FizzStr,"34", BizzStr, FizzStr,"37","38", FizzStr, BizzStr,"41", FizzStr,"43","44", FizzBizzStr,
   "46","47", FizzStr,"49", BizzStr, FizzStr,"52","53", FizzStr, BizzStr,"56", FizzStr,"58","59", FizzBizzStr,
   "61","62", FizzStr,"64", BizzStr, FizzStr,"67","68", FizzStr, BizzStr,"71", FizzStr,"73","74", FizzBizzStr,
   "76","77", FizzStr,"79", BizzStr, FizzStr,"82","83", FizzStr, BizzStr,"86", FizzStr,"88","89", FizzBizzStr,
   "91","92", FizzStr,"94", BizzStr, FizzStr,"97","98", FizzStr, BizzStr };

int main() {
	for (int i = 1; i<=100; i++ ) {
		cout << FizzBizzData[i] << endl;
	}
	return 0;
}
I think this solution is the fastest execution wise I've seen in this thread. Am I cheating? To be honest, if I asked someone to do this and they came up with a solution like this I'd probably hire them.

Last edited by adios; 01-31-2015 at 06:59 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-31-2015 , 06:44 PM
Quote:
Originally Posted by Fubster
yeah, that's pretty close to being on the mark. i don't know maybe multiprocessing would be better, i have no idea.

i'm absolutely dog**** with python so yes you could do it but no i probably couldn't. the problem i've always had with python is that it's so easy i'm like "oh yeah i know this, this is easy" until you actually run into some code that's tricky, at which point i go "jesus, i suck, i should actually learn python." then i go out and learn just enough to figure out my problem, and then i'm back to thinking "oh yeah i totally know python ****'s easy"
Ok cool. Yeah there are plenty of good books on Python and the internet is great. The only idea I was trying to convey regarding Python is that if you can model your algorithms at a really high level you can verify them when you implement the lower level code. Since Python is interactive you can experiment a little easier to gain more insight. I'm not a Python expert btw but I've done enough to know my way around in doing things. I reailize to that scripting will probably be part of this. Don't worrry about the multi-processing vs multi-threading at this point. I'm just throwing out things that would possibly need to be considered IE design a solution accoriding to what your requirements actually are.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-31-2015 , 07:32 PM
Code:
nums = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]

def make_99 ():
    num_set = set()
    for i in nums:
        for j in nums:
            num_set.add(i + j)
    num_set.remove("00")
    return num_set

def fizz_buzz():
    num_list = sorted(list(make_99()))
    for i in num_list:
        str = ''
        if (int(i[0]) + int(i[1])) % 3 == 0:
            str += "fizz"
        if i[1] == '5':
            str += "buzz"
        elif i[1] == '0':
            str += "buzz"
        if len(str) == 0:
            if i[0] == "0":
                str += i[1]
            else:
                str += i
        print(str)
    print("buzz")

fizz_buzz()
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-31-2015 , 07:57 PM
Quote:
Originally Posted by adios
Code:
#include <iostream>
using namespace std;
char * FizzStr     = "Fizz";
char * BizzStr     = "Bizz";
char * FizzBizzStr = "FizzBizz";
char * FizzBizzData[] = {
   "",
   "1",  "2", FizzStr, "4", BizzStr, FizzStr, "7", "8", FizzStr, BizzStr,"11", FizzStr,"13","14", FizzBizzStr,
   "16","17", FizzStr,"19", BizzStr, FizzStr,"22","23", FizzStr, BizzStr,"26", FizzStr,"28","29", FizzBizzStr,
   "31","32", FizzStr,"34", BizzStr, FizzStr,"37","38", FizzStr, BizzStr,"41", FizzStr,"43","44", FizzBizzStr,
   "46","47", FizzStr,"49", BizzStr, FizzStr,"52","53", FizzStr, BizzStr,"56", FizzStr,"58","59", FizzBizzStr,
   "61","62", FizzStr,"64", BizzStr, FizzStr,"67","68", FizzStr, BizzStr,"71", FizzStr,"73","74", FizzBizzStr,
   "76","77", FizzStr,"79", BizzStr, FizzStr,"82","83", FizzStr, BizzStr,"86", FizzStr,"88","89", FizzBizzStr,
   "91","92", FizzStr,"94", BizzStr, FizzStr,"97","98", FizzStr, BizzStr };

int main() {
for (int i = 1; i<=100; i++ ) {
cout << FizzBizzData[i] << endl;
}
return 0;
}
I think this solution is the fastest execution wise I've seen in this thread. Am I cheating? To be honest, if I asked someone to do this and they came up with a solution like this I'd probably hire them.
What if the problem changes later to be Soda Pop instead of fizz buzz?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-31-2015 , 08:03 PM
I think it's arguable as to whether that is cheating or not. You are replacing so if that is a condion of the problem, strictly speaking you fulfill it.

On more ambiguous questions ("print fizz instead...") you could probably just write in all the results and then list them to execute it even faster.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-31-2015 , 08:50 PM
Weird question but does anyone else have trouble making this thread or any others show up in the "subscribed threads" area of your control panel? (desktop web of course). i.e. it seems to be unsubscribed. Works fine on the android app.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-31-2015 , 08:57 PM
Quote:
Originally Posted by adios
Code:
#include <iostream>
using namespace std;
char * FizzStr     = "Fizz";
char * BizzStr     = "Bizz";
char * FizzBizzStr = "FizzBizz";
char * FizzBizzData[] = {
   "",
   "1",  "2", FizzStr, "4", BizzStr, FizzStr, "7", "8", FizzStr, BizzStr,"11", FizzStr,"13","14", FizzBizzStr,
   "16","17", FizzStr,"19", BizzStr, FizzStr,"22","23", FizzStr, BizzStr,"26", FizzStr,"28","29", FizzBizzStr,
   "31","32", FizzStr,"34", BizzStr, FizzStr,"37","38", FizzStr, BizzStr,"41", FizzStr,"43","44", FizzBizzStr,
   "46","47", FizzStr,"49", BizzStr, FizzStr,"52","53", FizzStr, BizzStr,"56", FizzStr,"58","59", FizzBizzStr,
   "61","62", FizzStr,"64", BizzStr, FizzStr,"67","68", FizzStr, BizzStr,"71", FizzStr,"73","74", FizzBizzStr,
   "76","77", FizzStr,"79", BizzStr, FizzStr,"82","83", FizzStr, BizzStr,"86", FizzStr,"88","89", FizzBizzStr,
   "91","92", FizzStr,"94", BizzStr, FizzStr,"97","98", FizzStr, BizzStr };

int main() {
	for (int i = 1; i<=100; i++ ) {
		cout << FizzBizzData[i] << endl;
	}
	return 0;
}
I think this solution is the fastest execution wise I've seen in this thread. Am I cheating? To be honest, if I asked someone to do this and they came up with a solution like this I'd probably hire them.
Why even use variables at all if you're going for pure speed? We're implicitly assuming here that the strings could change, but the length of the array and periodicity of the strings being output will never change.

Last edited by suzzer99; 01-31-2015 at 09:04 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-31-2015 , 09:39 PM
For kicks, a single line FizzBuzz in C#:

Quote:
Enumerable.Range(1, 100).Select(i => i%15!=0 ? (i%5!=0 ? (i%3 != 0 ? i.ToString() : "Fizz") : "Buzz") : "FizzBuzz").ToList().ForEach(s => { Console.WriteLine(s); });
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-31-2015 , 11:45 PM
Buiding an automated script is much harder than fizzbuzz.

Just wanted to toss that one out there.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-01-2015 , 02:54 AM
Quote:
Originally Posted by adios
Code:
#include <iostream>
using namespace std;
Stopped reading there.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-01-2015 , 09:22 AM
Quote:
Originally Posted by daveT
That's awesome! Congrats.

You wouldn't believe what I did to get vacation time for me and a handful of other employees.
So the rumors are true and "it's LA, try harder honey" don't just apply to acting jobs?

Just finished the sprawl trilogy the other day. A bit overrated imo but it's hard to take into account how forward thinking some of the stuff was given when it was written. Now I need something to read on the train. I always have one technical/work related book (currently empirical methods, eloquent JS probably next) and one other (was Mona Lisa Overdrive, now the Feyman comic book which is awesome but almost done).
Suggestions welcome.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-01-2015 , 09:33 AM
Quote:
Originally Posted by Craggoo
Unless you have a vision for the next Amazon, I don't see any experienced programmer working for future equity that may never be realized.
Generally I'd agree with you but this typo of job is attractive for many programmers imo. Side project for equity is fine.

The post on CL seems a bit rambly and all over the place but overall it does sound interesting. Alas I'm not interested but I have a feeling too many people will read this and wonder why they shouldn't just do it on your own. Your gambling expertise needs to be showcased more imo. Otherwise people will just think "so he bet sports a bit"?

tl;dr: Rewrite it under the assumption that the reader knows everything you expect and wants to know what you can bring to the table. The parts about what they should know can be added once this is nailed down perfectly.

It's also a bit unclear how the equity situation will look. From reading your responses I think you expect them to use the results to beat the market down the line (aka wager their own money)? What do they get if they don't want to do that? You don't have to give %ages but explain how this will get monetized.

Since this is CHI, chances are probably better if you drive to UoC (strong quant stuff from the econ there iirc) and post a couple of flyers.

Last edited by clowntable; 02-01-2015 at 09:49 AM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-01-2015 , 09:39 AM
Quote:
Originally Posted by blackize5
I'm struggling to imagine why C++ is necessary. Seems like there are better language choices regardless of the application.
C++ makes perfect sense. Seems like something where you'd want a lot of control over what you can optimize. I think stuff like that is usually prototyped in Python (the calculation bits sometimes in R but I only know the basics there) and then rewritten in a lower level language, specifically for parallized computing.
I only have a passing knowledge of a related domain (mathematicians quant-searching for lucrative oil drilling spots)

Quote:
Originally Posted by Craggoo
Uh no?
Not sure how to answer this without sounding like an ass. There are plenty of programmers out there doing stuff for free. In fact I'd argue that the vast majority of (good) programmers does this all the time. There's plenty of "omg that looks like a neat thing to do" projects people do on the side all the time. A very small %age of programmers goes in thinking about how that could make them money, increase their reputation etc.
All the people I have met that I'd label "excellent programmer" had this mindset.

The suggested project can be pitched exactly like this. Something cool to work on (with an inbuilt way of testing if it does...neat).

Last edited by clowntable; 02-01-2015 at 09:54 AM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-01-2015 , 10:13 AM
Quote:
i have such little experience working on big projects without some sort of hand-holding that i would 100% for sure **** it all up right from the beginning and have to start from scratch like five times before i got something that wasn't terrible.
I think there's three essential parts:
1) Identify how you get access to the data streams and how you'll handle the incoming data. What's the best way to get up to date injury data (my guess is some twitter magic), weather data, raw past statistics, live odds etc.
2) How do you place the bets, how do you do so in a high frequency manner?
3) The core algorithm(s) in the back. What inputs do you need, what do you want to spit out? My initial thoughts would be some support vector machine or NN that just spits out bet/don't bet. Game simulations for prediciton also fall into this. As does modern portfolio theory.

n) Glue it all together. You can test all of 1-3 induvidually and provide manual data if needed.

Optional: Some sort of domain specific language to quickly test what would happen if you changed the NBA rules to make a 3 pointer a 3.2 pointer etc.
I think I'd start with 1, build a solid foundation of past data in a normalized way. Once that's in place you can already think of some experiments to run (trivial stuff like "how much have betting lines shifted if stud WR was injured", "how fast was the line switch" etc...this is actually not as trivial as it sounds but it's a good starting point imo)

[and for the love of god just build for one sport, I assume you do but it's worth repeating]

You say you have worked on 3 kind of (you'll provide algorithms) but you can also point out that you should be good at 1 and 2 as a gambler. From what I hear 2 is usually the biggest problem. AFAIK it's still fairly easy to beat college BB algorithmically but you can't place enough bets to make it worthwhile.

Edit: The entire talk about C++ is a bit meh. Your inputs will most likely be scraped off websites or social media or stuff with web APIs. JavaScript/Python are fine for that. Only the algorithm backend needs to be perfectly optimized. I think C+ sounds perfect for that. In an ideal world Haskell would be the perfect language for that task but C++ is a good tradeoff for finding programmers and actually understanding the code yourself.
Python has the nice sideffect of being good enough to prototype the algorithm stuff in though.

Last edited by clowntable; 02-01-2015 at 10:28 AM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-01-2015 , 12:50 PM
Quote:
Originally Posted by clowntable
Just finished the sprawl trilogy the other day. A bit overrated imo but it's hard to take into account how forward thinking some of the stuff was given when it was written. Now I need something to read on the train.
Snow Crash/The Diamond Age/Secrets of the Javascript Ninja
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-01-2015 , 12:59 PM
Yeah I had Snow Crash on my list, might have started it back in France, can't remember. Guess I'll go there next, I've read that it's pretty well written, too.

Maybe I'll dive back into Terry Pratchett but I feel like scifi/cyberpunk and not fantasy these days so Snow Crash seems pretty much perfect.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-01-2015 , 01:09 PM
The Martian is pretty fantastic hard sci-fi if you haven't read that.
Hex by Allen Steele is great.
The Expanse series by James A. Corey is fantastic near future space opera.
Peter Hamilton writes huge far future space opera that is also fantastic.
for something different
The Folly series by Ben Aaronovitch is a cross between Harry Potter and Law and Order UK, and very well done for modern fantasy.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-01-2015 , 01:38 PM
Quote:
Originally Posted by clowntable

Not sure how to answer this without sounding like an ass. There are plenty of programmers out there doing stuff for free. In fact I'd argue that the vast majority of (good) programmers does this all the time. There's plenty of "omg that looks like a neat thing to do" projects people do on the side all the time. A very small %age of programmers goes in thinking about how that could make them money, increase their reputation etc.
All the people I have met that I'd label "excellent programmer" had this mindset.

The suggested project can be pitched exactly like this. Something cool to work on (with an inbuilt way of testing if it does...neat).
When I think of "free" stuff programmers might do it's contributing to open source projects, creating frameworks of your own, etc. It's the sort of stuff that looks free but is more self-serving imo. Down the line, if that framework takes off then you're in prime position to profit from it. Tutorial books come to mind as the most obvious.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-01-2015 , 02:00 PM
It's doubtful there is only one reason people contribute to open source software.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
02-01-2015 , 04:13 PM
For sci-fi/cyberpunk, I'd suggest Tad Williams Otherland.

I hate sci-fi/fantasy and I loved this epic series.
** 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