The challenge A number m of the form 10x + y is divisible by 7 if and only if x − 2y is divisible by 7. In other words, subtract twice the last digit from the number formed by the remaining digits. Continue to do this until a number known to be divisible by 7 is obtained; you can stop when this number has at most 2 digits because you are supposed to know if a number of at most 2 digits is divisible by 7 or not.
The challenge The Western Suburbs Croquet Club has two categories of membership, Senior and Open. They would like your help with an application form that will tell prospective members which category they will be placed. To be a senior, a member must be at least 55 years old and have a handicap greater than 7. In this croquet club, handicaps range from -2 to +26; the better the player the lower the handicap.
The challenge This program tests the life of an evaporator containing a gas. We know the content of the evaporator (content in ml), the percentage of foam or gas lost every day (evap_per_day) and the threshold (threshold) in percentage beyond which the evaporator is no longer useful. All numbers are strictly positive. The program reports the nth day (as an integer) on which the evaporator will be out of use.
The challenge Create a function named divisors/Divisors that takes an integer n > 1 and returns an array with all of the integer’s divisors(except for 1 and the number itself), from smallest to largest. If the number is prime return the string ‘(integer) is prime’ (null in C#) (use Either String a in Haskell and Result<Vec<u32>, String> in Rust). Example: 1 2 3 divisors(12); // results in {2, 3, 4, 6} divisors(25); // results in {5} divisors(13); // results in NULL The solution in C Option 1:
The challenge If　a = 1, b = 2, c = 3 ... z = 26 Then l + o + v + e = 54 and f + r + i + e + n + d + s + h + i + p = 108 So friendship is twice as strong as love 🙂 Your task is to write a function which calculates the value of a word based off the sum of the alphabet positions of its characters.
The challenge A child is playing with a ball on the nth floor of a tall building. The height of this floor, h, is known. He drops the ball out of the window. The ball bounces (for example), to two-thirds of its height (a bounce of 0.66). His mother looks out of a window 1.5 meters from the ground. How many times will the mother see the ball pass in front of her window (including when it’s falling and bouncing?
The challenge Instructions Write a function that takes a single string (word) as argument. The function must return an ordered list containing the indexes of all capital letters in the string. Example 1 Test.assertSimilar( capitals('CodEStAr'), [0,3,4,6] ); The solution in C Option 1: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include <stddef.h> #include <string.h> #include <stdlib.h> size_t *find_capitals(const char *word, size_t *nb_uppercase) { size_t n = strlen(word); size_t *arr = (size_t *) calloc(n, sizeof(size_t)); size_t j = 0; for(size_t i=0; i<n; i++) { if(word[i] >='A' && word[i] <='Z') { arr[j++] = i; } } *nb_uppercase = j; return realloc(arr, j * sizeof(size_t)); } Option 2:
Option 1 – Using AWS CLI Step 1 1 export bucketname='your-bucket-here' Step 2 1 aws s3api delete-objects --bucket \$bucketname --delete "\$(aws s3api list-object-versions --bucket \$bucketname --output=json --query='{Objects: *[].{Key:Key,VersionId:VersionId}}')"; Step 3 1 aws s3 rb s3://\$bucketname Option 2 – Using Python 1 2 3 4 5 6 7 8 9 10 11 #!/usr/bin/env python BUCKET = 'your-bucket-here' import boto3 s3 = boto3.resource('s3') bucket = s3.Bucket(BUCKET) bucket.object_versions.delete() bucket.delete()
If you are creating a FSx file system, and want to connect it to AWS Managed Active Directory, then you will need to create a VPC Security Group with the following ports: Inbound ports Rules Ports UDP 53, 88, 123, 389, 464 TCP 53, 88, 123, 389, 445, 464, 636, 3268, 3269, 9389, 49152-65535 Outbound ports All traffic, 0.0.0.0/0
If you need to calculate variance in Python, then you can do the following. Option 1 – Using variance() from Statistics module 1 2 3 4 5 6 7 import statistics list = [12,14,10,6,23,31] print("List : " + str(list)) var = statistics.variance(list) print("Variance: " + str(var)) Option 2 – Using var() from numpy module 1 2 3 4 5 6 import numpy as np arr = [12,43,24,17,32] print("Array : ", arr) print("Variance: ", np.
If you need to calculate and get the sum of a list in Python, then you can do the following. Option 1 – Using sum() 1 2 3 myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] listSum = sum(myList) print(f"Sum of list -> {listSum}") If you get a TypeError then you can do the following: 1 2 3 4 5 6 myList = ["1", "3", "5", "7", "9"] myNewList = [int(string) for string in myList] sum1 = sum(myNewList) sum2 = sum(number for number in myNewList) print(f"Sum of list -> {sum1}") print(f"Sum of list -> {sum2}") Option 2 – Using for 1 2 3 4 5 6 7 8 myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] length = len(myList) listSum = 0 for i in range(length): listSum += myList[i] print(f"Sum of list -> {listSum}")
If you need to add a list to a set in Python, then you can do the following: Option 1 – Using Tuple 1 2 3 4 5 myset = set((1,2,3,4)) mylist = list(1,2,3]) myset.add(tuple(mylist)) print(myset) Output: {1, 2, 3, 4, (1, 2, 3)} Option 2 – Using set.update() 1 2 3 4 5 myset = set((1,2,3,4)) mylist = list(8,9,12]) myset.update(tuple(mylist)) print(myset) Output: {1, 2, 3, 4, 8, 9, 12}
If you have a Python list, and want to remove all punctuation, then you can do the following: First get all punctuation by using string.punctuation 1 2 import string print(string.punctuation) Output: 1 !"#\$%&'()*+,-./:;<=>?@[\]^_`{|}~ Option 1 – Using for 1 2 3 4 5 6 7 8 9 10 11 12 import string words = ["hell'o", "Hi,", "bye bye", "good bye", ""] new_words = [] for word in words: if word == "": words.
If you need to normalize a list of numbers in Python, then you can do the following: Option 1 – Using Native Python 1 2 3 4 5 6 7 list = [6,1,0,2,7,3,8,1,5] print('Original List:',list) xmin = min(list) xmax=max(list) for i, x in enumerate(list): list[i] = (x-xmin) / (xmax-xmin) print('Normalized List:',list) Option 2 – Using MinMaxScaler from sklearn 1 2 3 4 5 6 7 import numpy as np from sklearn import preprocessing list = np.
If you need to multiply a list by a scalar in Python, then you can do one of the following: Option 1 – Using List Comprehensions 1 2 3 4 li = [1,2,3,4] multiple = 2.5 li = [x*multiple for x in li] print(li) Output: [2.5, 5.0, 7.5, 10.0] Option 2 – Using map() 1 2 3 4 5 6 7 li = [1,2,3,4] multiple = 2.5 def multiply(le): return le*multiple li = list(map(multiply,li)) print(li) Output: [2.
If you need to find the index of the minimum element in a list, you can do one of the following: Option 1 – Using min() and index() 1 2 3 lst = [8,6,9,-1,2,0] m = min(lst) print(lst.index(m)) Output: 3 Option 2 – Using min() and for 1 2 3 4 5 6 lst = [8,6,9,-1,2,0] m = min(lst) for i in range(len(lst)): if(lst[i]==m): print(i) break Output: 3 Option 3 – Using min() and enumerate() 1 2 3 lst = [8,6,9,-1,2,0] a,i = min((a,i) for (i,a) in enumerate(lst)) print(i) Output: 3
If you need to convert a set to a string in Python, then you can do one of the following: Option 1 – Using map() and join() 1 str_new = ', '.join(list(map(str, se))) You can confirm this worked as follows: 1 2 3 4 5 print(str_new) print(type(str_new)) # '1, 2, 3' # <class 'str'> Option 2 – Using repr() 1 r_str = repr(se) You can confirm this worked as follows:
If you need to decrement a loop in Python, then you can do the following: How to Decrement a loop in Python using -1 The optional third argument you can pass to the range function is the order. The default order is to count up / increment, while the -1 value, is to count down / decrement. 1 2 for i in range(3, 0, -1): print(i) Output: 3 2 1
If you need to create a zip of a directory using Python, then you can do the following: Create a Zip using shutil in Python 1 2 3 4 5 6 7 8 import os import shutil filename = "compressed_archive" format = "zip" directory = os.getcwd() shutil.make_archive(filename, format, directory)
If you need to remove the last character of a string in PHP, then you can do the following: Option 1 – Using rtrim() Syntax: rtrim(\$string, \$character) 1 2 3 4 5 6 7 \$mystring = "This is a PHP program!"; echo("Before Removal: \$mystring\n"); # Before Removal: This is a PHP program! \$newstring = rtrim(\$mystring, ". "); echo("After Removal: \$newstring"); # After Removal: This is a PHP program Option 2 – Using substr() Syntax: substr(\$string, \$start, \$length)