News for hackers. Stuff that matters.
Re:Code Llama, an AI tool for coding by droopyEyelids on Thursday August 24, 2023 @02:50PM (#37253013)
The simple-to-understand, greedy algorithm is always the correct first choice till you have to deal with a constraint.
Re:Code Llama, an AI tool for coding by blibble on Thursday August 24, 2023 @02:53PM (#37253038)
it's not that though, there's several other typical optimisations in there

just not the super obvious one that demonstrates extremely basic understanding of what a prime number is

Re:Code Llama, an AI tool for coding by jpeterson on Thursday August 24, 2023 @04:16PM (#37253991)
Having "extremely basic understanding" of prime numbers immediately at one's command is important for approximately 0% of software engineering jobs. If you instant-fail a candidate for this, it says a lot more about you and your organization than the candidate.
Re:Code Llama, an AI tool for coding by blibble on Thursday August 24, 2023 @04:46PM (#37254316)
> If you instant-fail a candidate for this, it says a lot more about you and your organization than the candidate.

yes, we expect professional software developers to have basic maths skills

"what is a prime number" is taught to 7 year olds, it's not vector calculus

what else would you consider to be an unreasonable thing for an employer to require?

reading and writing skills of a typical 7 year old?

Re:Code Llama, an AI tool for coding by ungruntled on Thursday August 24, 2023 @05:23PM (#37254722)
I think the key problem here is that is is a bad programming question. If you know anything about prime numbers then coming up with an answer is trivial. If you expect a more optimized solution, then you are really only gauging the interviewee’s understanding of prime numbers. So effectively the interview is more about mathematics than it is about programming or problem solving.
Re:Code Llama, an AI tool for coding by daok on Thursday August 24, 2023 @05:52PM (#37255028)
You probably do not have a child of 7 years old because they do not know at that age what is a prime number.

Second, basic math still that you never or rarely use or with very large time between usage might get rusty. You may understand the concept but not find the optimal solution. The way you are responding here shows quite a lot about how you are short sighted by instant-failing someone with a single question instead of trying to asses the whole person as much as you can. On you side, you are wasting opportunity to have a great person that could be a key player in your team by bringing other set of skill on the table.

Re:Code Llama, an AI tool for coding by blibble on Thursday August 24, 2023 @06:29PM (#37255391)
> You probably do not have a child of 7 years old because they do not know at that age what is a prime number.

it's part of the curriculum for children of this age where I grew up (I did check)

> The way you are responding here shows quite a lot about how you are short sighted by instant-failing someone with a single question instead of trying to asses the whole person as much as you can. On you side, you are wasting opportunity to have a great person that could be a key player in your team by bringing other set of skill on the table.

it may also be the case I have more in depth knowledge about the that roles I've interviewed candidates for

most recently: hiring people to work for quants

not instantly knowing that even numbers (other than 2) are not prime is a very strong signal

Re:Code Llama, an AI tool for coding by hyperbovine on Thursday August 24, 2023 @08:35PM (#37256376)
> You probably do not have a child of 7 years old because they do not know at that age what is a prime number.

A few do. And in 20 years you're reallyreally going to want to hire them.

Re:Code Llama, an AI tool for coding by jpeterson on Thursday August 24, 2023 @09:04PM (#37256599)
You're not testing for "basic math skills" here. What you're testing for is more like "immediately retrieves an irrelevant math fact after many years of having no need to think about it."

Look, if you think this sort of thing allows you to identify great candidates, good for you. But in my experience, not only is this kind of practice stupid on its face, but it leads to engineering orgs packed with people who are good at memorizing trivia but terrible at solving real problems.

Re:Code Llama, an AI tool for coding by Mawr on Friday August 25, 2023 @11:43AM (#37263006)
You happen to remember a particular piece of knowledge, so you project that expectation onto others. Theory of mind.

> yes, we expect professional software developers to have basic maths skills

Skill != knowledge. "What is a prime number" can be looked up and understood by any competent programmer in <5 minutes.

> "what is a prime number" is taught to 7 year olds, it's not vector calculus

Then it's reasonable to expect that an interviewee would be able to learn it as well, given the same resources. It does not however follow that an interviewee would inherently have that knowledge, just because 7 year olds are taught it.

Bottom line is, you're making too many assumptions about complete strangers.

Re:Code Llama, an AI tool for coding by rini17 on Friday August 25, 2023 @11:46AM (#37263043)
If they know "prime number" is some technical term to look up. They might confuse it with amazon prime or anything else depending on context. You waste time explaining, they get indignant they are supposed to coding not do maths, complete mess.
Re:Code Llama, an AI tool for coding by SideQuark on Thursday August 24, 2023 @07:28PM (#37255881)
Approx 0% of devs need to know what the earth is, but from lots of interviews I've given I've found consistent correlation between lack of basic knowledge and lack of ability to solve many things. It was so strong we found it much more cost effective to cut people early that didn't know at least a few of some standard knowledge items.
Re:Code Llama, an AI tool for coding by chaxor on Thursday August 24, 2023 @09:48PM (#37256906)
This is some really good advice here. It's always a good idea to throw out all candidates that can't immediately recall what the first theoretical result of the rest mass of a Higgs boson was in the first paper describing was. Basic knowledge like this just correlates so well with ability to make proper decisions in API architecture.
Re:Code Llama, an AI tool for coding by SideQuark on Sunday August 27, 2023 @03:38AM (#37280313)
I'd also save time and money cutting people that read as poorly as you're demonstrating.

Try actually measuring basic knowledge with competency at programming before thinking your opinion is better than measured data.

And yes, we tested all this carefully before enacting it. Interviews cost time and money, so giving 100% on every candidate despite quick signals is a waste of time and money that would be better spent on other candidates.

Re:Code Llama, an AI tool for coding by noduerme on Thursday August 24, 2023 @04:25PM (#37254096)
I'm mad at myself now that it has eaten 15 minutes of my time trying to come up with the right optimization. What's the trick? 2, +1, and then +2 from there on seems obvious but once you get to 9 is it worth building a list of nonprimes to skip?
Re:Code Llama, an AI tool for coding by Our_Benefactors on Thursday August 24, 2023 @04:46PM (#37254324)
https://stackoverflow.com/a/54544012/1336678

Common approach is to use square roots, this reduces the runtime. Recommend checking out project euler if you like solving hard math-code-o(n)-puzzles.

Re:Code Llama, an AI tool for coding by noduerme on Thursday August 24, 2023 @05:27PM (#37254762)
I didn't want to cheat by looking on S.O. but thanks ;)

Yes it makes sense (in the GPT code) that you'd only go up to i * i ... although looking at pythonic while: statements is just gross to me in this context, it would feel a lot more readable to say, e.g. in PHP:

for ($i=2;$i<sqrt($n);) { $i+=($i==2 ? 1 : 2); //although the first one should just be outside the loop }

Re:Code Llama, an AI tool for coding by thewataccount on Thursday August 24, 2023 @04:48PM (#37254355)
I think they're suggesting simply doing +2

+1 is not a good idea since ~half of all numbers are effectively non-prime simply by being even numbers.

You can double the speed by using +2 without using any fancy tricks, just changing a single character.

Re:Code Llama, an AI tool for coding by nojs on Thursday August 24, 2023 @08:44PM (#37256442)
Well it doesn’t double the speed, since anything with a factor of 2 undergoes only one loop iteration inside is_prime. It basically just saves a function call
Re:Code Llama, an AI tool for coding by dahfizz on Thursday August 24, 2023 @07:39PM (#37255979)
There's lots of more advanced optimizations, which would be an interesting avenue for discussion in an interview, but the drain dead algorithm would just use +2 instead of +1
Re:Code Llama, an AI tool for coding by bakuninsbart on Friday August 25, 2023 @09:50AM (#37261719)
Exactly, multiples of 2 can't be a prime, so skipping this saves a function call (that itself only does one comparison), so it is a very simple and relatively obvious optimization. But actually every multiple of a number per definition cannot be a prime, you can't just change the step size, but there are some nifty tricks to approach the problem from a different angle.