Philip ([info]bluesmoon) wrote,
@ 2003-11-14 17:18:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
Intel aptitude test?
Someone sent me this piece of code saying it was asked in an aptitude test for Intel:
   int i, n = 20;
   for(i = 0; i < n; i--)
      printf("-");

You've got to get it to print - 20 times. You may add, subtract OR replace only one character in the above code.

I'm posting my solutions as a comment, and screening it for a while.

[update]my bad, the problem was wrong. n is initialised to 20. thanks kalyan[/update]

[update 15-11-03, 19:00 IST]I should add that I've got 3 solutions[/update]



(Post a new comment)

Solutions
[info]bluesmoon
2003-11-14 03:53 am UTC (link)
1. for(i = 0; -i < n; i--)
2. for(i = 0; i + n; i--)
3. for(i = 0; i < n; n--)

(Reply to this)


[info]kalyan
2003-11-14 06:47 am UTC (link)
I think you got the problm wrong ;)

(Reply to this) (Thread)


[info]bluesmoon
2003-11-15 05:08 am UTC (link)
yes i did

(Reply to this) (Parent)


[info]mannu
2003-11-14 10:48 am UTC (link)
I gave up.

(Reply to this) (Thread)


[info]bluesmoon
2003-11-15 05:07 am UTC (link)
try again. problem statement updated

(Reply to this) (Parent)


[info]satyap
2003-11-14 02:59 pm UTC (link)
I'm about ready to give up. Is [info]kalyan right?

(Reply to this) (Thread)


[info]bluesmoon
2003-11-15 05:07 am UTC (link)
kalyan was right

(Reply to this) (Parent)


[info]jace
2003-11-15 05:01 am UTC (link)
Does "-" have to be printed exactly 20 times, or at least 20 times? If the latter, just replace the n = 0 with n = 1.

(Reply to this) (Thread)


[info]bluesmoon
2003-11-15 05:07 am UTC (link)
exactly 20 times, and it's n=20, not n=0.

(Reply to this) (Parent)


[info]kalyan
2003-11-15 05:15 am UTC (link)
I figured the answer, but wont spoil any fun for others.

I can however give an hint. Here you go :

OUt of the 3 operations, the operation what will fix the code is "replace" :)

(Reply to this) (Parent)(Thread)


[info]jace
2003-11-15 05:19 am UTC (link)
Heh. Now that's made it so plainly obvious.

(Reply to this) (Parent)


[info]bluesmoon
2003-11-15 05:24 am UTC (link)
If you post within the next 15 minutes, I'll screen it.

(Reply to this) (Parent)


[info]bluesmoon
2003-11-15 05:27 am UTC (link)
oh yeah, replace is not the only correct operation. I've found 3 solutions, and not all of them use replace

(Reply to this) (Parent)


[info]satyap
2003-11-15 06:31 am UTC (link)
Ercynpr gur v qrperzrag jvgu a qrperzrag

(Reply to this)


[info]satyap
2003-11-15 06:49 am UTC (link)
Since the previous solution is based on the hint, I had to come up with another one on my own:

Chg n zvahf fvta orsber gur v va gur pbzcnevfba

Unfortunately, we already know that there exist at least 3 solutions :-(

(Reply to this) (Thread)


[info]bluesmoon
2003-11-15 07:00 am UTC (link)
right both counts.
the third solution is the one most people (who've
finally got it) have a problem with. strangely,
it was the most obvious to me

(Reply to this) (Parent)


[info]satyap
2003-11-15 07:29 am UTC (link)
Punatr gur yrffguna fvta gb n cyhf fvta

(Reply to this) (Thread)


[info]bluesmoon
2003-11-15 08:20 am UTC (link)
and we have a winner. you think you can find anymore?

I wonder what someone reading this thread would think. Heh.

PS: \me got 3 solns in 5 mins
[Error: Irreparable invalid markup ('<wink,grin>') in entry. Owner must fix manually. Raw contents below.]

and we have a winner. you think you can find anymore?

I wonder what someone reading this thread would think. Heh.

PS: \me got 3 solns in 5 mins <wink,grin>

(Reply to this) (Parent)


[info]mannu
2003-11-15 09:01 am UTC (link)
I got the one that's pretty obvious: replace one character with another (you and I know which).

You have two more? I hope you aren't replacing one character with more than one for these.

(Reply to this) (Thread)


[info]satyap
2003-11-15 10:05 am UTC (link)
You mean like s/f/b/g; ? No. (f=foo, b=bar, in case anyone's wondering.)

Actually, gjb bs gur fbyhgvbaf vaibyir ercynpr. N guveq vaibyirf nqqvgvba bs n punenpgre. Haha, that sentence contains multiple hints!

(Reply to this) (Parent)(Thread)


[info]bluesmoon
2003-11-15 11:12 am UTC (link)
damn you satya. now I can read ROT13

(Reply to this) (Parent)


[info]satyap
2003-11-15 10:06 am UTC (link)
You mean like s/f/b/g; ? No. (f=foo, b=bar, in case anyone's wondering.)

Actually, gjb bs gur fbyhgvbaf vaibyir ercynpr. N guveq vaibyirf nqqvgvba bs n punenpgre. Haha, that sentence contains multiple hints!

(Reply to this) (Parent)


[info]fus
2003-11-15 07:14 pm UTC (link)
ok, saw the posts only now after the initial n = 0 was eating the life out of me, done with all 3

the solutions (hail caesar!)

ercynpr gur v va gur nhgbqrperzrag jvgu a

nqq n zvahf fvta orsber v va gur ybbc pbaqvgvbany

punatr gur yrff-guna gb cyhf

:-D

(Reply to this) (Thread)


[info]mannu
2003-11-16 02:02 am UTC (link)
Wow! The second and the third ones!

(Reply to this) (Parent)


[info]itsjoy
2003-11-16 09:04 pm UTC (link)
decrypt please!

(Reply to this) (Thread)


[info]bluesmoon
2003-11-16 09:08 pm UTC (link)
well, you can forget about a future in cryptanalysis. :D

(Reply to this) (Parent)(Thread)


[info]mannu
2003-11-17 12:40 am UTC (link)
Hehe... honestly, I didn't think of rot13 at first :-) It should've been obvious.

(Reply to this) (Parent)


Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…