From 498dec17fead6f28cce2e47a6c7c1e9dab481bcd Mon Sep 17 00:00:00 2001 From: Seif Sekalala Date: Sun, 31 Mar 2024 16:48:31 -0400 Subject: [PATCH] Adding the day's algo practice, via the 0wxOnWaxOff.py file. --- .DS_Store | Bin 14340 -> 14340 bytes .../Documentation.txt | 24 ++++++++ README.md | 2 +- importantAlgos/0wxOnWaxOff.py | 56 ++++++++++++++++-- 4 files changed, 75 insertions(+), 7 deletions(-) diff --git a/.DS_Store b/.DS_Store index 365c8afa098096e1d4e7cd99417193f5b90df890..d73d80bde4a71491f206a3761c67a044fbb67a30 100644 GIT binary patch delta 212 zcmZoEXepTB&*-o*z>{sVgOcgyvutLJJPZsBj6e(o9Ne1)ImB2ttMNQ#W>lQ)AfU8a zPhbhNIwwOAgDZn0gA0Q%kk(_!Wk~VN$xlwo$xj065&-Hq1Jc2hc}0vi{}g_}J(*h} zgm*1a$oD@OFfdFuRC1ZTL4kX6lvv7d0}#p=7hP=4-ai>;|7%Cfll7Z8lcDzytsZFF2q8 delta 182 zcmZoEXepTB&uG6fz>{tAJ2sQe=akGDc^DWN7=aiFIJh?pa)_~PR^xff%&0KgK|pD< zp1>03%`779JQEv?CUYxY?CT~#SW;{9BU!y@&qPp71&{#*o$jq`< zN1@u%#7sxQ%)qR+mXkwV)zH>6A-A%sx~8^n=HvtwdB$0j@3FaTKBdUP&S7X_sH0$L eWIWkX#c8vQ=4-aiYzALgCflo8ZZ=W9$OHf}FE@|? diff --git a/00--Documentation and DIR-Layout/Documentation.txt b/00--Documentation and DIR-Layout/Documentation.txt index 07fc0f5..b239dbe 100644 --- a/00--Documentation and DIR-Layout/Documentation.txt +++ b/00--Documentation and DIR-Layout/Documentation.txt @@ -20,9 +20,33 @@ ___Either document can be used--i.e., that (^^) or the current one--the notes be // // +// +// +=================================================================================// +=================================================================================// +// +// +>> March 31 to April 5 (+/-), 2024: Continuation of Overall STM +// + +=========>> Goals: +// +____>> I) "Stay On The Path!" +-------------//___>>> 1)-a--Number 13 of "CoderByte-18": "Switching Light Bulbs" via "0wxOnWaxOff.py" file. + +____>> II) Writing copy for the PM app +-------------//___>>> 2)-a--Writing about "risk" given its sensitivity as a PM concept; +-------------//___>>> 2)-b--Outlining other upcoming topics; and... +-------------//___>>> 2)-c--Looking up how to use CSS for diving an HTML page into blocks. + +____>> III) Again, "Stay On The Path (!)": Finish, or **continue** what you've already started, before moving on to other goals. +// +-------------//___>>> 1)-a--TDL (ie. To-Do List)-review +-------------//___>>> 2)-b--Mindfulness. // // + =================================================================================// =================================================================================// // diff --git a/README.md b/README.md index f44f97f..25b53eb 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ A sample-repository of final practice exercises and (final practice) projects to help self-taught devs graduate from S___ to M___! -Happy coding! :-) +Happy coding! :-) diff --git a/importantAlgos/0wxOnWaxOff.py b/importantAlgos/0wxOnWaxOff.py index 25145e4..55900e4 100644 --- a/importantAlgos/0wxOnWaxOff.py +++ b/importantAlgos/0wxOnWaxOff.py @@ -12,7 +12,6 @@ # for i in arr: # applied = fn(i) # result.append(applied) - # print(result) # square = lambda x: x * x @@ -105,13 +104,10 @@ #?_Add Code Here and Lines Below. # import math - # def majorityElement(arr): # candidate = None # count = 0 - - # for i in range(0, len(arr)): # if candidate is None or count == 0: # candidate = 1 @@ -120,7 +116,6 @@ # count += 1 # else: # count -= 1 - # count = 0 # for el in arr: # if el == candidate: @@ -130,8 +125,57 @@ # return candidate # else: # return None - #?_Test Notes: #?_Test suspended for today--i.e., not done. +#!-----------------------------------------------// + +#*_Day 11 of STM Self-Challenge: Mar 31 (Sun), 2024 +#!_Challenge #-13__: "Switching light bulbs" + +''' +**_Problem Details_** + +#!_Scenario: +___>> There are 100 light bulbs, numbered 1 to 100, lined up, and all set to "Off" initially. There are also 100 people, each numbered 1 to 100 as well. +___>> Person 1 will go through all the light bulbs and flip the switch, turning all of them on. +___>> Then person 2 will go through the switches, turning each other 2nd bulb off--i.e., 2, 4, 6, 8, etc. +___>> Then person 3 will go and flip to "Off" position the 3rd, 6th, 9th, ...(etc.) bulbs. + +#!_Questions: +___>> How many light bulbs will be on after 100 people have gone through them? +___>> What is that status of a given "N_th"--e.g. 34th, or 62nd, etc.; is it "On," or "Off"? +___>> How many people need to go through the line of bulbs until precisely "K" bulbs are set to on? + +#!_Game-Plan / Strategy: +#?_According the Book... +>> To answer these questions, we need a function to iterate through all "N" buls and perform each operation for every person labelled 1 to N. +>> We'll set up an array of N elements, all set to "FALSE"--i.e., representing the light-bulb in the "Off" position. +>> Then we'll loop through every person--1 to "N"--and within that loop, create another loop that will multiply each person's number by a particular ["i_th" / bulb] number; i.e.: +___>>> For current iteration, i = 1, 2, 3, 4, 5...etc. +___>>> ________''_________, i = 2, 4, 6, 8...etc. +___>>> ________''_________, i = 3, 6, 9, 12...etc. + +#?_My own consideration, to be solved/answered later; what's the run-time of the above solution--i.e., re: "0 of N"? And if the runtime is inefficient, can(n't) we do better? Random brainstormed-solution: how about using a hash table? +''' + +def lightBulb(N): + + #?_Create N bulbs, set to "Off". + lightbulbs = [False for i in range(0, N)] + + #?_Each person i sets each Kth bulb to "On" or "Off" position; k = 2 * i, 3 * i, etc. + #!_Very Important (!): "w" is merely a counter symbol! The letters/symbols that matter more importantly are k--the current/given person, and i--the current ith-iterative system--i.e., 1 += 1, or 2 (i.e. 2, 4, 6, etc.), or 3(i.e. 3, 6, 9, etc.). + + for i in range(1, N + 1): + w = 1 + k = w * i + while k <= N: + lightbulbs[k - 1] = not lightbulbs[k - 1] + w += 1 + k = w * i + + return lightbulbs +#?_Test suspended for today--i.e., not done. + #!-----------------------------------------------// \ No newline at end of file