Posted By

kentoy on 02/06/11


Tagged

Bash easy puzzle


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

adkatrit


100 Doors


 / Published in: Bash
 

URL: http://www.techinterview.org/post/526370758/100-doors-in-a-row

100 doors problem solved in Bourne Again Shell (optimized)

save source as: 100doors.sh compile: chmod u+x 100door.sh execute: ./100doors.sh

do all of this in the unix (bash) terminal ;)

  1. #!/bin/bash
  2.  
  3. for i in {1..100}; do
  4. door[$i*$i]=1
  5. [ -z ${door[$i]} ] && echo "$i : closed" || echo "$i : open"
  6. done

Report this snippet  

You need to login to post a comment.