-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/awk -f | ||
|
||
# Source: https://exercism.io/tracks/bash/exercises/acronym | ||
|
||
# Help generate some jargon by writing a program that converts a long name like | ||
# Portable Network Graphics to its acronym (PNG). | ||
|
||
BEGIN { | ||
if (ARGC == 1) { | ||
print "Usage:\n./acronym.awk <word1> <word2> ..."; | ||
exit 1; | ||
} | ||
|
||
acronym = ""; | ||
|
||
for (i = 1; i < ARGC; i++) { | ||
split(ARGV[i], array, ""); | ||
acronym = acronym array[1]; | ||
} | ||
|
||
print toupper(acronym); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/awk -f | ||
|
||
# Source: https://exercism.io/tracks/bash/exercises/armstrong-numbers | ||
|
||
# An Armstrong number is a number that is the sum of its own digits each raised | ||
# to the power of the number of digits. | ||
# For example: | ||
# 9 is an Armstrong number, because 9 = 9^1 = 9 | ||
# 10 is not an Armstrong number, because 10 != 1^2 + 0^2 = 1 | ||
# 153 is an Armstrong number, because: 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 | ||
# = 153 | ||
# 154 is not an Armstrong number, because: 154 != 1^3 + 5^3 + 4^3 = 1 + 125 | ||
# + 64 = 190 | ||
# | ||
# Write some code to determine whether a number is an Armstrong number. | ||
|
||
BEGIN { | ||
if (ARGC == 1) { | ||
print "Usage:\n./armstrong_numbers.awk <number>"; | ||
exit 1; | ||
} | ||
|
||
split(ARGV[1], digits, ""); | ||
sum = 0; | ||
len = length(ARGV[1]); | ||
|
||
for (i = 1; i <= len; i++) { | ||
split(ARGV[i], array, ""); | ||
|
||
sum += digits[i] ^ len; | ||
} | ||
|
||
if (ARGV[1] == sum) | ||
print "Armstrong number"; | ||
else | ||
print "Simple number"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/awk -f | ||
|
||
# Source: https://exercism.io/tracks/bash/exercises/error-handling | ||
|
||
BEGIN { | ||
if (ARGC <= 1) { | ||
print "Usage:\n./error_handling.awk <person>"; | ||
exit 1; | ||
} | ||
print "Hello, " ARGV[1]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/awk -f | ||
|
||
# Source: https://exercism.io/tracks/bash/exercises/hamming | ||
|
||
# Calculate the Hamming Distance between two DNA strands. | ||
# Your body is made up of cells that contain DNA. Those cells regularly wear | ||
# out and need replacing, which they achieve by dividing into daughter cells. | ||
# In fact, the average human body experiences about 10 quadrillion cell | ||
# divisions in a lifetime! | ||
# | ||
# When cells divide, their DNA replicates too. Sometimes during this process | ||
# mistakes happen and single pieces of DNA get encoded with the incorrect | ||
# information. If we compare two strands of DNA and count the differences | ||
# between them we can see how many mistakes occurred. This is known as the | ||
# "Hamming Distance". | ||
# | ||
# We read DNA using the letters C,A,G and T. Two strands might look like this: | ||
# GAGCCTACTAACGGGAT | ||
# CATCGTAATGACGGCCT | ||
# ^ ^ ^ ^ ^ ^^ | ||
# They have 7 differences, and therefore the Hamming Distance is 7. | ||
|
||
# Implementation notes | ||
# The Hamming distance is only defined for sequences of equal length, so an | ||
# attempt to calculate it between sequences of different lengths should not | ||
# work. | ||
|
||
BEGIN { | ||
if (ARGC <= 2) { | ||
print "Usage:\n./hamming.awk <dna1> <dna2>"; | ||
exit 1; | ||
} | ||
|
||
len1 = length(ARGV[1]); | ||
len2 = length(ARGV[2]); | ||
|
||
if (len1 != len2) { | ||
print "DNAs' lengths are not equal." | ||
exit 2; | ||
} | ||
|
||
split(ARGV[1], dna1, ""); | ||
split(ARGV[2], dna2, ""); | ||
|
||
hamming = 0; | ||
for (i = 1; i <= len1; i++) { | ||
if (dna1[i] != dna2[i]) | ||
hamming++; | ||
} | ||
|
||
print "Hamming distance: " hamming; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/awk -f | ||
|
||
BEGIN { | ||
print "Hello World" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/awk -f | ||
|
||
# Source: https://exercism.io/tracks/bash/exercises/raindrops | ||
|
||
# Your task is to convert a number into a string that contains raindrop sounds | ||
# corresponding to certain potential factors. A factor is a number that evenly | ||
# divides into another number, leaving no remainder. The simplest way to test | ||
# if a one number is a factor of another is to use the modulo operation. | ||
# The rules of raindrops are that if a given number: | ||
# has 3 as a factor, add 'Pling' to the result. | ||
# has 5 as a factor, add 'Plang' to the result. | ||
# has 7 as a factor, add 'Plong' to the result. | ||
# does not have any of 3, 5, or 7 as a factor, the result should be the | ||
# digits of the number. | ||
|
||
BEGIN { | ||
if (ARGC <= 1) { | ||
print "Usage:\n./raindrops.awk <number>"; | ||
exit 1; | ||
} | ||
|
||
sound = ""; | ||
|
||
if (ARGV[1] % 3 == 0) | ||
sound = sound "Pling"; | ||
if (ARGV[1] % 5 == 0) | ||
sound = sound "Plang"; | ||
if (ARGV[1] % 7 == 0) | ||
sound = sound "Plong"; | ||
if (sound == "") | ||
sound = ARGV[1]; | ||
|
||
print sound; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/awk -f | ||
|
||
# Source: https://exercism.io/tracks/bash/exercises/two-fer | ||
|
||
# Two-fer or 2-fer is short for two for one. One for you and one for me. | ||
# Given a name, return a string with the message: | ||
# One for name, one for me. | ||
# Where "name" is the given name. | ||
# However, if the name is missing, return the string: | ||
# One for you, one for me. | ||
|
||
BEGIN { | ||
if (ARGC > 1) | ||
you = ARGV[1]; | ||
else | ||
you = "you"; | ||
|
||
print "One for " you ", one for me."; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Exercise source: https://linux.die.net/Bash-Beginners-Guide/sect_06_05.html | ||
|
||
# For the this exercise, your input is lines in the following form: | ||
# Username:Firstname:Lastname:Telephone number | ||
# | ||
# Make an awk script that will convert such a line to an LDAP record in this | ||
# format: | ||
# dn: uid=Username, dc=example, dc=com | ||
# cn: Firstname Lastname | ||
# sn: Lastname | ||
# telephoneNumber: Telephone number | ||
# | ||
# Create a file containing a couple of test records and check. | ||
|
||
BEGIN { | ||
FS = ":"; | ||
} | ||
|
||
{ | ||
print "dn: uid=" $1 ", dc=example, dc=com"; | ||
print "cn: " $2 " " $3; | ||
print "sn: " $3; | ||
print "telephoneNumber: " $4; | ||
print ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
damian:Barbara:Collins:929-233-5128 | ||
danika_toy:Kathryn:Reed:781-492-9464 | ||
vida:Robert:Jones:626-641-1456 | ||
jordan:Debbie:Phillips:646-515-9319 | ||
Rosalveryb:Danny:Major:601-804-3755 | ||
selfpropulsion:Katie:Dart:504-442-3536 | ||
sitsang:Brett:Rivas:870-751-8983 | ||
felipa_sta1988:Jerry:Beaver:432-249-8790 | ||
alvis:Julie:Carter:334-524-9935 | ||
JBU21219:Shane:Ogg:208-680-9156 |