Skip to main content

Posts

Showing posts from June, 2015

Divisibility rules

Divisibility Rule for 2 and Powers of 2 A number is divisible by  if and only if the last  digits of the number are divisible by . Thus, in particular, a number is divisible by 2 if and only if its units digit is divisible by 2, i.e. if the number ends in 0, 2, 4, 6 or 8. Proof Divisibility Rule for 3 and 9 A number is divisible by 3 or 9 if and only if the sum of its digits is divisible by 3 or 9, respectively. Note that this does not work for higher powers of 3. For instance, the sum of the digits of 1899 is divisible by 27, but 1899 is not itself divisible by 27. Proof Divisibility Rule for 5 and Powers of 5 A number is divisible by  if and only if the last  digits are divisible by that power of 5. Proof Divisibility Rule for 7 Rule 1: Partition  into 3 digit numbers from the right (). The alternating sum () is divisible by 7 if and only if  is divisible by 7. Proof Rule 2: Truncate the last digit of , double that digit, and subtract it from the rest of the number (or vice-versa).  is div…

Divisibility rules in hex

We all learn in elementary school that a number is divisible by 2 if the last digit is even. A number is divisible by 3 if the sum of the digits is divisible by 3. A number is divisible by 5 if its last digit is 0 or 5. Etc. But imagine we were born with 8 fingers on each hand and did arithmetic in base 16, also called hexadecimal. Or suppose schools decided to teach children hexadecimal instead of decimal to give them a head start in computer science. We would count 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10, 11, … What would divisibility rules look like? Here are the simplest rules. n divisible by 2 if its last digit is even.n is divisible by 3 if its digit sum is divisible by 3.n is divisible by 4 if its last digit is 0, 4, 8, or C.n is divisible by 5 if its digit sum is divisible by 5.n is divisible by 6 if it is divisible by 2 and 3.n is divisible by 8 if it ends in 0 or 8.n is divisible by A if it is divisible by 2 and 5.n is divisible by F if its digit sum is divisible …

Awk Introduction Tutorial

Awk Introduction and Printing Operations Awk is a programming language which allows easy manipulation of structured data and the generation of formatted reports. Awk stands for the names of its authors “Aho, Weinberger, and Kernighan” The Awk is mostly used for pattern scanning and processing. It searches one or more files to see if they contain lines that matches with the specified patterns and then perform associated actions. Some of the key features of Awk are: Awk views a text file as records and fields.Like common programming language, Awk has variables, conditionals and loopsAwk has arithmetic and string operators.Awk can generate formatted reports Awk reads from a file or from its standard input, and outputs to its standard output. Awk does not get along with non-text files. Syntax: awk '/search pattern1/ {Actions} /search pattern2/ {Actions}' file In the above awk syntax: search pattern is a regular expression.Actions – statement(s) to be performed.several patterns…

50 Most Frequently Used UNIX / Linux Commands (With Examples)

1. tar command examples Create a new tar archive. $ tar cvf archive_name.tar dirname/ Extract from an existing tar archive. $ tar xvf archive_name.tar View an existing tar archive. $ tar tvf archive_name.tar More tar examples: The Ultimate Tar Command Tutorial with 10 Practical Examples 2. grep command examples Search for a given string in a file (case in-sensitive search). $ grep -i "the" demo_file Print the matched line, along with the 3 lines after it. $ grep -A 3 -i "example" demo_text Search for a given string in all files recursively $ grep -r "ramesh" * More grep examples: Get a Grip on the Grep! – 15 Practical Grep Command Examples 3. find command examples Find files using file-name ( case in-sensitve find) # find -iname "MyCProgram.c" Execute commands on files found by the find command $ find -iname "MyCProgram.c" -exec md5sum {} \; Find all empty files in home directory # find ~ -empty More find examples: Mommy, I found it! …