From b33db2590e7cee71bf44e66f6e3039c8a50d41e4 Mon Sep 17 00:00:00 2001 From: user-person <60802990+user-person@users.noreply.github.com> Date: Sun, 9 Feb 2020 02:47:33 -0500 Subject: Create ch-2.py --- challenge-046/user-person/python/ch-2.py | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 challenge-046/user-person/python/ch-2.py diff --git a/challenge-046/user-person/python/ch-2.py b/challenge-046/user-person/python/ch-2.py new file mode 100644 index 0000000000..6032cf4b47 --- /dev/null +++ b/challenge-046/user-person/python/ch-2.py @@ -0,0 +1,35 @@ +#!/usr/bin/python + +########################################################################### +# script name: ch-2.py # +# # +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-046/ # +# # +########################################################################### + +MAX = 500 +doors = ["CLOSED" for i in range(MAX+1)] + +def change (doorStatus): + returnString = "OPENED" + if doorStatus == "OPENED": + returnString = "CLOSED" + return returnString + +for i in range(1,MAX): + if i > MAX/2: + doors[i] = change(doors[i]) + continue + + for j in range(1,MAX): + if j % i == 0: + doors[j] = change(doors[j]) + +for k in range(1,MAX): + if doors[k] == "OPENED": + print(k,end=" ") + +print() + +# ch-2.py output: +# 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361 400 441 484 -- cgit