How to update NTP to sync clock on Linux

If you need to sync the clock on Linux using the central NTP clock service, you can do the following: 1 2 3 sudo service ntp stop sudo ntpd -gq sudo service ntp start The -gg flags do the following: Tell g flag tells the NTP Daemon to correct the time regardless of the offset The q flag tells it to exit immediately after setting the time

How to Find IP Address Ranges used by Amazon S3

You can query the ip-ranges Amazon AWS URL, and parse the results through jq as follows: Generic S3 IP Ranges Query: 1 curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes[] | select(.service=="S3")' Response: 1 2 3 4 5 6 7 8 9 10 11 { "ip_prefix": "3.5.140.0/22", "region": "ap-northeast-2", "service": "S3", "network_border_group": "ap-northeast-2" } { "ip_prefix": "52.219.170.0/23", "region": "eu-central-1", "service": "S3", <truncated> Region Specific S3 IP Ranges Query: 1 curl -s https://ip-ranges.

How to Find the nth Reverse Number in Java

The challenge Reverse Number is a number which is the same when reversed. For example, the first 20 Reverse Numbers are: 1 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101 Task You need to return the nth reverse number. (Assume that reverse numbers start from 0 as shown in the example.) Notes 1 < n <= 100000000000 The solution in Java Option 1:

How to Find the Sum of Intervals in Java

The challenge Write a function called sumIntervals/sum_intervals() that accepts an array of intervals, and returns the sum of all the interval lengths. Overlapping intervals should only be counted once. Intervals Intervals are represented by a pair of integers in the form of an array. The first value of the interval will always be less than the second value. Interval example: [1, 5] is an interval from 1 to 5. The length of this interval is 4.

How to Find the Stray Number in Python

The challenge You are given an odd-length array of integers, in which all of them are the same, except for one single number. Complete the method which accepts such an array, and returns that single different number. The input array will always be valid! (odd-length >= 3) Examples 1 2 [1, 1, 2] ==> 2 [17, 17, 3, 17, 17, 17, 17] ==> 3 The solution in Python Option 1:

[Solved] jsii.errors.JSIIError: docker exited with status 1

If you get the following error while running AWS CDK: 1 2 raise JSIIError(resp.error) from JavaScriptError(resp.stack) jsii.errors.JSIIError: docker exited with status 1 Then you can resolve it as follows: How to solve docker exited with status 1 error Make sure that your local Docker client is running. Start docker on the local machine and CDK will be able to make the Docker connections required.

How to Filter a Number in C

The challenge The number has been mixed up with the text. Your goal is to retrieve the number from the text, can you return the number back to its original state? Task Your task is to return a number from a string. Details You will be given a string of numbers and letters mixed up, you have to return all the numbers in that string in the order they occur.

How to Take a Ten Minute Walk in C

The challenge You live in the city of Cartesia where all roads are laid out in a perfect grid. You arrived ten minutes too early to an appointment, so you decided to take the opportunity to go for a short walk. The city provides its citizens with a Walk Generating App on their phones — everytime you press the button it sends you an array of one-letter strings representing directions to walk (eg.

How to Count Stats of a String in C

The challenge You will be given a string and your task will be to return a list of ints detailing the count of uppercase letters, lowercase, numbers and special characters, as follows. 1 2 Solve("*'&ABCDabcde12345") = [4,5,5,3]. --the order is: uppercase letters, lowercase, numbers and special characters. The solution in C Option 1: 1 2 3 4 5 6 7 8 9 10 void count_char_types (const char *string, unsigned counts[4]) { char c; counts[0] = counts[1] = counts[2] = counts[3] = 0; while((c = *string++)) if(c >= 'A' && c <= 'Z') counts[0]++; else if(c >= 'a' && c <= 'z') counts[1]++; else if(c >= '0' && c <= '9') counts[2]++; else counts[3]++; } Option 2:

How to Convert a String to the NATO Phonetic Alphabet in C

The challenge You’ll have to translate a string to Pilot’s alphabet (NATO phonetic alphabet). Input: If, you can read? Output: India Foxtrot , Yankee Oscar Uniform Charlie Alfa November Romeo Echo Alfa Delta ? Note: There are preloaded dictionary you can use, named NATO The set of used punctuation is ,.!?. Punctuation should be kept in your return string, but spaces should not. Xray should not have a dash within. Every word and punctuation mark should be seperated by a space ‘ ‘.

How to Add 1 to the Value of each Array in C

The challenge Given an array of integers of any length, return an array that has 1 added to the value represented by the array. the array can’t be empty only non-negative, single digit integers are allowed Return nil (or your language’s equivalent) for invalid inputs. Examples: Valid arrays [4, 3, 2, 5] would return [4, 3, 2, 6] [1, 2, 3, 9] would return [1, 2, 4, 0] [9, 9, 9, 9] would return [1, 0, 0, 0, 0]

How to Calculate the Sum of a Sequence in C

The challenge Your task is to make function, which returns the sum of a sequence of integers. The sequence is defined by 3 non-negative values: begin, end, step (inclusive). If begin value is greater than the end, function should returns **** Examples 1 2 3 4 2,2,2 --> 2 2,6,2 --> 12 (2 + 4 + 6) 1,5,1 --> 15 (1 + 2 + 3 + 4 + 5) 1,5,3 --> 5 (1 + 4) The solution in C Option 1:

How to Solve the Sum of Triangular Numbers in C

The challenge Your task is to return the sum of Triangular Numbers up-to-and-including the nth Triangular Number. Triangular Number: “any of the series of numbers (1, 3, 6, 10, 15, etc.) obtained by continued summation of the natural numbers 1, 2, 3, 4, 5, etc.” 1 2 3 4 5 6 [01] 02 [03] 04 05 [06] 07 08 09 [10] 11 12 13 14 [15] 16 17 18 19 20 [21] e.

How to Determine if a String Only Contains Unique Characters in C

The challenge Write a program to determine if a string contains only unique characters. Return true if it does and false otherwise. The string may contain any of the 128 ASCII characters. Characters are case-sensitive, e.g. ‘a’ and ‘A’ are considered different characters. The solution in C Option 1: 1 2 3 4 5 int has_unique_chars(const char *str) { int mask[128]={0}; while (*str) if (++mask[*str++]>1) return 0; return 1; } Option 2:

How to Find the Maximum Multiple in C

The challenge Given a Divisor and a Bound , Find the largest integer N , Such That , Conditions : N is divisible by divisor N is less than or equal to bound N is greater than 0. Notes The parameters (divisor, bound) passed to the function are only positive values . It’s guaranteed that a divisor is Found .Input » Output Examples 1 maxMultiple (2,7) ==> return (6) Explanation:

How to Assign a Digital Cypher in C

The challenge Digital Cypher assigns to each letter of the alphabet unique number. For example: 1 2 3 4 a b c d e f g h i j k l m 1 2 3 4 5 6 7 8 9 10 11 12 13 n o p q r s t u v w x y z 14 15 16 17 18 19 20 21 22 23 24 25 26 Instead of letters in encrypted word we write the corresponding number, eg.

How to Check for All Inclusive in C

The challenge Input: a string strng an array of strings arr Output of function contain_all_rots(strng, arr) (or containAllRots or contain-all-rots): a boolean true if all rotations of strng are included in arr false otherwise Examples: 1 2 3 4 5 contain_all_rots( "bsjq", ["bsjq", "qbsj", "sjqb", "twZNsslC", "jqbs"]) -> true contain_all_rots( "Ajylvpy", ["Ajylvpy", "ylvpyAj", "jylvpyA", "lvpyAjy", "pyAjylv", "vpyAjyl", "ipywee"]) -> false) Note: Though not correct in a mathematical sense we will consider that there are no rotations of strng == "" and for any array arr: contain_all_rots("", arr) --> true The solution in C Option 1:

How to Solve for Factorial in C

The challenge In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example: 5! = 5 * 4 * 3 * 2 * 1 = 120. By convention the value of 0! is 1. Write a function to calculate factorial for a given input. If input is below 0 or above 12 return -1 (C).

How to Create an Incrementer in C

The challenge Given an input of an array of digits, return the array with each digit incremented by its position in the array: the first digit will be incremented by 1, the second digit by 2, etc. Make sure to start counting your positions from 1 ( and not 0 ). Your result can only contain single digit numbers, so if adding a digit with its position gives you a multiple-digit number, only the last digit of the number should be returned.