C++ Light Bulb Switching Brain Teaser Exercise

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
863 views
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Aug 14, 2009

This is a video response to Sal's Brain Teaser. The link is at the bottom. I just made a program to do any number of light bulbs and tell you how many would be on.

http://www.youtube.com/user/khanacademy?blend=1&ob=4#play/uploads/0/WNhxk...

Category:

Education

Tags:

License:

Standard YouTube License

  • likes, 1 dislikes

Link to this comment:

Share to:

Uploader Comments (hendrix5045)

  • A simpler program would just be to return the floor of the square root of n.

  • I'm not really following you :/. I know that floor returns the largest integral value that's not greater than x, but I still don't get what you're saying. Maybe make a vid of this program using your method?

  • niceeeee!

  • Thanks, so do you program at all?

  • A bit, I learned with turbopascal (very old I know),

    but i'll be grabbing some C++ tutorials/books this summer since i'll be having c/c++ classes in september

    Your will videos will help a lot to start :-D

  • Awesome, good luck with C++!

see all

All Comments (9)

Sign In or Sign Up now to post a comment!
  • @hendrix5045 Ah I get what he's saying.For example, square root of 103 is 10.something. So it'll return 10. Floor rounds to the lowest integer. If it was 121, it would return 11 light bulbs on. But then it wouldn't show the light bulbs that were on. But then you could save that 11 on a variable, and say light bulbs x^2 until x=11 from 1. idk, knowing the explanation it just seems easier that way.

  • It would be simpler if you incremented j by k.

  • why do you sound like...my ex boyfriend LMAO

  • Or another method without vectors is

    int k = 1;

    for int i=1 , i<N , i++ do

    if i == k*k do

    printf "1 " ;

    k++ ;

    endIfDo else printf "0 " ;

    endForDo

    Pseudo code because youtube don't want to display c++ code...

  • khanacademy has the answer of this method.

    So if you have a N of 100 the answer will be for (int i=1; i<=(int)sqrt(N); i++) {

    lamps[i*i] = true;

    }

  • Thanks for the video but my problem is a little different with needs of optimization. Here is the problem acmp(dot)ru/index.asp?main=tas­k&id_task=337 use google translate for translation.

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more