From 3dc1af1a2021c42eab524972d8a1ff34781f13d4 Mon Sep 17 00:00:00 2001 From: Pansilu Wijesiri <107906835+PansiluAW@users.noreply.github.com> Date: Mon, 24 Oct 2022 23:08:15 +0530 Subject: [PATCH 1/5] Add lottery system code. --- problems/ProjectLotteryProblem.txt | 22 +++++++++++++++ solutions/ProjectLotterySolution.py | 44 +++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 problems/ProjectLotteryProblem.txt create mode 100644 solutions/ProjectLotterySolution.py diff --git a/problems/ProjectLotteryProblem.txt b/problems/ProjectLotteryProblem.txt new file mode 100644 index 0000000..39c026d --- /dev/null +++ b/problems/ProjectLotteryProblem.txt @@ -0,0 +1,22 @@ +Lottery system, where the user can input 5 numbers of choice and the system will generate another set of 5 numbers. The program will then check if the entered numbers have any match with the numbers generated randomly by the system and giveout the number of matches in the set of input numbers by the user. + +If there is no match, te system will display matches as 0(zero). + +Example 1: + +User input numbers : 1, 2, 3, 5, 4 + +Lottery numbers generated randomly by system : 30, 19, 21, 3, 32 + +Output : You have 0 matches + +Example 2: + +User input number : 45, 34, 65, 34, 22 + +Lottery numbers generated randomly by system : 5, 34, 40, 16, 37 + +You have 1 matches + + + diff --git a/solutions/ProjectLotterySolution.py b/solutions/ProjectLotterySolution.py new file mode 100644 index 0000000..b017e39 --- /dev/null +++ b/solutions/ProjectLotterySolution.py @@ -0,0 +1,44 @@ +#IMPORT RANDOM MODULE +import random + +#CREATE VARIABLE +user_list = [] +random_list = [] +user_value = 0 +random_value = 0 +count = 0 +matches = 0 + +#GET VALUES FROM THE USER INTO A LIST +user_list.append(int(input("Insert number 1 : "))) +user_list.append(int(input("Insert number 2 : "))) +user_list.append(int(input("Insert number 3 : "))) +user_list.append(int(input("Insert number 4 : "))) +user_list.append(int(input("Insert number 5 : "))) +print("\n") + +#GET RANDOM NUMBERS INTO A LIST +random_list.append(random.randrange(1,50)) +random_list.append(random.randrange(1,50)) +random_list.append(random.randrange(1,50)) +random_list.append(random.randrange(1,50)) +random_list.append(random.randrange(1,50)) + +#DISPLAY THE USER ENTRIES +print("User number :",end = " ") +for user_value in user_list: + print(user_value,end = " ") +print("\n") + +#DISPLAY THE LOTTERY NUMBERS +print("Lottery numbers : ",end = " ") +for random_value in random_list: + print(random_value,end = " " ) + +#LOOK FOR MATCHING VALUES IN BOTH LISTS +for count in range (5): + if user_list[count] == random_list[count]: + matches +=1 + +#DISPLAY NUMBER OF MATCHES +print("\n\nYou have",matches,"matches") From cb52338c7fac6f4a38fac6a9ac8f60839e9366ff Mon Sep 17 00:00:00 2001 From: Rishabh Jain <73517462+1-Rishabh-Jain-1@users.noreply.github.com> Date: Wed, 26 Oct 2022 11:13:48 +0530 Subject: [PATCH 2/5] Create 3_solution.py --- solutions/3_solution.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 solutions/3_solution.py diff --git a/solutions/3_solution.py b/solutions/3_solution.py new file mode 100644 index 0000000..199b66b --- /dev/null +++ b/solutions/3_solution.py @@ -0,0 +1,18 @@ +def check_palindrome(n): + temp = n + rev = 0 + is_palindrome = False + while (n != 0): + digit = n % 10 + rev = rev * 10 + digit + n = n // 10 + if temp == rev: + is_palindrome = True + return is_palindrome + +n = int(input("Enter any number: ")) +ans = check_palindrome(n) +if ans == True: + print("The given number is a palindrome!") +else: + print("The given number is not a palindrome!") From c62a7a2b818f3c32f91e1f4fb02ad2fb7882b645 Mon Sep 17 00:00:00 2001 From: Jerald Jacob Date: Tue, 10 Oct 2023 15:28:50 +0530 Subject: [PATCH 3/5] Create 10_solution --- solutions/10_solution | 102 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 solutions/10_solution diff --git a/solutions/10_solution b/solutions/10_solution new file mode 100644 index 0000000..0334623 --- /dev/null +++ b/solutions/10_solution @@ -0,0 +1,102 @@ +Fork/Join +The fork/join framework is an implementation of the ExecutorService interface that helps you take advantage of multiple processors. It is designed for work that can be broken into smaller pieces recursively. The goal is to use all the available processing power to enhance the performance of your application. + +As with any ExecutorService implementation, the fork/join framework distributes tasks to worker threads in a thread pool. The fork/join framework is distinct because it uses a work-stealing algorithm. Worker threads that run out of things to do can steal tasks from other threads that are still busy. + +The center of the fork/join framework is the ForkJoinPool class, an extension of the AbstractExecutorService class. ForkJoinPool implements the core work-stealing algorithm and can execute ForkJoinTask processes. + +Basic Use +The first step for using the fork/join framework is to write code that performs a segment of the work. Your code should look similar to the following pseudocode: + +if (my portion of the work is small enough) + do the work directly +else + split my work into two pieces + invoke the two pieces and wait for the results +Wrap this code in a ForkJoinTask subclass, typically using one of its more specialized types, either RecursiveTask (which can return a result) or RecursiveAction. + +After your ForkJoinTask subclass is ready, create the object that represents all the work to be done and pass it to the invoke() method of a ForkJoinPool instance. + +Blurring for Clarity +To help you understand how the fork/join framework works, consider the following example. Suppose that you want to blur an image. The original source image is represented by an array of integers, where each integer contains the color values for a single pixel. The blurred destination image is also represented by an integer array with the same size as the source. + +Performing the blur is accomplished by working through the source array one pixel at a time. Each pixel is averaged with its surrounding pixels (the red, green, and blue components are averaged), and the result is placed in the destination array. Since an image is a large array, this process can take a long time. You can take advantage of concurrent processing on multiprocessor systems by implementing the algorithm using the fork/join framework. Here is one possible implementation: + +public class ForkBlur extends RecursiveAction { + private int[] mSource; + private int mStart; + private int mLength; + private int[] mDestination; + + // Processing window size; should be odd. + private int mBlurWidth = 15; + + public ForkBlur(int[] src, int start, int length, int[] dst) { + mSource = src; + mStart = start; + mLength = length; + mDestination = dst; + } + + protected void computeDirectly() { + int sidePixels = (mBlurWidth - 1) / 2; + for (int index = mStart; index < mStart + mLength; index++) { + // Calculate average. + float rt = 0, gt = 0, bt = 0; + for (int mi = -sidePixels; mi <= sidePixels; mi++) { + int mindex = Math.min(Math.max(mi + index, 0), + mSource.length - 1); + int pixel = mSource[mindex]; + rt += (float)((pixel & 0x00ff0000) >> 16) + / mBlurWidth; + gt += (float)((pixel & 0x0000ff00) >> 8) + / mBlurWidth; + bt += (float)((pixel & 0x000000ff) >> 0) + / mBlurWidth; + } + + // Reassemble destination pixel. + int dpixel = (0xff000000 ) | + (((int)rt) << 16) | + (((int)gt) << 8) | + (((int)bt) << 0); + mDestination[index] = dpixel; + } + } + + ... +Now you implement the abstract compute() method, which either performs the blur directly or splits it into two smaller tasks. A simple array length threshold helps determine whether the work is performed or split. + +protected static int sThreshold = 100000; + +protected void compute() { + if (mLength < sThreshold) { + computeDirectly(); + return; + } + + int split = mLength / 2; + + invokeAll(new ForkBlur(mSource, mStart, split, mDestination), + new ForkBlur(mSource, mStart + split, mLength - split, + mDestination)); +} +If the previous methods are in a subclass of the RecursiveAction class, then setting up the task to run in a ForkJoinPool is straightforward, and involves the following steps: + +Create a task that represents all of the work to be done. + +// source image pixels are in src +// destination image pixels are in dst +ForkBlur fb = new ForkBlur(src, 0, src.length, dst); +Create the ForkJoinPool that will run the task. + +ForkJoinPool pool = new ForkJoinPool(); +Run the task. + +pool.invoke(fb); +For the full source code, including some extra code that creates the destination image file, see the ForkBlur example. + +Standard Implementations +Besides using the fork/join framework to implement custom algorithms for tasks to be performed concurrently on a multiprocessor system (such as the ForkBlur.java example in the previous section), there are some generally useful features in Java SE which are already implemented using the fork/join framework. One such implementation, introduced in Java SE 8, is used by the java.util.Arrays class for its parallelSort() methods. These methods are similar to sort(), but leverage concurrency via the fork/join framework. Parallel sorting of large arrays is faster than sequential sorting when run on multiprocessor systems. However, how exactly the fork/join framework is leveraged by these methods is outside the scope of the Java Tutorials. For this information, see the Java API documentation. + +Another implementation of the fork/join framework is used by methods in the java.util.streams package, which is part of Project Lambda scheduled for the Java SE 8 release. For more information, see the Lambda Expressions section. From 8169f1d4cfc5bd78094cdcaf1221c8213fb7b5c5 Mon Sep 17 00:00:00 2001 From: Jerald Jacob Date: Tue, 17 Oct 2023 14:24:31 +0530 Subject: [PATCH 4/5] Create Ai --- Ai | 1 + 1 file changed, 1 insertion(+) create mode 100644 Ai diff --git a/Ai b/Ai new file mode 100644 index 0000000..387cce8 --- /dev/null +++ b/Ai @@ -0,0 +1 @@ +What is Generative AI on AWS? From 11a8415558f1b41f01ef2aad973d1101be8c430c Mon Sep 17 00:00:00 2001 From: Jerald Jacob Date: Tue, 17 Oct 2023 14:25:36 +0530 Subject: [PATCH 5/5] Create Ans --- Ans | 1 + 1 file changed, 1 insertion(+) create mode 100644 Ans diff --git a/Ans b/Ans new file mode 100644 index 0000000..634ca47 --- /dev/null +++ b/Ans @@ -0,0 +1 @@ +From startups to enterprises, organizations trust AWS to innovate with generative artificial intelligence (AI). With enterprise-grade security and privacy, access to industry-leading foundation models, and generative AI-powered applications, AWS makes it easy to build and scale generative AI, built for your data, your use cases and your customers.