Skip to main content
gamedev.net
🔒 Locked

Programmer Exam Question

Started by snowball123 91 replies 6k views
Original Post
snowball123
snowball123
I recently requested the programmer exam from Gearbox''s site. I''m missed this question and I''m wondering if somebody knows the answer. Here is the question. 1. Rewrite the following function so that the following conditions are satisfied: A) the multiplication operator (''*'') is not used. B) the division operator (''/'') is not used. C) the function does not make use of loops. D) And no sneaky using assembly either! int MultiplyBy321(int value) { int rslt; rslt = value * 321; return rslt; }
snowball123
snowball123
I''m thinking recursion because I failed at properly using shift operators.
Neophyte
Neophyte

  
int MultBy321 ( int value ) {
return (value<<8) + (value<<6) + value;
}


-Neophyte
darookie
darookie
quote:
Original post by snowball123
I''m thinking recursion because I failed at properly using shift operators.

Then think again. It can be done easily with two bit shifts and two additions.
korybricker
korybricker
int MultiplyBy321(int value)
{
int rslt;

//rslt = value * 321;
rslt = (value << 8) + (value << 6) + value;
return rslt;
}
snowball123
snowball123
Wow, very impressive everybody!
snowball123
snowball123
A few small questions!

1.) How long did this problem take you to solve?
2.) Difficulty (Easy, Medium, Hard)?
3.) How did you approach this problem?
snowball123
snowball123
I just tried it with 123 and I got the hang of it. Thanks for help because its helped me alot.
BBlodgett
BBlodgett
You could also unroll a loop.. Slow and silly I know but it works. The bit shifts are much better.

int MultiplyBy321(int value)
{
return (value+
value+
value+
..... 321 times);
}
www.brightbug.com
Extrarius
Extrarius
quote:
Original post by snowball123
A few small questions!

1.) How long did this problem take you to solve?
2.) Difficulty (Easy, Medium, Hard)?
3.) How did you approach this problem?


1) As soon as I read the problem, I knew the answer (Even the first time I read it when I asked for the exam from GearBox)

2) Very, Very Easy

3) I remebered doing those kind of optimizations in the ''old days'' (when dos was popular and mode 13h was lots of colors =-)

----------
Almost typo-ified using Extrarius'' AUTOMATIC Typo Generator, but I decided to be nice =-)
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
GekkoCube
GekkoCube
I took a number of programmer''s tests for a few game companies...although i never made it in (yet), I learned a bit, just a bit.

One of my questions, which i totally BS''ed and spin-doctored to the point of being a complete liar was a question about how to manage voice commentary in a football game as well as some ways to implement a replay system for it.

Again, I had no earthly clue. I couldnt do it if my life depended on it. To put it plain and simple - I felt quite dumb. In fact, comparing myself to many other programmers who excel (and not to mention "made it into the business") I still feel quite dumb.

So i guess what im asking is, how would ya go about implementing (in theory) the replay and sound management system for a sports title?
cwarwick
cwarwick
To do the replay system you need to set the game up to record what keys are pressed and released and at what time since the replay started and also the state of the game from when you want to start the replay, then play the game back from the saved state, but instead of using the controller (or keyboard) you use the recorded keys.

You need to be a bit careful of the framerate, if the framerate is lower than when recorded then your gonna miss times that the keys were pressed, eg key ''z'' was pressed at time 298, but the slow frame rate moves you from time 295 to 302, so you do the update for the previous key combo using the time 295->298, then do the current key combo for the time 298->302.

Fairly simple to implement.

As for managing the commentry, well I personally think thats a very broad question, what are they exactly talking about, how to manage the memory, when it''s played, how its broken up, etc etc.


Black Edge Games

biovenger
biovenger
A more smooth way to implement replays without any framerate loss is to actually record each coordinate of each object every frame. This is good for sports games since you don''t have 100+ objects. It also fixes the framerate problem, so what you do in a replay is just play a sequence of coordinates and animations for the objects ingame.

-----------------------------
Final Frontier Trader
-----------------------------Final Frontier Trader
Skizz
Skizz
The best interview question I''ve seen (and, thankfully, didn''t ever get at an interview) is:

Write a function to pick one random element from a stream of items containing an unknown number of elements, the stream terminating with an EOF marker. The function is to be used in an embedded system with very limited memory - malloc and free are not available and there is insufficent space on the stack to store an instance of the element. The stream of items can only be read once and file pointer manipulation is not permisible.

The function prototype is:

int pick_random_item (item_type *const selected_item, FILE *const input_stream);

The function should return 0 if there were no items in the stream and no-zero if an item was selected.

Skizz
biovenger
biovenger

  
int pick_random_item (item_type *const selected_item, FILE *const input_stream)
{
// temporary variables

int size = 0;
int numitems = 0;

// checks the size of the file for calculations

fseek(input_stream, 0, SEEK_END);
size = ftell(input_stream);

// sanity-check for item amount

if(size < sizeof(item_type))
return 0; // no items in stream


// randomize a number, first calculate number of streams

numitems = size / sizeof(item_type);

// call randomize function, seed() already called

fseek(input_stream, (rand() % numitems) * sizeof(item_type), SEEK_SET);

// read the item and store it into the pointer

fread(selected_item, sizeof(item_type), 1, input_stream);

// return non-zero

return 1;
}


Might that work or did I miss a criteria? I''m not that good at these things, but it''s damn fun to try. Heh.

-----------------------------
Final Frontier Trader
-----------------------------Final Frontier Trader
Skizz
Skizz
No, that breaks the criteria because:

quote:

The stream of items can only be read once and file pointer manipulation is not permisible.



which rules out fseek.

Think of it as a serial link with data being sent down the link, mapped to a FILE implementation the can read n bytes at a time, and once read, the data cannot be re-read.

Skizz

[edited by - Skizz on February 28, 2003 7:24:32 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.