/ 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 ;)
Expand |
Embed | Plain Text
#!/bin/bash for i in {1..100}; do door[$i*$i]=1 [ -z ${door[$i]} ] && echo "$i : closed" || echo "$i : open" done
You need to login to post a comment.
