Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I implemented Annoying Alarm Clock using Python. I also added a read me file explaining the code. Hoping to get the PR merged and getting the Hacktoberfest and hacktoberfest- accepted badge #1315

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Annoying Alarm Clock/annoyingalarmclock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import time
import winsound

def annoying_alarm_clock(duration, snooze_time):
# Play the alarm sound progressively louder
for i in range(1, duration + 1):
winsound.Beep(500, 100) # Play a beep sound
time.sleep(i) # Wait for i seconds

# After the alarm duration, ask if the user wants to snooze
snooze = input("Press 's' to snooze for {} seconds, or any other key to stop: ".format(snooze_time))
if snooze.lower() == 's':
time.sleep(snooze_time)
annoying_alarm_clock(duration, snooze_time) # Recursively snooze

if __name__ == "__main__":
alarm_duration = 30 # Duration of the alarm (in seconds)
snooze_time = 300 # Snooze time (in seconds)

print("Annoying Alarm Clock - It gets louder over time!")
print("Press Ctrl+C to stop the alarm at any time.")

try:
annoying_alarm_clock(alarm_duration, snooze_time)
except KeyboardInterrupt:
print("\nAlarm stopped.")
46 changes: 46 additions & 0 deletions Annoying Alarm Clock/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Annoying Alarm Clock

This is a Python script for an "Annoying Alarm Clock." It plays an alarm sound that gets progressively louder over time, and it offers a snooze option.

## Getting Started

To use the Annoying Alarm Clock, follow these steps:

1. Clone or download this repository to your local machine.

2. Make sure you have Python installed on your computer. You can download Python from the official website: [Python Downloads](https://www.python.org/downloads/).

3. Open a terminal or command prompt and navigate to the directory where the script is located.

4. Run the script by executing the following command:


5. The alarm will start, and it will get louder with each passing second.

6. You can stop the alarm at any time by pressing Ctrl+C.

7. If you want to snooze the alarm when it stops, press 's' and the alarm will snooze for the specified snooze time.

## Customization

You can customize the behavior of the alarm by modifying the following variables in the code:

- `alarm_duration`: Set the duration of the alarm in seconds.
- `snooze_time`: Set the snooze time in seconds.

## Operating System Compatibility

This script uses the `winsound` module for sound generation, which is compatible with Windows. If you are using a different operating system, you may need to use a different library for sound playback.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Acknowledgments

- This project was created for fun and as an example of a progressively louder alarm clock.
- Enjoy waking up to the sound of an annoying alarm!

---

Happy waking up!
59 changes: 35 additions & 24 deletions BFS/BFS.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
graph = {
'5' : ['3','7'],
'3' : ['2', '4'],
'7' : ['8'],
'2' : [],
'4' : ['8'],
'8' : []
}
from collections import defaultdict


class Graph:

def __init__(self):
self.graph = defaultdict(list)

visited = []
queue = []
def addEdge(self,u,v):
self.graph[u].append(v)

def bfs(visited, graph, node):
visited.append(node)
queue.append(node)
def BFS(self, s):
visited = [False] * (len(self.graph))
queue = []
queue.append(s)
visited[s] = True

while queue:
s = queue.pop(0)
print (s, end = " ")
for i in self.graph[s]:
if visited[i] == False:
queue.append(i)
visited[i] = True

# Driver code

while queue:
m = queue.pop(0)
print (m, end = " ")

for neighbour in graph[m]:
if neighbour not in visited:
visited.append(neighbour)
queue.append(neighbour)

print("Following is the Breadth-First Search")
bfs(visited, graph, '5')
# g = Graph()
# g.addEdge(0, 1)
# g.addEdge(0, 2)
# g.addEdge(1, 2)
# g.addEdge(2, 0)
# g.addEdge(2, 3)
# g.addEdge(3, 3)

# print ("Following is Breadth First Traversal"
# " (starting from vertex 2)")
# g.BFS(2)
81 changes: 39 additions & 42 deletions Binary Search/BinarySearch.cpp
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
//C++ program to implement Binary search using recursive method
//For this we are hoping that the array is sorted

#include<bits/stdc++.h>

#include <iostream>
using namespace std;

// A function that return the index of the element if found
// If the number is not there then it will return -1

int bSearch(int binarySearchArray[], int low, int high, int searchingNumber){
int mid = (low + high)/2;
// When the array is initialized then low represents 0th index whereas high represents the last index of the array
if(low > high)
return -1;
// we return -1 when low becomes greater than high denoting that the number is not present
if(binarySearchArray[mid] == searchingNumber)
return mid;
// If the number is found we are returning the index of the number where it was found
else if(searchingNumber > binarySearchArray[mid])
bSearch(binarySearchArray, mid + 1, high, searchingNumber);
// Since the number is greater than the mid element in the array so we increase the index of low by mid+1
// becuase the number before do not contain the number we were searching for
else
bSearch(binarySearchArray, low, mid-1, searchingNumber);
// Since the number is less than the mid elemet in the array so we decrease the index of high to mid-1
// because the number after the middle element do not contain the number we were searching for
}

int main(){
int sizeofArray = 10; // Taking the size of array
int binSearchArray[sizeofArray] = {5, 8 ,12, 34, 36, 40, 45, 50, 56, 61}; // Array containing the elements
int searchNumber = 40;

int isNumberFound = bSearch(binSearchArray, 0, sizeofArray - 1, searchNumber);

if(isNumberFound != -1)
cout<<"The number is found at the index : "<<isNumberFound;
// Since the returned index is not -1 we print that the number was found and at what index
else
cout<<"The number is not present in the array";
// else part is activated when the function returns -1 indicating that the number is not present

return 0;
int main()
{
int count, i, arr[30], num, first, last, middle;
cout<<"how many elements would you like to enter?:";
cin>>count;

for (i=0; i<count; i++)
{
cout<<"Enter number "<<(i+1)<<": ";
cin>>arr[i];
}
cout<<"Enter the number that you want to search:";
cin>>num;
first = 0;
last = count-1;
middle = (first+last)/2;
while (first <= last)
{
if(arr[middle] < num)
{
first = middle + 1;

}
else if(arr[middle] == num)
{
cout<<num<<" found in the array at the location "<<middle+1<<"\n";
break;
}
else {
last = middle - 1;
}
middle = (first + last)/2;
}
if(first > last)
{
cout<<num<<" not found in the array";
}
return 0;
}
53 changes: 10 additions & 43 deletions Cyclic Sort/CyclicSort.cpp
Original file line number Diff line number Diff line change
@@ -1,45 +1,12 @@
#include <bits/stdc++.h>
#include<iostream>
using namespace std;

void cyclicSort(vector<int>& arr)
{
int n=arr.size();
int i = 0;
while(i < n)
{
int correct = arr[i] - 1 ;
if(arr[i] != arr[correct])
{
swap(arr[i], arr[correct]) ;
}
else{
i++ ;
}
void cyclicSort(int &arr[],int n){
int i=0;
while(i<n){
int correct=arr[i]-1;
if(arr[i]!=correct){
swap(arr[i],arr[correct]);
}
else{i++;}
}
}

void printArray(vector<int> arr)
{
int size=arr.size();
for (int i = 0; i < size; i++)
{
cout << arr[i] << " ";
}
cout<<endl;
}

int main()
{
int n;
cin>>n;//Size of array
vector<int> v(n);
for(int i=0;i<n;i++)
{
cin>>v[i];//Input Array elements
}
cyclicSort(v);//Cyclic sort function
cout<<"Printing sorted array:"<<endl;
printArray(v);//Printing Sorted array
return 0;
}

}
10 changes: 6 additions & 4 deletions Factorial/Factorial.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
-- Standard inplementation of a factorial in Haskell
factorial :: Integer -> Integer
factorial 0 = 1
factorial n = n * factorial (n - 1)
-- Luis L Reyes
-- Simple factorial function
module Factorial where
factorial :: Integer -> Integer
factorial 1 = 1
factorial n = n * (factorial (n-1))
51 changes: 15 additions & 36 deletions Factorial/Factorial.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,19 @@
import java.util.Scanner;
/*This a example of Factorization*/
public class Main {
public static long factorial(int n){
long accumulator = 1;
class Factorial{

for(; n > 0; n--){
accumulator *= n;
}

return accumulator;
}

public static boolean isInteger(String text){
try{
Integer.parseInt(text);
return true;
}catch(Exception e){
return false;
}
}

public static void main(String[] args){
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReadLine br = new BufferedReadLine(reader);
System.out.println("Enter a number to factorialize: ");
int input = Integer.parseInt();

if(isInteger(input)){
try{
int num = Integer.parseInt(input);
System.out.println("The factorial of " + num + " is " + factorial(num));
}catch(NumberFormatException e){
System.out.println("What happened there ?");
}
}else {
System.out.println("The input was not a number");
}
public static void main(String[] args){

Scanner s=new Scanner(System.in);
System.out.println("Enter a non negative number");
int n=s.nextInt();
int fact=1;
if(n==0 || n==1){
fact=1;
}else{

for(int i=2;i<=n;i++)
fact*=i;
}
System.out.println("Factorial of the number is "+fact);
}
}
19 changes: 9 additions & 10 deletions FibonacciSeq/Fibonacci.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
-- Inplementation of a fibonacci sequence in Haskell
-- Calculating the nth number in the sequence
fibonacci :: Integer -> Integer
fibonacci 0 = 0
fibonacci 1 = 1
fibonacci n = fibonacci (n-1) + fibonacci (n-2)

-- Generating the first n numbers in the sequence
fibseq :: Integer -> [Integer]
fibseq n = [fibonacci x | x <- [1..n]]
-- Luis L Reyes
-- fibonacci function takes in the nth number
-- of the sequence you want where sequence
-- is 1 while n = 0 or 1
module Fibonacci where
fibonacci :: Integer -> Integer
fibonacci 0 = 1
fibonacci 1 = 1
fibonacci n = (fibonacci (n-1)) + (fibonacci(n-2));
27 changes: 12 additions & 15 deletions FibonacciSeq/Fibonacci.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
class Fibonacci
def series
puts "Enter the Fibonacci value"
n=gets.to_i
f1=0
f2=1
f3=0
while f3<n do
f3=f1+f2
puts f3
f1=f2
f2=f3
end
def fib(n)
if n <= 2
return 1
else
return fib(n-1) + fib(n-2)
end
end
obj1=Fibonacci.new
obj1.series

puts "Enter limit : "
limit = gets.to_i

result = fib(limit)

puts "Fib(#{limit}) = #{result}"
Loading