← Home ← Back to /g/

Thread 105718989

56 posts 12 images /g/
Anonymous No.105718989 [Report] >>105719014 >>105719037 >>105719071 >>105719134 >>105719149 >>105719211 >>105719265 >>105719300 >>105719303 >>105719334 >>105719513 >>105721762 >>105721973 >>105722149 >>105722403 >>105726003 >>105726040 >>105726052
90% of /g/ will get this wrong
Anonymous No.105719014 [Report] >>105719056 >>105725380
>>105718989 (OP)
You don't need to reverse a word to check if it's a palindrome what is this brainlet nonsense
Anonymous No.105719037 [Report]
>>105718989 (OP)
>Wordswordswords
Anonymous No.105719047 [Report]
B. What do I win.
>inb4 tranny porn
Anonymous No.105719056 [Report] >>105719099 >>105719123
>>105719014
If you don't reverse it how do you know it's a palindrome?
Anonymous No.105719071 [Report] >>105719143 >>105726054
>>105718989 (OP)
Pro tip: Always use the option with less nesting.
Anonymous No.105719099 [Report]
>>105719056
by asking kindly
Anonymous No.105719123 [Report] >>105719192
>>105719056
i=0
k=s.length
While(i<k)
if(s[i]!=s[k])
return false
i++
k--
return true
Anonymous No.105719134 [Report] >>105719146 >>105719259 >>105719310
>>105718989 (OP)
All 3 solutions are dogshit
You are not hired, you're brown.
Anonymous No.105719143 [Report] >>105719161
>>105719071
>blocks your path
Anonymous No.105719146 [Report] >>105719163 >>105719192
>>105719134
I don't think your implicit claim, that only people who come up with the most optimized solution to a problem are the ones who get hired, is true
if that was the case software would be way less shitty than it is now
Anonymous No.105719149 [Report]
>>105718989 (OP)
because empty array is undefined?
Anonymous No.105719156 [Report]
i can't remember the exact method, but isn't there a way to use modulus to quickly check for a palindrome? it has to do with isolating each character position and then checking for symmetry directly.
Anonymous No.105719161 [Report]
>>105719143
>dart
God no... Please no !!!
Anonymous No.105719163 [Report]
>>105719146
This anon gets it. Fire everyone, and let the AI take over.
Anonymous No.105719192 [Report] >>105719242 >>105719252
>>105719146
I know as hell I wouldn't let me boss hire you.
You see, a lead dev is always present when hiring someone new to our team, in this case it would be me and sure as hell, I wouldn't accept any of OP's shitty solutions.

I would however accept his (but whit one less variable):>>105719123
Anonymous No.105719211 [Report]
>>105718989 (OP)
This is part of a recruitment process for a literal pyramid scheme. OP is a retard bragging about being scammed.
Anonymous No.105719242 [Report] >>105719367 >>105719412 >>105719748
>>105719192
Ah yes, you could do
i=0
While(i<s.length-i)
if(s[i]!=s[s.length-i])
return false
i++
return true
Is that actually better tho? You have to dereference s.length every iteration. I suppose it gets cached tho
Anonymous No.105719252 [Report] >>105719276
>>105719192
i = 0;
while (i <= trunc(s.len))
if (s[i] != s[s.len - i - 1])
return false;
i++;
return true;
Anonymous No.105719255 [Report]
>interview questions for ants

The craziest thing is you can earn way more money in other white collar jobs and the interviews are never this retarded

The whole our company is the most elite dance for us monkey shit gets old real quick after you do enough of them

What you eventually get is that everyone is trying to hide the fact that the job is fuck easy and there’s so many people banging on every door that it’s completely a mistake

That a ton of these people have nothing else they’re good at in life or going on that they enshrine CRUDing as some awesome thing
That other code “smells” or some shit

It’s dickwaving by small people who would get crushed in any real situation
A fucking corner boy fent dealer could steamroll everyone in the room in real life

It’s a job for losers and pussies
Anonymous No.105719259 [Report] >>105719534
>>105719134
AI doubters are getting so btfo these days it's actually incredible. That is nuts.
Anonymous No.105719265 [Report] >>105719325
>>105718989 (OP)
leave it to /g/ neet retards to completely miss the point of this question and jerk themselves off over their "optimized" solutions instead. you would all fail this question miserably.
Anonymous No.105719276 [Report]
>>105719252
fix:
while (2*i < s.len)
Anonymous No.105719296 [Report] >>105719569
but 'racecar' should be True
Anonymous No.105719300 [Report]
>>105718989 (OP)
In Python this is just
def Check_Palindromes(word_list):
return all(word == word[::-1] for word in word_list)
Anonymous No.105719303 [Report]
>>105718989 (OP)
Can confirm
>t. Got it wrong 9 times out of 10
Anonymous No.105719310 [Report] >>105719324
>>105719134
Anonymous No.105719324 [Report] >>105719472
>>105719310
AI is getting weird
Anonymous No.105719325 [Report] >>105719422
>>105719265
I mean, most well-equipped high-level languages will have a reverse() method and an all(condition) method. The task is trivial.
Low-level languages will require manual implementation just like what the neets here are doing.
Anonymous No.105719334 [Report]
>>105718989 (OP)
Option C is the longest, so it's obviously the most correct.
Anonymous No.105719367 [Report]
>>105719242
>it gets cached ?
Yes, either runtime optimizer (in case of jit) or the compiler will sort that out.
Anonymous No.105719412 [Report]
>>105719242
>You have to dereference s.length every iteration
If you're that concerned about it, you could store it in a stack variable.
Anonymous No.105719422 [Report] >>105719457
>>105719325
The point is that you should be able to recognize that only one of them works with any number of words while the other two only work for exactly three.
Anonymous No.105719457 [Report] >>105719463 >>105719487
>>105719422
Since when "best practices" means "find the one option that actually functions"? Besides, the only correct one has a bad of cleancodeitis.
Anonymous No.105719463 [Report]
>>105719457
*case
Anonymous No.105719472 [Report]
>>105719324
always has been
>deep dream
Anonymous No.105719487 [Report]
>>105719457
>Since when "best practices" means "find the one option that actually functions"?
It's a best practice to write code that works.
Anonymous No.105719513 [Report]
>>105718989 (OP)
Solution 4: don't ask AI and code it yourself.
Anonymous No.105719534 [Report] >>105719550
>>105719259
Soon, the entire movie industry will shift to Ai aided content
Anonymous No.105719550 [Report]
>>105719534
That would probably improve the quality over what it shits out now.
Anonymous No.105719569 [Report] >>105719589
>>105719296
You've failed the interview due to being illiterate. Congratz.
Anonymous No.105719589 [Report]
>>105719569
OP was right, 90% is wrong.
Anonymous No.105719748 [Report]
>>105719242
It depends on what exactly your code looks like. If you're using strlen() on C-style char* strings it actually might fail to cache but not in this example since you're just doing pure stuff locally. In any case, caching strlen() into a temp variable is free since it's more or less the same as you directly telling the compiler to cache it.
Anonymous No.105721762 [Report]
>>105718989 (OP)
>reversing a string to check for palindromes
An Indian (AI) wrote this.
Anonymous No.105721903 [Report]
Option B seems perfectly fine to me. Yeah, checking the existing string for palindromitude in-place character by character is faster, but this version is more obvious, which is usually more important if not specified otherwise.
Anonymous No.105721973 [Report]
>>105718989 (OP)
>Pseudocode
There is no correct answer. You can't evaluate the efficacy of something that doesn't function.
Anonymous No.105722085 [Report]
B is clearly the best answer of the 3, the others are pajeet i fear for loops level of shit

Not that the best of the three is the most optimal
Anonymous No.105722149 [Report] >>105722423
>>105718989 (OP)
Get what wrong? There is no question, just an observation of how "AI" handles a programming request
Anonymous No.105722403 [Report]
>>105718989 (OP)
>hur dur let's put the helper functions at the top
no fuck you every ide worth their salt can quickly jump between call site and declaration. all of these solutions belong in the trash
Anonymous No.105722423 [Report]
>>105722149
have you ever been to a school?
Anonymous No.105725380 [Report]
>>105719014
This is the only valid answer.
Anonymous No.105725812 [Report]
def are_all_palindromic(arr):
def reverse_str(s):
if s == "":
return ""
else:
return reverse_str(s[1:]) + s[0]

def is_palindrome(el):
s = str(el) # Convert to string
n = len(s) # Number of characters

# Check for edge cases
if n == 0:
return True # Empty string
elif n == 1:
return True # Single character
else:
# Check for base case
first_last_match = (s[0] == s[-1])
inner_check = is_palindrome(s[1:-1]) if n > 2 else True
reversed_full = reverse_str(s)
full_match = (s == reversed_full)

midpoint = n // 2
first_half = s[:midpoint]
second_half = s[n - midpoint:]
reversed_second = reverse_str(second_half)
half_match = (first_half == reversed_second)

# Return final result
return first_last_match and inner_check and full_match and half_match

i = 0
# Check if all elements are palindromic
result = True
# Copy array
arr_copy = arr[:]

# Iterate through array
while i < len(arr_copy):
current = arr_copy[i]

check1 = is_palindrome(current)
check2 = (str(current) == str(current)[::-1])

if check1 == check2:
result = result and check1
else:
s = str(current)
mid = len(s) // 2
valid = True
for j in range(mid + 1):
# Check if first half is equal to second half
if j < len(s) and (len(s) - 1 - j) >= 0:
# Check if characters are equal
if s[j] != s[len(s) - 1 - j]:
# Set valid to false
valid = False
result = result and valid

i += 1

return result
Anonymous No.105726003 [Report]
>>105718989 (OP)
Ok. What's the question?
Anonymous No.105726040 [Report]
>>105718989 (OP)
all fail. the instruction was to return True or False, not true or false
Anonymous No.105726052 [Report]
>>105718989 (OP)
sigh.
Anonymous No.105726054 [Report]
>>105719071
This is the best and concise answer. Nesting is a nightmare to deal with.