[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
>Alright, for this next part, go up to the whiteboard and
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 157
Thread images: 6
File: Interviewer.jpg (17 KB, 350x244) Image search: [Google]
Interviewer.jpg
17 KB, 350x244
>Alright, for this next part, go up to the whiteboard and write a function that reverses an integer array in place.
>You can write it in any language you like, but you only have 10 minutes/

What do?
>>
>do it
That's what I do
>>
>>51320979
>write and compile on phone first
>copy down working solution on whiteboard when done
>>
Write
NIGGERS
and go home.
>>
>Alright, for this next part, go up to the whiteboard and write a function that solves the halting problem
>You can write it in any language you like, but you only have 1 hour/
wat do?
>>
Is this supposed to be difficult?
i := 0
j := len(arr) - 1
while i < j do
tmp := arr[j]
arr[j] := arr[i]
arr[i] := tmp
i +:= 1
j -:= 1
od
>>
>>51321029
Write it in BananaScheme
>>
Write it in Brainfuck. He'll have no choice but to believe you.
>>
arr[::-1]


Done
>>
>>51321232
disqualified
>>
>>51320979
1 minute looking it up on Stack overflow.
2.5 minutes copying it. (Messy handwriting if I write too fast.)
6.5 minutes shitposting on /g/
>>
for(int i = sizeof arr / sizeof *arr, int j = 0; i > 0; --i, j++)
__asm{ xchg arr[i], arr[j]}
>>
>>51320979
Kek it doesn't have to be efficient? Literally takes 20 seconds to do it naively.
>>
Dumb the array in a stack, fill it again from the stack.
>>
>>51321306
If you weren't a retard, you'd be able to write one out in 30 seconds.
>>
>>51321402
*dump. Shit, that was dumb.
>>
>>51320979
void reverse (int *arr)
{
int i = 0, j = sizeof(arr);
while(i < j)
{
arr[i] = arr[i] xor arr[j];
arr[j] = arr[i] xor arr[j];
arr[i] = arr[i] xor arr[j];
i++;
j--;
}
}
>>
>>51321077
>>51321402
>in place
dumb fucks. That means no temp variables, no stacks
>>
Write "a function that reverses an integer array in place." in english
>>
>>51321456
>in place
>no temp variables
That is not what that means. Doing it using O(1) space is what that means. I could use silly xor tricks to swap the two variables or use a language that will let me do both assignments on the same line (so it would grab each item first and then do the assignment) but I chose to use a temporary variable for the purpose of clarity.
>>
>>51320979
Would you hire me, /g/?
void reverse(int *arr, unsigned size) {
int tmp[size];
int a = size - 1;
int b = 0;
while (a >= 0 && b <= size) {
tmp[b] = *(arr+a);
a--;
b++;
}
a = 0;
while (a <= size) {
*(arr+a) = tmp[a];
a++;
}
}
>>
>>51321432
>sizeof(arr)
Why are you taking the size of a pointer?
>>
>>51321600
I'm too lazy to look up finding the size of an array from a pointer. I also didn't subtract 1 to get the index of the final element of arr. deal w/it
>>
Have underscore.js do it for me, whatever that is :^)
>>
File: despair.jpg (232 KB, 538x785) Image search: [Google]
despair.jpg
232 KB, 538x785
I've already been at this for 40 minutes and I still don't have a working solution.

Am I retarded?
>>
>>51321615
just feed it into the function with sizeof while it's still in scope.
>>
>>51321663
yes
public void reverse(int[] list) {
for (int i = 0; i < list.length / 2; i++) {
int temp = list[i];
list[i] = list[list.length - 1 - i];
list[list.length - 1 - i] = temp;
}
}
>>
>>51321663
wut
It's just going through the front and back of the array the same time switching out the entries and stopping when they meet in the middle. This is CS101 tier stuff man
>>
>people looping through the whole array
baka senpai
>>
>>51321503
>Doing it using O(1) space is what that means.
O(1) ADDITIONAL space. You'll need O(n) space for the original array.

But yes. Temp variables are fine.
>>
>>51321825
i tried doing that and the array mirrored itself
like..
3 2 1 1 2 3
>>
>>51321825
>>51321861
you only go through to half the array
>>
>>51321861
mate.. I don't know how to say this, but..I hope you're not looking into getting a degree in CS or mathematics.
>>
>>51321871
>stopping when they meet in the middle
Sounds like half to me
>>
>>51320979
write the integer manually.
>>
>>51321898
shut up, sperg
>>
>>51321618
>using the smiley with a carat nose
>>
>>51320979
I had a phone interview this week where I learned Ruby. They gave me a problem that would take me 1 minute to write an language I actually know, but forced me to use Ruby so I had to spend 10 minutes learning Ruby, then 1 minute writing the logic.
>>
>>51321325
>xchg mem, mem
syntax error
>>
File: 1373349990078.jpg (17 KB, 229x200) Image search: [Google]
1373349990078.jpg
17 KB, 229x200
>>51320979
Just do your fucking homework instead of /g/ doing it for you.
>>
>>51320979
while(1){
print("i'm not doing your homework for you");
}
>>
>>51320979

void doYourHomework(int ** array)
if(array)
printf("I AM A FAGGOT PS GIFT ME A DEGREE");
>>
>>51321782
>not catching values
I can't take this
>>
>>51321917
I'm just trying to get a kid to not waste his life. There's no tricks to this algorithm, and if you have to take more than 20minutes to figure it out then you probably aren't going to make it in CS.
It's the truth, a sad one
>>
>>51322269
ok autist
>>
>>51322287
Try web dev
>>
>>51322367
>YOU NEED MATH TO BE SOFTWARE DEV
sorry you wasted your life
>>
>>51322398
Like, come on
Dude
u cnt b srrs
>>
>>51322398
>YOU DONT NEED MATH TO BE SOFTWARE DEV
>>
Just walk to the whiteboard and scribble a fizzbuzz + some random stuff and pepper the code with "λ" symbols to make them impressed.
>>
>>51321029
return false, mainly
>>
>>51322542
Like this?
http://thedailywtf.com/articles/The-Fizz-Buzz-from-Outer-Space
>>
>>51321432
Can't do xor swap without a conditional. It will fail if the values are the same.
>>
Ruby:
def revarr(arr)
arr.reverse!
end
>>
>>51322848
>>> a = 5
>>> b = 5
>>>
>>> a = a ^ b
>>> b = a ^ b
>>> a = a ^ b
>>>
>>> a, b
(5, 5)

What?
>>
>>51321456
>dumb fucks
why do you do this
you know you don't know jack shit about the subject
you asked for help
people provide it
why insult them
just why
>>
>>51322264
>catching values
what
>>
void reverse_arr(int arr[], int size)
{
int i;
for(i = 0; i < size/2 - (size-1)%2; i++)
{
arr[i] = arr[i]^arr[size-i-1];
arr[size-i-1] = arr[i]^arr[size-i-1];
arr[i] = arr[i]^arr[size-i-1];
}
}
>>
#include <stdio.h>
void reverse(int *arr,int len){
int p;
int temp=0;
for(p=0;p<len/2;p++){
temp=arr[p];
arr[p]=arr[len-1-p];
arr[len-1-p]=temp;
}
}

for some reason sizeof(arr)/sizeof(int) doesn't work insise the reverse function, maybe becasue i'm passing by adress.
>>
Can't think of a way to do with in Java without temporary variables. Even assembly requires temporary registers to copy values from and to different memory units.

What form of wizardry do I have to know to do this? I can't handle being retarded.
>>
>>51323005
Look up XOR swap

Although it's shitty nowadays to use such an "optimization." Some processors actually perform bitwise operations slower than moving values through registers, and a good compiler will detect your use of temporary variables and choose what algorithm would be optimal for your target architecture anyway.

Just write code that's fucking legible.
>>
>>51323005
"in place" simply means using O(1) space.
>>
>>51321019

ROODY-POO
>>
MATLAB:
flip()

stay mad, non-science fags

:^)
>>
>>51320979
>write integer array
>hold mirror up to it

Do I get hired for being a free thinker?
>>
File: 1439784611151.jpg (9 KB, 255x234) Image search: [Google]
1439784611151.jpg
9 KB, 255x234
This isn't a meme. I've actually witnessed first-hand the absolute retardation of people in compsci courses.

>mfw my peers think printing an array backwards reverses it
>mfw the TA in the lab chews them out for being retarded while reviewing their "solution"
>mfw they start bitching about the class being hard
>mfw the TA has to go up to the board and explain this after everyone is stumped on it for two hours
>mfw I'm finished and am only still in the lab to finish next week's homework
>>
The people in CS are idiots. In a recent assignment we had to write two separate programs. The main difference between the two being that one took in a file via a command line argument and the other one read from stdin. Apparently a majority of the class thought that by "reading from stdin" they meant read the name of the file from stdin, and use that.
I shit you not, this class isn't even a freshman course.
>>
>>51320979
krsort($intarray);

I can start tomorrow.
>>
>>51323356
>krsort
>Sorts an array by key in reverse order, maintaining key to data correlations. This is useful mainly for associative arrays.

>not reverse
>not in-place
>not array

you can start flipping burgers right now
>>
>>51321663
>Am I retarded?

No. Just confirms you're a normie with a girl who gives good head, would take in hert beat.
>>
>>51320979
Ask him why he's asking me this in a position for systems administration.
>>
#!/usr/bin/bash
rev ${ARRAY[*]}


kek, I love being a sysadmin
>>
Off the top of my head.

#include <stdlib.h>

void reverse_iary(int *ary, size_t len)
{
int tmp;
const size_t l = len / 2;
for (size_t i=0; i<l; ++i) {
tmp = ary[len - i - 1];
ary[len - i - 1] = ary[i];
ary[i] = tmp;
}
}
>>
without using any xor tricks or temp variables
for i in range 0 to s/2
A[s-i] += A[i]
A[i] -= A[s-i]
A[i] = - A[i]
A[s-i] -= A[i]


looking forward to my job offers from google and Tesla soon
>>
File: krsort.png (4 KB, 187x293) Image search: [Google]
krsort.png
4 KB, 187x293
>>51323376
It did exactly what was wanted though.
#!/usr/bin/php
<?php
$intarray = array('1', '4', '7', '3', '6', '8');
print_r ($intarray);
krsort($intarray);
print_r ($intarray);

?>
>>
array.reverse()
>>
>>51323442
Not in-place, not reverse, not array.
If you find a seed using which after shuffling the array it becomes reversed, it's not a proper solution.
>>
>>51323409
Not even remotely close to in-place.
>>
>>51323449
>reverse
Kek
>>
>>51323459
I don't think you even understand the question nor the solution anon gave. Go back and flip burgers, they don't pay you to shitpost on /g/.
>>
>>51323530
His reverse is not in-place because PHP does not sort in-place, his "integer array" is a mapping of ints to strings and the operation he's doing is not called reverse - it's sort.
>>
>>51323557
I said go flip burgers...
>>
>>51320979
>What do?
Refuse to do it citing the fact that thousands of coders have already done this and it is an inefficient use of your time and would be easier and more productive for the company to work with reusable code.

Or, write it in 6502 assembly language.

Either way the kike will be fucked.
>>
>>51323564
make me
>>
>>51323565
He will just hire the next person who does not get offended when someone wants to test his capacity as a programmer.
>>
def reverse_integer_array(integer_array):
return reversed(integer_array)
>>
>>51320979
Write a curl line that navigates stack overflow and downloads the highest rated response.
>>
ArrayUtils.reverse(int[] array)


:^)
>>
def reverse(list):
i = 0
j = len(list) - 1
while i < j:
list[i], list[j] = list[j], list[i]
i++
j--
>>
>>51323579
actually, you make me a cheeseburger and some fries
>>
>>51323676
make me
>>
>>51321029
the halting problem is solved by not having input until the bootstrap forks from safe hardware initialization and then catching an aggregated processor state, and halting before critical damage can occur
the problem is generally presented with poorly defined terminology, for instance when a process is sleeping it can be considered to be 'halted' and when a computer is hibernated it is in the middle of an execution status that can (under an ideal scenario) ignore the bootstrapping of an environment before resuming computation.
to say that it is undecidable would imply there is a volatile storage medium managing hardware, something that is only optimal in a cluster of processors or when bottlenecking occurs in IO control
>>
>>51323678
actually, you make me a cheeseburger and some fries
>>
-module(reverse).
-export([reverse/2]).

-spec reverse([_], [_]) -> [_].

reverse([], A) ->
A;
reverse([H|T], A) ->
reverse(T, [H] ++ A).
>>
void array(int * array, int len)
{
for (int i = 0; i < len / 2; i++)
{
int temp = array[i];
array[i] = array[len - i];
array[len - i] = temp;
}
}
>>
File: 1443455704174.jpg (214 KB, 1920x1080) Image search: [Google]
1443455704174.jpg
214 KB, 1920x1080
include utilities // utilities that are useful

array = new array (1, 2, 3,4,5)
reversed-array = utilities.reverseArray(array)
// reversed-array should be (5,4,3,2,1)
return reversed-array
>>
>>51323679
on wikipedia they describe print("hello world") to be halting, but it is static, so unless the data pipe from processor to storage medium necessitated the use of an external timer (IE tape feeding system) there would be no instant in which the payload could be partially delivered due to some other input.
on a non turing complete computer, the program would need to be static. and incredibly meticulously described to the point where hardware breakage is the only way it would ever halt in the lifetime of said computer.


they also cite an empty while loop as being non-halting: but it sleeps immediately and cannot be woken so it is doubly self destructive and unwakeable
>>
>>51320979
God, I hate whiteboard programming.

Even with a fucking master's degree I'm asked to do this shit.

Anyway
void reverse(int* array, size_t size)
{
size_t i;
for (i = 0; ( i < (size >> 1) ) && ( i != size - i - 1 ); ++i) {
array[i] ^= array[size - i - 1];
array[size - i - 1] ^= array[i];
array[i] ^= array[size - i -1];
}
}
>>
>>51323756
>would need to be static
I meant to say
>would need to be non-static (ie self enlightened as to the specific output device's semantics)
>>
>not using functional programming to solve problem
>>
This is actually a very difficult problem that only 1/10 undergraduate students can actually solve within 10 minutes.
>>
>>51323783
in place does not mean copy it into another array you dolt
>>
>>51323349
I also thought that reading from stdin meant reading the filename from stdin. Maybe the instructions should have been clearer.
>>
>>51323800
functional does not mean immutable you dolt
>>
>>51323772
Eh, I just realized the second condition is redundant. Ignore me, I'm a retard.
>>
>>51323807
recursion does not mean functional programming
>>
>>51323800
Why do you think FP requires you to use a second array?
>>
>>51320979
b=fliplr(A)
b=flipud(A)
>>
>>51323845
to modify an array is to have a side effect.
>>
>>51323831
basically this.
function no bueno
recursion bueno
>>
Array=randomArrayGenerator.generate()
for i in range(len(Array)/2):
Array[i],Array[len(Array)-i]=Array[len(Array)-i],Array[i]

How did I do?
>>
int *container[] = null array(array.sizeof() * &Integer.length);
loop (i = 0; ++i):
container[i] *= &array[0] + array.sizeof - &&container[i].sizeof;
break while (container[container.lastindex] != null);
>>
(function(){
var cocks = reverse(["face.", "my", "rape", "please", "faggot", "huge", "a", "I'm"]);
console.log(cocks.join(" "));

function reverse(someArray){
reversedArray = [];
for(var i = 0; i < someArray.length; i++){
reversedArray[i] = someArray[(someArray.length - 1) - i];
}
return reversedArray;
}
})();

Why is everyone using temps? Am I missing something?
>>
Why does it feel like most solutions won't work properly with a simple array such as [5,3,2,4,1].
>>
>>51323974
you're not changing the 2nd half of the array
>>
>>51323672
>list[i], list[j] = list[j], list[i]
Python's nice.
>>
>>51323845
Mutability and side-effects are impure, mang.
>>
>>51323996
W-what second half?
>>
>>51323974
You are not reversing in place.
>>
>>51324026
my bad, I thought you were doing it differently. Caught up in my own head.

Anyway, some shithead's gonna come along and yell "In place"
>>
>>51323974
>reversedArray
That's not in-place.
>>
>>51323672
>i++
>j--

lol, rejected and beaten outside for wasting our time
>>
this was literally part of the second assignment in my intro CS course
>>
>>51324036
>>51324043
>>51324049
Guess I didn't get the job then
>>
>>51323672
>i++
>j--
>python
>>
NONE OF YOU GUYS HAVE DONE IT RIGHT, SO FAR ONLY >>51323705 HAS DONE IT RIGHT...
>>
>>51324036
wait, so reversing in place means working on both an nth item from the start and nth item from the end of the array( which means no need for changing actual list so we can create new lists and such?)

or does it mean the above but instead, we change the actual list?
>>
>>51323772
>>51323783
void reverse(int* array, size_t start, size_t end)
{
if (start < end) {
array[start] ^= array[end];
array[end] ^= array[start];
array[start] ^= array[end];
reverse(array, start + 1, end - 1);
}
}
>>
>>51324058
>>51324071
I was just making sure you guys were paying attention :^)
>>
>>51324086
In place means using O(1) additional storage.
>>
>>51320979
a = a[::-1]

u happy?
>>
>>51324094
explain, I'm not a CS fag (yet)
>>
>>51324081
I understood in-place as overwriting the original array in reverse order.

Nobody cares if you make a temp variable or temp array.
It's 2015.
>>
>>51324086
It means you modify the array passed in as an argument to the function.
>>
>>51324105
OP is a retard, this question sounds like the typical inteview question of you have an array and reverse it while getting the reversed sorted too.(that is "in place").
>>
>>51324102
The amount of additional storage your algorithm uses (on top of things being passed in to it) is constant. It does not depend on the size of the input.
>>
Swapping values with xor-shenanigans is harmful, don't do it. You are just going to fuck it up.
>>
>>51324136
this is /g/ here
>>
>>51324136
The kids like to look edgy than being practical. Sooner or later they will know that it isn't useful at work.
>>
>>51324146
>>51324136

>isn't useful
Wrong, it's very useful when you have to get used to code obscurification.

http://pastebin.com/GQPnUi7d
>>
>>51324163
AT WORK, and I don't think anyone here or most WORKS with such things, jesus...
>>
>>51324173
>no one works with malware detection, self-modifying code etc
>>
>>51324178
Am I supposed to expect /g/ to be working with such?
>>
void reverseArray(int * arr, int len) {
int i = 0;
int j = len - 1;
int tmp;

while (i < j) {
tmp = arr[i];
arr[i++] = arr[j];
arr[j--] = tmp;
}

}


this is what interviewers are looking for. If you swap your values using the xor autism trick, your power level will undoubtedly be revealed and you won't be called back
>>
>>51320979
>any language you like
A = A[::-1]
>>
>/g/ actually having problems with reversing an array

Topkek, it's CS 101
>>
>>51324182
Plenty of people here work as penetration testers, anti-virus software engineers and stuff like that. And a typical interview question for a company doing that line of work would be figuring out why >>51324163 does what it does.

Not everyone ITT is a sophomore CS student you know :)

>>51324185
>XOR atuism
>implying it isn't one of the most known in-place swap algorithms known
When I interviewed at Microsoft for normal entry level programming stuff, I was actually asked how I would swap to integers without using a helper variable. Guess which solution they wanted.
>>
>>51324127
im still confused, does that mean the algorithm can work with a constant size of a subarray at a time, and then it proggressively reduces the array?
>>
>>51324210
Yeah of course, silly me everyone in /g/ who posts anime shit, crossdressing faggotry and etc. Are in fact security engineers or senior devs with more than 20 years of real life experience, I am sorry.
>>
>>51324215
In layman's terms it means that you don't copy values from one array to another (albeit in different order), it means that you work on the same array "in place".

Basically you do something like this:

for (int i = 0, j = size - 1; i < size / 2; ++i, --j)
{
int temp = array[j];
array[j] = array[i];
array[i] = temp;
}
>>
>>51324226
You do know that just because one type of people post in one type of threads, that doesn't mean that another type of people doesn't post in another type of thread.

/g/ supposedly being full of NEETs and CS students is just as much a myth as /b/ supposedly being filled with social rejects and transexuals.
>>
>>51324237
reverse [1,2,3,4,5]
>>
>>51322893
probs meant caching
>>
>>51324269
[5, 4, 3, 2, 1]
>>
>>51324210
>>implying it isn't one of the most known in-place swap algorithms known
>implying I implied that

>I was actually asked how I would swap to integers without using a helper variable
>to
They literally asked you if you knew the autism xor trick. Congrats on reading CTCI before your interview, buddy.

That's different than pulling it out of your ass while reversing an array. Sure, it can't hurt to mention it as a side note, but your average software engineering role doesn't need those NEET tricks
>>
>>51324136
Never once has it caused an issue for me. It was incredibly useful in a small embedded computer vision application I wrote.
>>
reverse l =  rev l []
where
rev [] a = a
rev (x:xs) a = rev xs (x:a)
Thread replies: 157
Thread images: 6

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.