Skip to main content

First post using stackedit

Welcome to StackEdit! Hey! I’m your first Markdown document in StackEdit 1 . Don’t delete me, I’m very helpful! I can be recovered anyway in the Utils tab of the Settings dialog. Documents StackEdit stores your documents in your browser, which means all your documents are automatically saved locally and are accessible offline! Note: StackEdit is accessible offline after the application has been loaded for the first time. Your local documents are not shared between different browsers or computers. Clearing your browser’s data may delete all your local documents! Make sure your documents are synchronized with Google Drive or Dropbox (check out the Synchronization section). Create a document The document panel is accessible using the button in the navigation bar. You can create a new document by clicking New document in the document panel. Switch to another document All your local documents are listed in the document panel. You can switch from one to anoth...

What doors are closed?


There is an interesting interview question, which has been asked at many US companies.

There are 500 doors, initially closed. There are 500 people, one by one goes through all the doors.

The 1st person change the status of all the doors (i.e, open all of them).
The 2nd person change the status of all the doors with number can divide to 2 (i.e, he will change the status of doors number 2, 4, 6, 8, 10, ... 500)
The 3rd person change the status of doors 3, 6, 9, ...
...
The 500th person change the status of the door 500

Change the status means: close the opening door, and open the closing door.

The question is: in the end, how many doors are close?

You can solve this problem by using mathematics, but it may be faster to simulate it.

You can check my simulation at: http://www.codeskulptor.org/#user38_rrZv4nVRno_1.py and easy to see, the opening doors are the doors with the number are square number.

Comments

Popular posts from this blog

Getting started with Cryptpad in Ubuntu: step by step

Cryptpad is an open source collaborative editor which is hosted at: https://github.com/cjdelisle/cryptpad It is easy to clone the github repository and start to try, but if you are a newbie, there maybe some difficulties. Suppose that you have a clean Ubuntu machine, and want to try with Cryptpad, you can follow these steps: 1. Download mongodb for Linux: https://www.mongodb.org/downloads 2. Unzip the file you got to a location you want. You will start mongodb from there, or add this directory to your PATH variable so you can start mongodb from anywhere. 3. Suppose that you chose the easier way, i.e start mongodb from its directory. 4. Open Terminal (Ctrl + Alt + T for shortcut), move to the directory of mongodb 5. Type: mkdir db mongod --dbpath=./db These above commands will first, create a directory 'db' insider the directory mongodb, then start mongodb server. 6. Keep the terminal with mongodb server running 7. Open another terminal (Ctrl...

First post using stackedit

Welcome to StackEdit! Hey! I’m your first Markdown document in StackEdit 1 . Don’t delete me, I’m very helpful! I can be recovered anyway in the Utils tab of the Settings dialog. Documents StackEdit stores your documents in your browser, which means all your documents are automatically saved locally and are accessible offline! Note: StackEdit is accessible offline after the application has been loaded for the first time. Your local documents are not shared between different browsers or computers. Clearing your browser’s data may delete all your local documents! Make sure your documents are synchronized with Google Drive or Dropbox (check out the Synchronization section). Create a document The document panel is accessible using the button in the navigation bar. You can create a new document by clicking New document in the document panel. Switch to another document All your local documents are listed in the document panel. You can switch from one to anoth...

P vs NP: A very short brief introduction

My summary document, after Udacity CS313: An Introduction to Theoretical Computer Science. Suitable for undergraduate or Master computer science students. Link