this post was submitted on 21 Dec 2024
72 points (93.9% liked)

Fun Loops ▶️

315 readers
300 users here now

Posting interesting/cool/funny videos from Loops here

https://loops.video/

Thanks to @Bluefruit @lemmy.world for the icon and banner!

Discussion of and questions about Loops should go over in !loops@lemmy.world

If the loop you're posting isn't original content uploaded by the creator, prefix the title with [R] for "reposted". For example, [R] Cute dog.

Rules:

  1. Don't be a dick
  2. Don't make me add more rules

founded 1 month ago
MODERATORS
top 35 comments
sorted by: hot top controversial new old
[–] PhilipTheBucket@ponder.cat 23 points 6 days ago (1 children)

For-loop even number guy can get lost. Sleep-sort guy I would at least be interested to see the rest of the test. As long as he has an awareness of when not to do that kind of thing in production code, it actually might indicate he has some ability.

[–] aberrate_junior_beatnik@midwest.social 4 points 5 days ago (1 children)

For-loop even number guy can get lost

I don't get this. Who cares if they forgot or just didn't know the better solution? They were able to solve the problem under pressure, even if not in the most optimal way. They even remembered to handle the negative case, which is straight up a good sign (no pun intended). And while it's slow, it would honestly still be fine to use in production anywhere you'd use typescript, as long as it's not in a hot spot.

In my mind this tells me approximately as much about the programmer as if they wrote it using modulo.

[–] PhilipTheBucket@ponder.cat 7 points 5 days ago

It's really just not a good solution. It's more complex, it's way slower, it shows they're not familiar with stuff they really should be familiar with.

Anyone who struggles to write a function to determine evenness of a number, and has to throw in some crazy solution to be able to make it across the finish line, is going to really struggle with real production code. They're going to produce stuff that's going to make everyone's job a lot more difficult.

return (x % 2) == 0;
return (x & 1) == 0;
return (x / 2 * 2) == x;
return x/2 == (x+1) / 2;

You can come up with unusual solutions and it can be fine. You can't come up with cockamamie solutions, that's why you're doing the test.

[–] ptz@dubvee.org 19 points 6 days ago* (last edited 6 days ago) (2 children)

Good news: The Loops embed feature has moved to beta.

https://tesseract.dubvee.org/c/loops@midwest.social

If anyone is willing/able to test through the hosted instance (linked above) and submit any bugs they may encounter, it would be greatly appreciated :)


On the array sort....that is clever but it doesn't return those values to something you can use; it just sorts them on screen. I respect the cleverness, but yeah, not useful.

On the array sort…that is clever but it doesn’t return those values to something you can use; it just sorts them on screen. I respect the cleverness, but yeah, not useful.

This is not the reason it isn't useful. The function could just as easily modify an array as print; you could also keep a list (or an atomic integer if that functionality is available) of which have been sorted and spin until it shows that every member has been sorted. Taking n milliseconds to sort an array whose highest element is n, with the cost of all of the thunks, plus the potential for a (very rare) race condition... not so great.

Regardless, I'd hire either of these programmers if there weren't red flags elsewhere.

[–] m_f@midwest.social 4 points 6 days ago (1 children)
[–] Cris_Color@lemmy.world 5 points 6 days ago* (last edited 6 days ago) (1 children)

Hey, is there any chance it might make sense to slow down the rate at which loops are posted?

I really enjoy seeing them on my feed, but if I'm subbed to the loops comm it just floods literally everything else and every other post is a loop with a vertical thumbnail twice the height of other posts. Edit: just checked and it's actually several loops for every other post 😅

If it's not something that makes sense for the comm that's fine, I just wanted to ask :) engagement seems like it might also be a bit higher with a more limited selection of posts

Hope you have a lovely day :)

[–] m_f@midwest.social 4 points 6 days ago (1 children)

Thanks for the feedback! Would it help if I used something like schedule.lemmings.world to spread the posts out over the day?

[–] Cris_Color@lemmy.world 2 points 6 days ago* (last edited 6 days ago) (1 children)

I think that would help a lot! There are just so many of them in quick succession that it's really easy for them to drown out all the other stuff I'm subscribed to

Thanks for the work you do running this community and posting stuff for folks, it's appreciated :)

[–] m_f@midwest.social 1 points 4 days ago (1 children)

I'm trying out Lemmy Schedule, how has the frequency been with that?

[–] Cris_Color@lemmy.world 2 points 4 days ago* (last edited 4 days ago)

It feels better to me, on my feed I'm seeing a couple loops bunched together, and then a fair number of other posts in between those bunches, so it feels much less like my feed is being drowned out

I think the real solution to this problem would be some sort algorithms that do a better job of prioritizing small communities, and that don't allow one comm to drown out others if it's really active, but short of that, your change seems to have helped :)

Thank you so much for being receptive to my thoughts! I really appreciate the work you do that contributes to lemmy being a place worth going ❤️

[–] astrsk@fedia.io 13 points 6 days ago

That sort is pretty bonkers. I agree with the no hire because it doesn’t really display an understanding but if I got that as an answer in a technical interview, it would be fun to dive into why that code was written and might turn into a hire if we peer just a bit deeper under the hood of the thinking. This is why “solve for x” technical questions suck unless you make the actual interview about the back and forth. Assume a correct premise if it works and tweak and change and poke and prod to really sus out if they understand what and why that was written.

[–] Cris_Color@lemmy.world 10 points 6 days ago

That's honestly so cool lol. Fun to see logic problems solved in really inventive ways

[–] rowanthorpe@lemmy.ml 7 points 5 days ago

const isEven = (n) => !(n & 1)

[–] TootSweet@lemmy.world 7 points 6 days ago (2 children)

I don't have any interview stories. Alas, I've only given a couple of interviews. (Or maybe rather fortunately I've only given a couple of interviews, depending how you look at it.)

But I do remember a first code review for one guy. Dude implemented his own bubble sort rather than using a sort method from the standard library. Aside from that one interesting choice, he was a good coder as I recall. He's a manager now.

[–] m_f@midwest.social 5 points 6 days ago

I did a review of someone's code submission once where they pretty much wrote a bespoke JQuery implementation to handle the super-complex task of incrementing a number in a div when a button is pressed. I don't think they got the job. I felt a little bad for them, but a valid part of those coding interviews is "Will this person go off and do something crazy like write their own half-baked React instead of just using React?". Showing that you know how to write code as simply as possible is a big plus.

[–] astrsk@fedia.io 3 points 6 days ago (1 children)

I have yet to administer or discuss interviews where using an api was an acceptable answer. Granted my experience is more on the engineering side but it seems odd to me to not expect someone to implement their own algorithm. If they had 60 seconds to answer a multiple choice technical question on a prescreen online test, maybe. But it seems that person demonstrated their understanding on a technical level that should have been expected and explored?

[–] TootSweet@lemmy.world 2 points 5 days ago (1 children)

Oh. Oh no. You misunderstand. My story was about one of the first pull requests a guy opened after he was hired. He put his home-grown bubble sort in code that would have ended up in production in an e-commerce application had I not pointed him to the sort functionality in the standard library.

[–] astrsk@fedia.io 3 points 5 days ago

Oh my, I definitely missed something when reading lol. That’s insane behavior! I hope he learned from the mistake.

[–] KurtVonnegut@mander.xyz 5 points 6 days ago (1 children)

Why does the sort one work? 🤨

[–] ScreamingFirehawk@feddit.uk 15 points 6 days ago (1 children)

It doesn't, the array is still in the same order it started in, it's members are just printed to the console in numerical order.

It just prints the number 1 after 1 ms, 2 after 2 ms, 3 after 3 ms etc.

[–] Randelung@lemmy.world 7 points 5 days ago

Instead of print you could add them to a second array, though. Even clear the original first for "in place" sorting; never mind the memory allocation for the lambdas.

[–] Orbituary@lemmy.world 1 points 6 days ago

Sorry, but, I think all my coding would go out the window and I'd start making some nonsense up if she was interviewing me.

[–] Kraiden@kbin.earth -3 points 6 days ago (4 children)

I'm sorry, but even without knowing about the mod operator, this is inefficient and over engineered. Why have a loop at all?

fun isEven(n: Int){
    return n == abs(n)
}

no loop required...

having said that, I can totally see how that was missed in a high pressure interview. I hate interviews like that!

edit: Ha ha... isEven...not isPositive... I'm tired. ignore me!

[–] lobut@lemmy.ca 11 points 6 days ago* (last edited 6 days ago) (1 children)

Because the abs(3) == 3 is true and that isn't even.

An even number of flips would be true and an odd number of flips would be false which works out.

I was thinking a bitwise & or converting it to a string and testing if the right most character is 0, 2, 4, 6, 8 would be panic mode solutions too.

[–] Kraiden@kbin.earth 2 points 5 days ago (1 children)

you might be able to do it with a bitwise op? My track record tonight is not great so I'm not going to comment. Have a look at @ImplyingImplactions comment for a loopless solution

[–] UID_Zero@infosec.pub 2 points 5 days ago

Bitwise and with 0x1. If result is 0, it's even. Least significant bit is always 1 for odd numbers.

[–] braindamagebuddy@lemmy.world 9 points 6 days ago (1 children)

Lol I think the interview pressure got to you.

[–] Kraiden@kbin.earth 6 points 5 days ago

Ha ha ha, yup... whoops!

[–] ImplyingImplications@lemmy.ca 8 points 6 days ago (2 children)

That would be isPositive.

Without using the modulo operator you'd essentially have to reimplement it. Divide the number by 2 and round down. Multiply that by 2 and then subtract it from the original number.

isEven(10) results in 10-10==0 (true) whereas isEven(13) results in 13-12==0 (false).

function isEven(n){
  n = Math.abs(n)
  return (n - (Math.floor(n/2) * 2)) == 0
}
[–] Kraiden@kbin.earth 5 points 5 days ago

Yep! I'm wrong. Pretty embarrassing!

That's a nice solution though! Gonna have to try and remember that one!

[–] dream_weasel@sh.itjust.works 4 points 5 days ago* (last edited 5 days ago)

Minor simplification: this works even without taking absolute value first of you use fix instead of floor.

Edit: I don't know if fix is in the stock math library on second thought...

[–] petrol_sniff_king@lemmy.blahaj.zone 8 points 6 days ago (1 children)

I'm not following.
n == abs(n) only tells you if it's positive.

[–] Kraiden@kbin.earth 6 points 5 days ago (1 children)

yes, I'm being a dumb tonight. I'm completely wrong

Haha, s'all good, yo.