This Slack discussion by , Oliver N and Arvin Kushwaha occurred in slogging's official #programming-challenges channel, and has been edited for readability.
In the least amount of lines in your preferred language, build a recursive function that calculates the prime numbers. Bonus points mostly to number lines and also to a system where recursion doesn't fault.
Dane Lyons
Oliver N
my one line js 😄const f = (n, x) => x === undefined ? f(n, n - 1) : x > 1 ? n % x !== 0 && f(n, x - 1) : true;
Oliver N
console.log(f(2))console.log(f(3))
console.log(f(4))
console.log(f(5))
console.log(f(6))
console.log(f(10))
console.log(f(13))
Hilariously man I was gonna say no js trickery
Thot that was anti my ethos hah
Oliver N
haha, why 😄 That was quick! Are you looking for work and what other languages you work in
Oliver N
I'm working mostly in Go and JS I love node. Never figured out go.
Go is compiled tho ya? Fast?
Oliver N
yes, compiled, and fast Yeah we looked at that or rust to get our cycles down. Both confuse me
Didn't answer q tho do you have much free time? My company is ostensibly giving me my offer in the next 1-2 weeks after we finalize the fund in caymans. I offered to cut my salary if we could give it to what we've been affectionately calling a 'real dev'. I'm great at POC and shipping but am entirely self taught, untested, procedural and.. well.
Yes, we know the color scheme sucks
I mixed up ostensibly and allegedly. Ha!
Oliver N
how about part-time? Would probably do the trick yeah. You just did in a few minutes what would have taken me hours. Does that one liner fault ever?
And do you have much experience with trading systems? Crypto exchange apis?
Oliver N
yeah, maybe, I haven't test it with any input other than number, also maybe it will fault with JS infinity We have some other candidates but yeah do send your resume maybe or linkedin here or pm? Forward to ceo
Oh yeah no no worries on bad input, I meant as increasing
Utsav Jaiswal David Smooke looks like your new product may have done what months of searching including your new partners on jobs.hackernoon didn't ;)
Arvin Kushwaha
When you say recursive function that calculates the prime numbers, do you mean returns a sequence of prime numbers or checks if the number is prime? Very good point, my original idea was indeed to return the sequence of primes. When the original answer was posted I chaulked up the disconnect to miscommunication and a failure in directions :)
Arvin Kushwaha
Well, in that case, here's my answer in Pythong = lambda x: (print(x) if not any([x%i == 0 for i in (range(2, x) if x < 10 else range(2, int(x**0.5)))]) and x >= 2 else False) or g(x+1)
g(0) # Or any number you wish to start fromOf course, it does have the limitation of recursive depth...
Is also the reason I made a bonus point about faulting. Any idea when the recursive depth would fail? Does it vary?
Arvin if you don't mind and you'd wanted to be considered can you send linkedin github or whatever via pm?