From d0795b559058f8817bfcfd501cc208324b4f6378 Mon Sep 17 00:00:00 2001 From: adil khan Date: Thu, 6 Oct 2022 12:59:59 +0530 Subject: [PATCH 1/2] Added smart light automation script --- random/light_control.py | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 random/light_control.py diff --git a/random/light_control.py b/random/light_control.py new file mode 100644 index 0000000..572ec22 --- /dev/null +++ b/random/light_control.py @@ -0,0 +1,63 @@ +# import phue library +from phue import Bridge +import time + +# add ip address of your router +ip_address = '' + +#establishing connection +connection = Bridge(ip_address) +list_of_lights = connection.lights + + +#Switch on all lights +def switch_on(): + for light in list_of_lights: + light.on = True + light.hue = 15000 + light.saturation = 120 + +#Switch of all lights +def switch_of(): + for light in list_of_lights: + light.on = False + + +#Toggle specific light +def toggle_light(name): + light = connection.get_light(name) + if light.on: + light.on = True + else: + light.on = False + + +#Set Timer to on or off +def setTime(hour,minute,On): + T = time.localtime() + curr_hour,curr_minute = T[3],T[4] + + if curr_hour >= hour and curr_minute: + if On: + for light in list_of_lights: + light.on = False + else: + for light in list_of_lights: + light.on = False + + +#Dim light according to the time of day +def naturalLight(): + T = time.localtime() + curr_hour = T[3] + + if curr_hour >= 6 and curr_hour <= 18: + for light in list_of_lights: + light.on = True + light.hue = 15000 + light.saturation = 120 + else: + for light in list_of_lights: + light.on = True + light.hue = 150 + light.saturation = 50 From 41a464961bed6c29219a06940a628b99e62fea41 Mon Sep 17 00:00:00 2001 From: adil khan Date: Thu, 6 Oct 2022 13:07:21 +0530 Subject: [PATCH 2/2] Template for ternary search --- DSA/Sorting/ternarySearch.py | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 DSA/Sorting/ternarySearch.py diff --git a/DSA/Sorting/ternarySearch.py b/DSA/Sorting/ternarySearch.py new file mode 100644 index 0000000..c704354 --- /dev/null +++ b/DSA/Sorting/ternarySearch.py @@ -0,0 +1,37 @@ +""" +Ternary Search| + +We can divide the array into three parts by +taking mid1 and mid2 which can be calculated +as shown below. Initially, l and r will be +equal to 0 and n-1 respectively, where n is +the length of the array. +mid1 = l + (r-l)/3 +mid2 = r – (r-l)/3 +""" +def ternerySearch(arr,x): + l=0 + r=len(arr)-1 + while l<=r: + m1= l+(r-l)//3 + m2 = r-(r-l)//3 + if xarr[m2]: + l=m2+1 + elif x==arr[m1] or x==arr[m2]: + return True + else: + l=m1+1 + r=m2-1 + return False + + +""" +We can apply ternery search on unimodal +functions:- + A function f(x) is a unimodal function + if for some value m, it is monotonically + increasing for x ≤ m and monotonically + decreasing for x ≥ m. +"""