Open Side Menu Go to the Top

01-10-2016 , 01:19 PM
I'm mad leetcode doesn't let you test your answers without an account. Rawr

Also, I really struggle with the idea that being a good programmer means you instantly know the best way to write a solution the second you finish hearing the problem. I'm pretty sure that's not how it works in real life, but that's the understanding I've developed from solving lots of little simple things through school.

Yet another reason I assume school is somewhat bad for/at teaching software engineering.
** 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-10-2016 , 01:33 PM
Quote:
Originally Posted by adios
What if your program was a few milliseconds slower but was more maintainable and you spent half the amount of time another developer spent in coming up with a faster solution, who did the better job of writing the code?
To be clear, I'm not asking about practical coding standards here. I was just curious if there was any way at all to get a faster execution time in Python. My solution is already pretty weird imo, using a bitwise operator and casting the result to bool. Here's what I'd normally do (somebody might want to work on this problem so I'll spoiler it, even though for such a simple example it seems silly).

Spoiler:
Code:
class Solution(object):
    def canWinNim(self, n):
        """
        :type n: int
        :rtype: bool
        """
        return n % 4 > 0


But then I decided to make a game of trying to optimize the runtime and my earlier post was the best I could come up with, but apparently not very good at all (my best was 44ms, somebody got it down to 32ms in Python so I'm curious).
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2016 , 04:05 PM
Try using the bit shift operator maybe.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2016 , 04:19 PM
Quote:
Originally Posted by adios
@daveT - What programming skills do you think the interviewer was trying to evaluate with this question?
Since I'm not a technical interviewer, I wouldn't know the answer. the claim was to see if you know how to design a program, with very low priority on knowing how to use arcane algorithms.

my approach was this, which I'm sure is awful:

Spoiler:


import the op module so I can do arithmetic operations without eval
import the itertools module so I can do permutations.

create a list of ops, something like [op.add, op.sub, op.div, op.mul]

convert each number to a string, permute / split each string into a matrix. For example, 1234 would end up like this:
[[1234]
[123, 4]
[12, 3, 4]
....]

for each op and for each row in matrix, run through each combo of arithmetic expressions, check if valid (total brute-force solution here)

concat each valid combo into a string, print the string.


Quote:
Originally Posted by kerowo
Doesn't a large part of that revolve around knowing that equation that has e and pi in it?
I don't think so. I suspect it would work with any two sets of numbers, but e and pi just sounds cool.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2016 , 06:58 PM
in b4 gaming mouse posts a 1 line solution to daveT's problem
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2016 , 08:09 PM
fruit snacks; I'm sure there's some recurrance / pizza-slicing algorithm that does this just as well. I've never been that good at discrete math or recurrances, so I suppose that would be a limitation of my algorithmic understanding on these types of questions. That would definitely remove the muti-demsional array and reduce the time and space complexity, but wouldn't make it a one-line solution.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2016 , 08:25 PM
Quote:
Originally Posted by fruit snacks
in b4 gaming mouse posts a 1 line solution to daveT's problem
Quote:
Originally Posted by daveT
fruit snacks; I'm sure there's some recurrance / pizza-slicing algorithm that does this just as well. I've never been that good at discrete math or recurrances, so I suppose that would be a limitation of my algorithmic understanding on these types of questions. That would definitely remove the muti-demsional array and reduce the time and space complexity, but wouldn't make it a one-line solution.
i think i could probably get the brute force recursive solution down to a readable 10-15 lines, but i'll be honest: i see no way to write a solution that handles 100 digit numbers. that's far beyond the scope of a brute force solution, yet if we have to print all possible solutions, i don't see any trick to avoid brute forcing. dave, are you sure the problem required handling 100 digits?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-10-2016 , 08:55 PM
I'm not entirely sure what the top number was. This is from some older notes and I don't have the entire spec written down. I searched online and there are a few that have the entire problem with solutions, but no one mentioned the top limit. For some reason, 100 digits sticks in my head.

For whatever it's worth, my solution was about 20 LOC, but as noted, I used modules. I guess that solving it for some reasonable solution that doesn't require brute-forcing would count as well. I'd rather adjust the number down if that means the solution is elegant.

For example, this is a solution: https://gist.github.com/bhu1st/7dea8ec07b10bc28310b

but it uses eval(), which I explicitly remember was disallowed in the question posed to me.

I think the correct one-line solution is this, though:

Code:
## FML, I quit.

Last edited by daveT; 01-10-2016 at 09:01 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-11-2016 , 02:49 AM
Def index
@images = @Image.all.sample(1)
end

Can someone please tell me why this line works for def index but not for def home? I'm trying to get random @images for the homepage (pulled from Images model) and no combination works.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-11-2016 , 12:06 PM
Have any of you guys used this keyboard before?
http://www.amazon.com/AmazonBasics-K.../dp/B005EOWBHC

I know a mechnical keyboard would be nice but I'm wondering now that maybe something like the above keyboard would be good, simply because it would be much easier to clean and should be tactile enough?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-11-2016 , 01:17 PM
Have you ever used mechanical before? Like, the new modern ones
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-11-2016 , 01:55 PM
After going through a lot of them, I can't say enough good things about this keyboard: http://www.amazon.com/gp/product/B005L38VRU

Solar powered, wireless. There's no lag when it comes on and the keys are low and flat. Gunk doesn't get under them, they don't break and to me their easier to type on. It's similar to the MacBook keyboard feel.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-11-2016 , 02:23 PM
why are you "going through a lot of them"?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-11-2016 , 02:35 PM
Quote:
Originally Posted by Shoe Lace
Have any of you guys used this keyboard before?
http://www.amazon.com/AmazonBasics-K.../dp/B005EOWBHC

I know a mechnical keyboard would be nice but I'm wondering now that maybe something like the above keyboard would be good, simply because it would be much easier to clean and should be tactile enough?
That's basically a standard office Dell keyboard.

If you can't take the keys off the keyboard, they are not easy to clean.

The "tactile" in mechs refer to a point about mid-travel, where a "bump" indicates that you have activated the switch. If used well, you seldom "bottom out" which means you are never actually hitting the hard surface under the keys.

In contrast, the linked keyboard requires full travel, thus you are hitting the hard surface beneath the keys each time, which while "tactile," is highly unpleasant, and not synonymous with the meaning used in mechs.

IMO, the low-profile flat-keyed board you have linked is the worst kind of keyboard. it only takes me a few hours of use before my hands start burning. I'd rather take the style with taller keys, but they aren't a huge step better.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-11-2016 , 02:57 PM
@Noodle, nope but the Das mechanical keyboards are supposedly some of the best. Haven't gotten a chance to try one first hand. Youtube them tho if you want to see reviews.

@daveT, the problem with normal sized keys for cleaning is random crap gets under them and some keyboards are really difficult to take apart so cleaning it involves fishing between the keys with a pin or toothpick.

I'm not a slob either, but after a few years stuff does accumulate. I figured the short keys would lock out the dirt.

Hmm, that's interesting. I have a "regular" keyboard now (big keys, not a true mech) and I guess it falls somewhere in the middle. I personally hit them all the way down but if I sit here and try to measure it, it does feel like it will register a key before it bottoms out.

What makes your hands burn? I never tried the short keys before.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-11-2016 , 03:25 PM
I have a Das Keyboard, and it is still running great after 3 years. I'm not a slob either, but yeah, that stuff gets dirty. I probably break apart my keyboard about once every 3 months and give it a good solid clean. The keys are easy to remove with a key yanker. Of course, if you have the blank keys like I do, you have to be careful to put them back in correctly.

I'm not entirely sure what makes my hands burn with the low-profile keys. My laptop has scissor switches and that doesn't bother me much, though I have my keyboard on my laptop now. I think it is because the Dell-like boards have no real resistance until I bottom out the keys, so I hit the key with full force, plus after a few months, a key or two no longer responds on the first strike, so I end up double hitting very hard. The scissor keys and the mech each have a little bit of push back.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-11-2016 , 04:28 PM
Mechanical keyboards are like high end office chairs. There is no point trying to convince someone how a $1200 chair is better than a $120 chair. Either they'll get it, or their use cases are so bizarre they don't. Plenty of people love the Apple keyboard. w/e

I use a Filco. Most people will get a ~10-20wpm boost in speed (obv not if you're 130wpm+) moving over to a mechanical.

daveT,

Nice selection.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-11-2016 , 04:36 PM
Quote:
Originally Posted by Wolfram
why are you "going through a lot of them"?
Keys break or I don't like them due to ergonomic issues or bluetooth lag.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-11-2016 , 05:07 PM
For the record I type at about 70 wpm. Having to double strike due to a hardware issue sounds annoying. That's kind of what my keyboard is like now because it's 5 years old and has never been taken apart to clean.

I'm pretty sure you could build a bird's nest with the amount of garbage floating under the casing.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-11-2016 , 05:48 PM
I love it when I forget what language I'm in:
Code:
String s = "x";
if(s.equals('x')) {
  System.out.println("HERO");
} else {
  System.out.println("ZERO");
}
Spoiler:

ZERO ('x' is a byte)

Yeah I know always use the same '' or "" in other languages so mixing them should ring alarm bells and I usually default to ''...added the conditional after not looking at the code for a couple of weeks (the declaration of x was obviously scrolled offpage and not right there like in the example) and it took me at least 2 minutes or so to even realize where the problem could be
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-11-2016 , 05:57 PM
Also I was proofreading a JAVA exam the other day and it had a fun sub question about infinite loops. It's pretty obvious when it's introduced like this so I'll just write it. Was a multiple choice question "which of the following causes an infinite loop" with one answer being
Code:
for(byte b = 0; b < 100; b--) {
  System.out.println("Eating your resources...but how many?!");
}
I think it's kind of a dumb question but also kind of fun. Obviously powered through the test and didn't even read the byte and only thought...lawl always <0 so infinite...this is too easy.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-12-2016 , 05:21 PM
Does anyone have any insight into just how "minimum" an MVP should be?

For example: My friend and I want to track some information about User activity, which would require a certain database structure. This user activity is NOT a feature for an MVP, but it would likely be added later. In an MVP scenario do you literally just code the features with no regard for future development and just spend the extra time later to rewrite stuff?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-12-2016 , 06:08 PM
It is really hard to answer that question, but my experience with MVPs leads me to be skeptical that tracking user activity will "require a certain database structure" and would completely ignore that and if you want it in the future, figure it out then.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-12-2016 , 06:09 PM
Like, not to say it doesn't require a certain database structure, just that right now you aren't going to do it right anyway so what is the point in doing something that probably won't work in the future.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-12-2016 , 06:11 PM
Here is what an engineer working on an MVP release said earlier today

Quote:
i mean, i agree it's kinda ****ty, but hashtagidontgivea****
and this'll take me <15 minutes to implement
** 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