[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 8597 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 365 days
Recommended Popular Threads Controvertial Threads
शीर्षक जे पनि हुन सक्छ।
डीभी परेन भने खुसि हुनु होस् ! अमेरिकामाधेरै का श्रीमती अर्कैसँग पोइला गएका छन् !
What are your first memories of when Nepal Television Began?
Sajha Poll: नेपालका सबैभन्दा आकर्षक महिला को हुन्?
ChatSansar.com Naya Nepal Chat
NRN card pros and cons?
TPS Re-registration case still pending ..
Basnet or Basnyat ??
TPS Re-registration
निगुरो थाहा छ ??
Nas and The Bokas: Coming to a Night Club near you
Toilet paper or water?
Anybody gotten the TPS EAD extension alert notice (i797) thing? online or via post?
अमेरिकामा छोरा हराएको सूचना
ढ्याउ गर्दा दसैँको खसी गनाउच
Sajha Poll: Who is your favorite Nepali actress?
Problems of Nepalese students in US
nrn citizenship
TPS EAD auto extended to June 2025 or just TPS?
अमेरिकामा बस्ने प्राय जस्तो नेपालीहरु सबै मध्यम बर्गीय अथवा माथि (higher than middle class)
Nas and The Bokas: Coming to a Night Club near you
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