[Show all top banners]

A_GuY
Replies to this thread:

More by A_GuY
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 Solve this
[VIEWED 8563 TIMES]
SAVE! for ease of future access.
Posted on 06-15-16 9:06 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Programming Puzzle - hot question asked in interview

http://www.gufgaaf.com/Page/DisplayThread?threadId=5
 
Posted on 06-15-16 9:50 PM     [Snapshot: 75]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Easily can be done since modifying for loop is allowed. Just have i<101 and increase i by i=i+1 and print i.

But this can be done without modifying the For loop. Just print ("1","2","3"......."100");

:)
 
Posted on 06-15-16 10:14 PM     [Snapshot: 96]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Yeah. But that prints 1 to 100 but we have to print 100 to 1.
 
Posted on 06-15-16 10:15 PM     [Snapshot: 100]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

try this as well -

http://gufgaaf.com/Page/DisplayThread?threadId=13
 
Posted on 06-15-16 11:04 PM     [Snapshot: 140]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Set I to 101 and decrease I to 1 or something like that.
 
Posted on 06-16-16 5:58 AM     [Snapshot: 217]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

i'd do this in scripting for similar needs -

I think the question asked to print 100 to 1:

for(i=100; i>0; i--) {
console.log(i);
}

and if you wanted 1 to 100:

for(i=1; i<101; i++) {
console.log(i);
}

wish all interview questions were as lame.
 
Posted on 06-16-16 7:21 AM     [Snapshot: 260]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

@ghogay_moro
Oops thats wrong.-
everything needs to be done within
for(var i=0){
}
you cant start another for loop outside closing parenthesis. and you can't print 1 to 100.
 
Posted on 06-16-16 7:43 AM     [Snapshot: 290]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

for(var i=0; i<100; i++) {
console.log(100-i);
}

 
Posted on 06-16-16 9:26 AM     [Snapshot: 368]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

c864916 - you got it.


 
Posted on 06-16-16 9:46 AM     [Snapshot: 389]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

a_guy, i think i am not seeing the obvious. care to explain a bit how my for loop is "starting" outside  either parentheses? not trying to be a deek, but just trying to understand which part of the question i misread. cheers!
Last edited: 16-Jun-16 09:47 AM

 
Posted on 06-16-16 9:58 AM     [Snapshot: 412]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

This is super basic. Calling it a Puzzle, itself is a Puzzle. Lol.
 
Posted on 06-16-16 10:27 AM     [Snapshot: 442]     Reply [Subscribe]
Login in to Rate this Post:     1       ?     Liked by
 

@ghogay_moro: What I understood was that the initializer expression should be limited to var i = 0. @A_GuY: Correct me if I am wrong.
@fuckeetow: Yes, it's pretty straightforward. The only confusion folks had was with the initializer constraint.
 
Posted on 06-16-16 11:01 AM     [Snapshot: 480]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

thanks c88.., for the explanation. i can now wrap that in my head. the original question should have asked just that!

side note: talking about interviews, i once helped prepare a question for an interview - to come up with a typewriter effect via ActionScript (Flash was a thing then!), and he didn't waste more than 3 minutes to complete it. it takes me more than 3 minutes to just think through the problem. some people really are good at what they do!
 
Posted on 06-16-16 11:26 AM     [Snapshot: 508]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Thanks guys for participating..
 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 90 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
Toilet paper or water?
and it begins - on Day 1 Trump will begin operations to deport millions of undocumented immigrants
Tourist Visa - Seeking Suggestions and Guidance
From Trump “I will revoke TPS, and deport them back to their country.”
I hope all the fake Nepali refugee get deported
advanced parole
Sajha Poll: Who is your favorite Nepali actress?
ढ्याउ गर्दा दसैँको खसी गनाउच
To Sajha admin
Problems of Nepalese students in US
Mamta kafle bhatt is still missing
अरुणिमाले दोस्रो पोई भेट्टाइछिन्
MAGA denaturalization proposal!!
Are Nepalese cheapstakes?
Nepali Psycho
How to Retrieve a Copy of Domestic Violence Complaint???
wanna be ruled by stupid or an Idiot ?
All the Qatar ailines from Nepal canceled to USA
MAGA मार्का कुरा पढेर दिमाग नखपाउनुस !
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters