Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
shrughes
Oct 11, 2008

(call/cc call/cc)

how!! posted:

If you have a query that is slow, the only way to fix that problem is to tweak settings, or re-write your query.

The solution isn't to rewrite the entire product?

Adbot
ADBOT LOVES YOU

Tres Burritos
Sep 3, 2009

shrughes posted:

The solution isn't to rewrite the entire product?

Hah. I see what you did there.

:munch:

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

shrughes posted:

The solution isn't to rewrite the entire product?

No, you rewrite the database. Duh.

Of course, you need to know B-trees for that, so gently caress it. Let's just use flat files.

Null Pointer
May 20, 2004

Oh no!

shrughes posted:

The solution isn't to rewrite the entire product?

No, that's just how you avoid NP-hard problems.

how!! posted:

Instead of trying to optimize through these types of algorithms, its best to redesign the system itself that makes this type of problem happen in the first place.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Ithaqua posted:

No, you rewrite the database. Duh.

Of course, you need to know B-trees for that, so gently caress it. Let's just use flat files.
But that'd require actually writing code, and all he does is Google for already existing code that does what he needs. Luckily there's a few more database servers to try before the company runs out of money.

double sulk
Jul 2, 2010

Ithaqua posted:

90k for a junior position is absurd even in NYC. 65-75 is pretty fair. I think your tax calculations are off, though. I don't get taxed anywhere near that much. I don't have the numbers in front of me, but I have about 28% of my paycheck deducted for taxes. I also don't live in NYC and make more than 70k, so your mileage may vary.

Consider living in Hoboken or Jersey city and commuting if you take the job. It will be a LOT cheaper. Or anywhere along the northeast corridor NJ Transit line; I used to live in New Brunswick and could be at penn station in an hour, which isn't bad. I paid $1150 for a pretty spacious one bedroom apartment there.

I checked back on the thread and saw a ton of posts and was worried this ended up ignored! So thanks for replying. I don't know where the other numbers are coming from if those numbers you're suggesting are fair. I was talking about it in YOSPOS (joke forum aside, there are some good people over there) and someone mentioned that the NYC taxes are pretty hefty, but I forget the exact context (if you're living and working in NYC, or just working there and living anywhere in the area). Even if it's about a 28% tax on 70k, it's still very close to 50k after all is said and done. Hoboken might be reasonable, but I know nothing of that area and I'd like to minimize my commute to work as much as possible, even if it means spending a little more. I believe can get a decent studio for about $1500 a month if I look hard enough, and space isn't the biggest issue so I can sacrifice on that front for a nicer commute.

Are there any early signs I can look for that suggest whether I will be getting relocation assistance, if offered a position at all? Nothing was stated that they would or wouldn't do it, but I was told on the initial screen that supposedly many/most of the people who applied were not from the area and would only be looking to telecommute, which they don't want.

tef
May 30, 2004

-> some l-system crap ->

how!! posted:

At that point I pretty much realized he was looking for someone who thinks exactly like him. [...] It wouldn't bother me so much if it weren't for the face that literally 99% of phone interviews end up like this.

I am tempted to conclude that you are failing because they are looking for someone who thinks (like a programmer) given your posting history collaborates this.

The reason interviews end up failing 99% of the time is because you are whiny petulant egotist who is hostile when questioned on your ability or skill as a programmer. You have a hard time accepting that other people might know better, or that you have some room to grow or learn.

If you are lucky, you will be hired by someone who does not think like a programmer. I wish you success in this venture, given the alternative — growing up — may take considerable time.

quote:

Am I the only person who is unable to write algorithms over the phone?

There are lots of other people who fail programming interviews because of a lack of competence in the subject, you are not alone.

So many in fact, that very simple exercises like fizzbuzz are popular. The majority of people writing programs have very little in the way of algorithmic knowledge, or competency beyond shuffling characters around on the screen.



quote:

In real life, being faced with problems like these means you have bigger problems, IMO.

Given you can't pass a programming interview, I don't think you're allowed to use this "real-life" excuse every time your approach is challenged.



quote:

Instead of trying to optimize through these types of algorithms, its best to redesign the system itself that makes this type of problem happen in the first place. All real life problems have a context. Imaginary interview problems have no context.

The context is far more real life than the "real life" programming you tout. What you are missing is that they are solving a problem - how to hire a programmer.


quote:

What do these numbers represent? Why do we have a stream of numbers that scales to the point where we absolutely need the most optimal algorithm? Answers to these questions are essential to creating the best solutions, but are unanswerable when asked as part of an interview.

The colour of the bikeshed is very important when demonstrating basic competency in construction.

quote:

Just wanted to rant.

I love these chats :3:

tef
May 30, 2004

-> some l-system crap ->

how!! posted:

Too much lovely code comes from by programmers who just mindlessly write code without considering the best possible solution.

Most of the terrible code I have seen is not from beginners. The mistakes are easy and obvious to spot, just from a simple overview I can see how bad things are.

The worst code I have seen is from 'experts'. The mistakes are subtle and well hidden behind layers of well meaning abstraction and encapsulation.

In the real world, tradeoffs happen. I know it is hard to put your utopian zealotry aside, abandoning perfectionism, and write 'lovely' code.

The reason lovely code exists is that good code takes far more time to write well, and many problems will have moved on by then.

quote:

I think the reason why I hate these kinds of questions is because they assume a "mode of operation" that is completely different than how I solve problems. My way of solving problems is to always step up to a higher level and fix it there, instead of dropping down to a lower level to solve the problem.

This mode is 'pragmatism'. What you do is architecture ad absurdum.

quote:

I was once asked in another interview how database indexes work. I answered "thats how you speed up queries. You add an index to a column that you query against and it makes selecting against that column much faster. The trade-off is that is slows down writes".

He asked you how they work. You told him they work like magic.

quote:

The interviewer then asked me how they are implemented. I said "low level computer sciency stuff, linked lists and big O trees and crap, idk" (in other words, "don't know don't care").

This sentence is a beautiful snowflake.

quote:

He then proceeded to practically lecture me (in a respectful way) on how important it is to understand stuff from a low level. I fundamentally disagree with this sentiment.

I can believe this, you have demonstrated wilful ignorance many times in this forum too.

KidDynamite
Feb 11, 2005

gucci void main posted:

a decent studio for about $1500 a month

Not happening unless you go to Brooklyn and then you will have to commute anyway.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

gucci void main posted:

I don't know where the other numbers are coming from if those numbers you're suggesting are fair. I was talking about it in YOSPOS (joke forum aside, there are some good people over there) and someone mentioned that the NYC taxes are pretty hefty, but I forget the exact context (if you're living and working in NYC, or just working there and living anywhere in the area). Even if it's about a 28% tax on 70k, it's still very close to 50k after all is said and done. Hoboken might be reasonable, but I know nothing of that area and I'd like to minimize my commute to work as much as possible, even if it means spending a little more. I believe can get a decent studio for about $1500 a month if I look hard enough, and space isn't the biggest issue so I can sacrifice on that front for a nicer commute.

(note: I'm kind of assuming you're in your early 20s and this is a first or second job. If I'm wrong, correct me!)

NYC is really, really, really expensive. You're not going to get around that if you work and live there. Roommates are not uncommon, especially if you're just getting your career started. Since you're going for junior positions, I'm assuming that's the case. Junior developers generally can pull in somewhere between 65 and 75k. If they end up forcing you to name a number, say 80. They might just shrug and give it to you, in which case you're doing better than I was until I had around 6-7 years of experience. If they don't, it's not so far off the average that they'll automatically laugh you out the door.

$1500 a month is a lot of money, and that's not taking into account your other living expenses (gas, water, electricity, etc). I strongly recommend doing research into the cities in NJ that have PATH stations.

quote:

Are there any early signs I can look for that suggest whether I will be getting relocation assistance, if offered a position at all? Nothing was stated that they would or wouldn't do it, but I was told on the initial screen that supposedly many/most of the people who applied were not from the area and would only be looking to telecommute, which they don't want.

That's something you bring up when you're discussing salary and benefits.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
Yeah, dude, you need to loving let go. There are too many dogmatic morons in every field who hold onto their ideals while covering their eyes and ears. In programming, where at some point you need to trust that your hires will make competent decisions on their own, you are a very unattractive hire. You allow your dogmatic views to:

- interfere with your knowledge development
- make excuses for rather than acknowledge your shortcomings
- handicap your ability to solve problems practically
- damage your ability to communicate your decisions to others

I'm just a programming nub, but I've seen plenty of folks like you in other fields. They either grow out of their dogma, or get forever passed over by much more open minded, flexible and practical people.

tef
May 30, 2004

-> some l-system crap ->

how!! posted:

Because there is always a high level work around that results in better, more maintainable code.

There is so much wrong in this one sentence alone my mind is reeling to disentangle it.

quote:

For instance, right now I'm writing a python framework (https://github.com/priestc/giotto).

“The X server has to be the biggest program I’ve ever seen that doesn’t do anything for you”

dingy dimples
Aug 16, 2004
So. how!!. You've already been told how your attitude is not going to win over interviewers. Also your statements on higher levels and context sound like handwavy bullshit and I'm not even convinced that you're fooling yourself, let alone others. Let's get back to the algorithm for a bit, in plain English rather than code.

When I first read the problem, I considered paring the array of numbers down to unique values. Iterate over each element of the array and add the element to a hash table. This takes bigtheta(n) time. Then, iterate over the keys of the hash table and check if the target sum minus the key is itself also in the hash table, and return true if it is. If the search fails, return false. This second step is O(n) in the worst case that every element of the original array was unique.

However, after I literally slept on it, I realized that this might be incorrect if a number appears exactly once and the sum is exactly double that number. An example was posted earlier with an array {1,3} and a target of 6.

So. Instead of reducing the array down to a set of unique values, we need a mapping of each value to the number of times it occurs. Basically, the first step of counting sort, http://en.wikipedia.org/wiki/Counting_sort. Once we build this mapping (a bigtheta(n) operation), we can proceed with our checks. Iterate over the keys in your count map. Compute the difference between the target and the current element. If the difference and the element are equal AND the element occurred more than once, return true. If the difference and the element are not equal and the difference occurred at least once, return true. If no iteration returns true, return false. This overall solution is also bigtheta(n).

If you actually write code for this, it'd be a great idea to write a simple test harness and test it out with some array/target pairs like so:
[1,2,3,50], 100
[1,2,3,50,50], 100
[1,2,3], 5
[1,2,3], 100

So there you have it, not just a way to answer the problem, but a way to answer the problem to impress an interviewer. This way demonstrates an improving understanding of the problem, a request for clarification, an improving algorithm, and a concern for testing your final solution. These will carry you farther than simply balking, as you did here and in that tumblr post from the other day: http://programming-gibberish.tumblr.com/post/37246383728/micro-and-macro-challenges-coding-during-interviews.

It also involved a lot of that "low level computer sciency stuff, linked lists and big O trees and crap, idk". You need to understand why hash lookups are fast and how they can improve the big-O/big-theta of your algorithm. Or at least the difference between O(n) and O(n^2) so you don't end up writing Schlemiel the Painter algorithms: http://www.joelonsoftware.com/articles/fog0000000319.html.

I'll close with a question: what kind of low-level questions would you not balk at? Do you know C? Would you write an implementation of strlen if asked? strcat? Could you implement any sort at all, in any language, from scratch?

Thom Yorke raps
Nov 2, 2004


I couldn't resist
code:
public Pair<Integer, Integer> lookup(int target, List<Integer> numbers) {
  Set<Integer> possibleAnswers = new HashSet<Integer>();
  for(Integer number : numbers) {
    if(possibleAnswers.contains(number)) 
	return Pair.create((target - number), number);
    possibleAnswers.add(target - number);
    
  }
  return null;
}

Ithaqua posted:

(note: I'm kind of assuming you're in your early 20s and this is a first or second job. If I'm wrong, correct me!)

NYC is really, really, really expensive. You're not going to get around that if you work and live there. Roommates are not uncommon, especially if you're just getting your career started. Since you're going for junior positions, I'm assuming that's the case. Junior developers generally can pull in somewhere between 65 and 75k. If they end up forcing you to name a number, say 80. They might just shrug and give it to you, in which case you're doing better than I was until I had around 6-7 years of experience. If they don't, it's not so far off the average that they'll automatically laugh you out the door.

$1500 a month is a lot of money, and that's not taking into account your other living expenses (gas, water, electricity, etc). I strongly recommend doing research into the cities in NJ that have PATH stations.


That's something you bring up when you're discussing salary and benefits.
I would ask for at least 85,000. I live in a very cheap city and I know multiple developers starting at over 70,000 right out of school (with co-ops or internships). I know people who got their first job in NYC and started at 105,000. NYC is ungodly expensive. Also yes they should pay a couple thousand in moving expenses.

how!!
Nov 19, 2011

by angerbot

dingy dimples posted:

However, after I literally slept on it,

You don't have the luxury of sleeping on it. If I had that luxury, I would have solved it too. The reason I made that post was to complain about having to write the algorithm over the phone. I've thought about it more, and realized the problem is that I'm an introvert. I get really nervous when talking on the phone with people I don't now. I have a social battery that runs out very quickly. Usually at the end of the interview, when they ask "Do you have any questions", I usually say no because I'm mentally exhausted I just want to hang up. Also, most interviewers are the same way, I suspect. Occasionally I'll interview with someone who is very extroverted and friendly and the whole thing will go more smoothly, but usually not.

quote:

I'll close with a question: what kind of low-level questions would you not balk at? Do you know C? Would you write an implementation of strlen if asked? strcat? Could you implement any sort at all, in any language, from scratch?

Why do you want me to rewrite strlen, sort, or strcat? Whats wrong with the ones that come with the language? I don't like to re-invent the wheel just for the hell of it. If I were to write my own sort algorithm, I have no confidence it will work as well as the one built in. There could be corner cases, it could be very slow. With the built in implementations, I am confident they will work fine.

Lets say you could convince me that python's sort function is not as fast as it could be. In that case, telling me to write a better sort function is a legitimate task. The first step in my process is to google "sort python fast", because there is a big change you're full fo poo poo. Its not worth my time, or any company's time writing a lovely implementation of a sort function based on a lie. Lets say you are right. Python's sort function is crappy and slow. Someone wrote a blog post describing how you can get 3% improvement in sort performance if you use some crazy duff device type optimization. In the blog lists the code. There it is, your better sort function. Problem solved It only took, what, 20 seconds? Obviously I'd test out the code to make sure it actually works.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

how!! posted:

Why do you want me to rewrite strlen, sort, or strcat?

To ensure you know what they do. strlen and strcat are both two lines of code max.

Yes, they'd be slower, but that's not the point. You have to know how they're implemented in C, otherwise you don't know C.

JawnV6
Jul 4, 2004

So hot ...

how!! posted:

I don't like to re-invent the wheel just for the hell of it.

I thought that was your whole gimmick?

Rello
Jan 19, 2010

how!! posted:

You don't have the luxury of sleeping on it. If I had that luxury, I would have solved it too.

Could you have come up with the solution he did (or the other solutions posted) without a grasp of basic CS concepts? Wouldn't it help to have an understanding of how the data structures and sorting functions are implemented, along with the CS knowledge to understand why they are faster for this problem?

Someone could correct me if I'm wrong but I don't think the interviewer was expecting you to come up with that solution but was more interested in seeing how you approached the problem.

Your approach was to come up with an O(n^2) solution and then reluctantly try to optimize it and you took one step forward in trying to sort it and then stopped.

If everyone is telling you to try and learn CS why not just hop on Coursera and knock out algorithms and data structures course in a few months. What's the worst that could happen?

The Insect Court
Nov 22, 2012

by FactsAreUseless
The problem with heuristics like "indexes = faster queries, more disk" is that they're brittle. They're better than nothing, but they're inferior to a basic understanding of what B-trees are and how they let indexes do what they do. You don't need to reinvent the wheel, but knowing "wheels make moving stuff easy" while being ignorant of how wheels work is a bad idea if you then decide that a wheeled cart is a great way to climb stairs.

how!!
Nov 19, 2011

by angerbot

Rello posted:

Could you have come up with the solution he did (or the other solutions posted) without a grasp of basic CS concepts? Wouldn't it help to have an understanding of how the data structures and sorting functions are implemented, along with the CS knowledge to understand why they are faster for this problem?

Someone could correct me if I'm wrong but I don't think the interviewer was expecting you to come up with that solution but was more interested in seeing how you approached the problem.

Your approach was to come up with an O(n^2) solution and then reluctantly try to optimize it and you took one step forward in trying to sort it and then stopped.

If everyone is telling you to try and learn CS why not just hop on Coursera and knock out algorithms and data structures course in a few months. What's the worst that could happen?

I know how to code. Look at my github. I have over 20,000 lines of code that I've written over the past few years. Over 200,000 lines if you add up all the plusses and minuses across all commits. I just can't code over the phone. He asked me the question, I gave my initial solution after 3 or 4 seconds of thought. From the time he first asked the question until the interview moved on, was about 20 or 30 seconds. The problem is that I don't quite think verbally. My thinking process is more visual. Look up Rich Hickey's "Hammock Driven Development" talk. He pretty much describes my thinking process to a T. When I first saw that presentation I wanted to give Rick Hickey a hug.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Rello posted:

If everyone is telling you to try and learn CS why not just hop on Coursera and knock out algorithms and data structures course in a few months. What's the worst that could happen?

On that, I'm realizing that while I'm busy on my own projects, as a self taught my implementations are likely real clumsy and I arrive at solutions by trial and error more than through knowing the correct approaches through prior learning.

Doing online courses seems like it'd be a good way to shore up my weaknesses? Would anyone have suggestions for which courses are best for that. Is this the sort of thing I should be looking at?

https://www.coursera.org/course/algs4partI

genki
Nov 12, 2003

how!! posted:

I know how to code. Look at my github. I have over 20,000 lines of code that I've written over the past few years. Over 200,000 lines if you add up all the plusses and minuses across all commits. I just can't code over the phone. He asked me the question, I gave my initial solution after 3 or 4 seconds of thought. From the time he first asked the question until the interview moved on, was about 20 or 30 seconds. The problem is that I don't quite think verbally. My thinking process is more visual. Look up Rich Hickey's "Hammock Driven Development" talk. He pretty much describes my thinking process to a T. When I first saw that presentation I wanted to give Rick Hickey a hug.
1. Please don't equate lines of code to knowing how to code.
2. If you have issues verbally coding over the phone, that's something you should prepare for. Google sample questions, practice solving them out loud. If you can, have a friend or someone to talk you through it. Frankly, the biggest point of those sorts of questions is to see whether the candidate has a logical thought process when they approach a problem. If you want to take up time to get your thoughts together, try restating the question in your own words to be sure you understand what they're asking for. And if you present them with a solution that you know isn't optimal, tell them that you know it isn't optimal, then start thinking out loud about how you could make it optimal. You don't have to know the right answer right away, you just have to show the interviewer that you know there's a better answer, and that you know the logical next steps to get to the right answer.

Usually, in real life, the problems aren't the problems you get on the phone, the problems are problems that no one else has seen. So it doesn't matter how good you are at finding someone else's solution if it doesn't exist, you have to be able to show that you have problem-solving skill. I'll admit that with most jobs, the issue is being able to match the exact issue you have at work with a somewhat similar problem that someone else had somewhere else. So then with an understanding of the comp-sci principles that were used by someone else to solve THAT problem, you can make the necessary adjustments to solve your work problem. It's actually fairly rare that you get to work on problems that no one else has seen... unfortunately.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Ranma posted:

I couldn't resist
code:
public Pair<Integer, Integer> lookup(int target, List<Integer> numbers) {
  Set<Integer> possibleAnswers = new HashSet<Integer>();
  for(Integer number : numbers) {
    if(possibleAnswers.contains(number)) 
	return Pair.create((target - number), number);
    possibleAnswers.add(target - number);
    
  }
  return null;
}
Unless I'm missing something, it still does not pass lookup(6, [1, 3]). This is why people are asked this question. The gotcha isn't that you missed it, but what they really want is to see whether or not you can think of the solution now that you know about this case.

Strong Sauce fucked around with this message at 08:12 on Dec 14, 2012

Rello
Jan 19, 2010

how!! posted:

I know how to code. Look at my github. I have over 20,000 lines of code that I've written over the past few years. Over 200,000 lines if you add up all the plusses and minuses across all commits. I just can't code over the phone. He asked me the question, I gave my initial solution after 3 or 4 seconds of thought. From the time he first asked the question until the interview moved on, was about 20 or 30 seconds. The problem is that I don't quite think verbally. My thinking process is more visual. Look up Rich Hickey's "Hammock Driven Development" talk. He pretty much describes my thinking process to a T. When I first saw that presentation I wanted to give Rick Hickey a hug.

Ah sorry, I'm not questioning you're ability to code. There is a difference between knowing how to code and knowing how to come up with quick algorithms and how to avoid slow algorithms (knowing how to code well). You seem to struggle with the latter and it isn't impossible to fix so why not just take the time to do it? They are both important and there is no reason to disregard either one.

Are you under the impression that people who think CS is important to know (nearly everyone) are spending hours and hours at work trying to come up with the most optimal algorithms for any problem that appears? Of course not but it is important to be able to know how to avoid slow algorithms and how to speed algorithms that are causing issues. It doesn't take nearly as much time as you seem to think it does to optimize an O(n^2) solution, it takes a few minutes not hours. Out of curiosity did you know that the solution you gave the interviewer was O(n^2)?

Trust everyone and just take the time to learn some computer science. I know Algorithms: Design and Analysis, Part 1 is starting on coursera soon so that would be a good start since I don't think they assume any previous knowledge on the subject.

tk
Dec 10, 2003

Nap Ghost

how!! posted:

I know how to code. Look at my github. I have over 20,000 lines of code that I've written over the past few years. Over 200,000 lines if you add up all the plusses and minuses across all commits. I just can't code over the phone. He asked me the question, I gave my initial solution after 3 or 4 seconds of thought. From the time he first asked the question until the interview moved on, was about 20 or 30 seconds. The problem is that I don't quite think verbally. My thinking process is more visual. Look up Rich Hickey's "Hammock Driven Development" talk. He pretty much describes my thinking process to a T. When I first saw that presentation I wanted to give Rick Hickey a hug.

There are some people that just don't do well in interviews. They can be fantastic programmers, awesome at problem solving, great interpersonal skills, spectacular hair, and everything else that you would want in an employee. But they have a hard time in interviews. It's a real thing.

You are not one of these people.

greatZebu
Aug 29, 2004

Strong Sauce posted:

Unless I'm missing something, it still does not pass lookup(6, [1, 3]). This is why people are asked this question. The gotcha isn't that you missed it, but what they really want is to see whether or not you can think of the solution now that you know about this case.

You are missing something. Take another look.

Optimus Prime Ribs
Jul 25, 2007

JawnV6 posted:

I thought that was your whole gimmick?

He only reinvents the wheel if the doesn't like the wheels that his place of employment has invested time and money into implementing because his wheels are better, dammit!

Suspicious Dish posted:

To ensure you know what they do. strlen and strcat are both two lines of code max.

I could only make my strlen be four lines (excluding the two lines which are closing braces):

C++ code:
int strlen_crappy_version(char* src) {
    for (int i = 0; *src != '\0'; i++) {
        if (*(++src) == '\0') {
            return i+1;
        }
    }
    return 0;
}

void strcat_crappy_version(char* dest, char* src) {
    memcpy(dest+strlen_crappy_version(dest), src, strlen_crappy_version(src)+1);
}
How would you make that only two lines? Move the if statement into the for's condition or something?

It also crashes if you give strcat_crappy_version an unitialised string. :ssh:

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

Optimus Prime Ribs posted:

How would you make that only two lines? Move the if statement into the for's condition or something?

It also crashes if you give strcat_crappy_version an unitialised string. :ssh:

C++ code:
int strlen_crappy_version(char* src) { for (int i = 0; *src != '\0'; i++) { if(*(++src) == '\0'){return i+1;} } } return 0; }

void strcat_crappy_version(char* dest, char* src) { memcpy(dest+strlen_crappy_version(dest), src, strlen_crappy_version(src)+1); }
job please :colbert:

greatZebu
Aug 29, 2004

Optimus Prime Ribs posted:

He only reinvents the wheel if the doesn't like the wheels that his place of employment has invested time and money into implementing because his wheels are better, dammit!


I could only make my strlen be four lines (excluding the two lines which are closing braces):

C++ code:
int strlen_crappy_version(char* src) {
    for (int i = 0; *src != '\0'; i++) {
        if (*(++src) == '\0') {
            return i+1;
        }
    }
    return 0;
}

void strcat_crappy_version(char* dest, char* src) {
    memcpy(dest+strlen_crappy_version(dest), src, strlen_crappy_version(src)+1);
}
How would you make that only two lines? Move the if statement into the for's condition or something?

It also crashes if you give strcat_crappy_version an unitialised string. :ssh:

Not that you would actually write it like this, but:

C++ code:
int lousy_strlen(char* s) {
    if (!*s) return 0;
    return 1 + lousy_strlen(s + 1);
}

int lousy_strlen_2(char* s) {
    char* c = s;
    while (*c++) {}
    return c - s - 1;
}

Strong Sauce
Jul 2, 2003

You know I am not really your father.





greatZebu posted:

You are missing something. Take another look.

Ah yes, I retract my statement.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Optimus Prime Ribs posted:

How would you make that only two lines? Move the if statement into the for's condition or something?

I was looking for something along the lines of:

C++ code:
int strlen(char *src) {
   char *orig = src;
   while (*src++) ;
   return src - orig;
}

void strcat(char *dst, char *src) {
   while (*dst++) ;
   while ((*dst++ = *src++)) ;
}

Optimus Prime Ribs
Jul 25, 2007

greatZebu posted:

Not that you would actually write it like this, but:

Suspicious Dish posted:

I was looking for something along the lines of:

I never actually knew that '\0' evaluates to false, which is why I never claimed to be competent in C. :)
Though in retrospect that does make sense.

My strcat is still only one line, even if it's probably slower, and definitely more convoluted. :colbert:

Volte
Oct 4, 2004

woosh woosh

Optimus Prime Ribs posted:

I never actually knew that '\0' evaluates to false, which is why I never claimed to be competent in C. :)
Though in retrospect that does make sense.

My strcat is still only one line, even if it's probably slower, and definitely more convoluted. :colbert:
'\0' is literally 0.

shrughes
Oct 11, 2008

(call/cc call/cc)

Volte posted:

'\0' is literally 0.

Literally.

nachos
Jun 27, 2004

Wario Chalmers! WAAAAAAAAAAAAA!

gucci void main posted:

Tomorrow is my meeting and I'm trying to think about a few issues. I effectively worked around the salary question in the phone screen with a rough answer of "I am open to a fair offer based on the market rate and cost of living," and it hasn't been brought up since. I was, as mentioned before, told I did a great job on the coding project. I'm not trying to over-think the situation, but I assume that they are very serious about bringing me on if they are having me make a two hour trip.

What I'm wondering (and have asked a few people though), and am not 100% certain about just yet, is what I should be looking for as far as salary goes, as well as dealing with the cost of relocation. Apartments are not cheap in either Manhattan or Brooklyn, which is where I would need to be; it costs about 1600-2400 a month for a studio. I would very strongly prefer to live alone so I can have my privacy, hence those rates. My official title, as far as I am aware, would be as a Junior (Rails) Developer, but I've heard varying numbers in regards to what I should be looking for. Some people have said 70k minimum, and others have said 90k. 70k after taxes is about $46,000, based on salary calculators, which seems somewhat difficult to get by on comfortably.

Anyone familiar with the area who can give some advice is appreciated. I really want to think that they are planning to actually make an offer and not waste my time, even if I'm not taking a flight to get there.

I work at a startup in NYC and we hired a junior PHP dev for 75k. It's common for a startup to pay a bit below market value and try to make up the difference with an equity package so I'd echo Ranma and say ask for 80-85k. I've also lived alone on a 70k salary with 2k/month in bills and it's doable if you aren't saddled with loans or other debt to pay off.

Thom Yorke raps
Nov 2, 2004


Strong Sauce posted:

Unless I'm missing something, it still does not pass lookup(6, [1, 3]). This is why people are asked this question. The gotcha isn't that you missed it, but what they really want is to see whether or not you can think of the solution now that you know about this case.

It should, the check happens before the number is added so that isn't a problem. The code loops twice: First it checks if 1 is in the set, it is not so it adds 5 to the set. Then it checks if 3 is in the set, it is not so it adds 3 to the set. Then it returns null.

Posting Principle
Dec 10, 2011

by Ralp

Maluco Marinero posted:

On that, I'm realizing that while I'm busy on my own projects, as a self taught my implementations are likely real clumsy and I arrive at solutions by trial and error more than through knowing the correct approaches through prior learning.

Doing online courses seems like it'd be a good way to shore up my weaknesses? Would anyone have suggestions for which courses are best for that. Is this the sort of thing I should be looking at?

https://www.coursera.org/course/algs4partI

Online courses can be great, but there is no better resource than Introduction to Algorithms. This is the CLRS book that people keep talking about. It is a fantastic introduction to the implementation, design, and analysis of algorithms, and its an incredibly useful reference to have around. Look for international versions if price is an issue.

Steve French
Sep 8, 2003

greatZebu posted:

Not that you would actually write it like this, but:

C++ code:
int lousy_strlen(char* s) {
    if (!*s) return 0;
    return 1 + lousy_strlen(s + 1);
}


Oh please

C++ code:
int derplen(char *derp) {
  return *derp ? derplen(derp + 1) + 1 : 0;
}
(edit: also, multiple return statements??? HOW DARE YOU)

Steve French fucked around with this message at 17:35 on Dec 14, 2012

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.

Jerry SanDisky posted:

Online courses can be great, but there is no better resource than Introduction to Algorithms. This is the CLRS book that people keep talking about. It is a fantastic introduction to the implementation, design, and analysis of algorithms, and its an incredibly useful reference to have around. Look for international versions if price is an issue.

Bought this early for a course next semester, had to hide it because it was too distracting from the boring poo poo I'm taking now. I wish I had it earlier, to be honest. It is seriously so good.

Adbot
ADBOT LOVES YOU

oRenj9
Aug 3, 2004

Who loves oRenj soda?!?
College Slice

What's with all of these n00bs reinventing the wheel?

code:
size_t strlen (str) const char *str;
{
	const char *char_ptr;
	const unsigned long int *longword_ptr;
	unsigned long int longword, himagic, lomagic;
	
	for (char_ptr = str; ((unsigned long int) char_ptr
						& (sizeof (longword) - 1)) != 0;
		++char_ptr)
	if (*char_ptr == '\0')
		return char_ptr - str;

	longword_ptr = (unsigned long int *) char_ptr;
	himagic = 0x80808080L;
	lomagic = 0x01010101L;
	
	if (sizeof (longword) > 4)
	{
		/* 64-bit version of the magic.  */
		/* Do the shift in two steps to avoid a warning if long has 32 bits.  */
		himagic = ((himagic << 16) << 16) | himagic;
		lomagic = ((lomagic << 16) << 16) | lomagic;
	}
	if (sizeof (longword) > 8)
		abort ();
	
	for (;;)
	{
		longword = *longword_ptr++;
		if (((longword - lomagic) & ~longword & himagic) != 0)
		{
			/* Which of the bytes was the zero?  If none of them were, it was
			a misfire; continue the search.  */
			const char *cp = (const char *) (longword_ptr - 1);

			if (cp[0] == 0)
				return cp - str;
			if (cp[1] == 0)
				return cp - str + 1;
			if (cp[2] == 0)
				return cp - str + 2;
			if (cp[3] == 0)
				return cp - str + 3;
			if (sizeof (longword) > 4)
			{
				if (cp[4] == 0)
					return cp - str + 4;
				if (cp[5] == 0)
					return cp - str + 5;
				if (cp[6] == 0)
					return cp - str + 6;
				if (cp[7] == 0)
					return cp - str + 7;
			}
		}
	}
}
cat glibc/string/strlen.c

how!!, am I doing this job thing right?

oRenj9 fucked around with this message at 19:45 on Dec 14, 2012

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply