From 3a7a8436bdaa9b6ad39d7a8e27cb25f72d348e37 Mon Sep 17 00:00:00 2001 From: d-l-mcbride Date: Sun, 11 Oct 2020 19:47:36 -0700 Subject: [PATCH 01/15] Add @d-l-mcbride as a contributor --- .all-contributorsrc | 13 ++++++++++- CONTRIBUTORS.md | 57 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 86d86a78..4342ac5d 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -318,6 +318,17 @@ "doc", "code" ] + }, + { + "login": "d-l-mcbride", + "name": "d-l-mcbride", + "avatar_url": "https://avatars3.githubusercontent.com/u/46550732?v=4", + "profile": "https://github.com/d-l-mcbride", + "contributions": [ + "doc", + "code" + ] } - ] + ], + "commitConvention": "none" } diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 5b193e77..39699d08 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -5,13 +5,56 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): - -| [MADHAV BAHL
MADHAV BAHL](http://madhavbahl.tech/)
[💻](https://github.com/CodeToExpress/dailycodebase/commits?author=MadhavBahlMD "Code") [📝](#blog-MadhavBahlMD "Blogposts") [📖](https://github.com/CodeToExpress/dailycodebase/commits?author=MadhavBahlMD "Documentation") [🎨](#design-MadhavBahlMD "Design") [✅](#tutorial-MadhavBahlMD "Tutorials") | [Rajdeep Roy Chowdhury
Rajdeep Roy Chowdhury](http://www.linkedin.com/in/razdeeproychowdhury)
[💻](https://github.com/CodeToExpress/dailycodebase/commits?author=Razdeep "Code") [📖](https://github.com/CodeToExpress/dailycodebase/commits?author=Razdeep "Documentation") [✅](#tutorial-Razdeep "Tutorials") | [Hrishi
Hrishi](https://hrishi1999.github.io)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=Hrishi1999 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=Hrishi1999 "Code") | [Bhanu Ailani
Bhanu Ailani](https://github.com/Bhanu0202)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=Bhanu0202 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=Bhanu0202 "Code") | [Deepak Sharma
Deepak Sharma](https://sourcerer.io/dsdsharma)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=dsdsharma "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=dsdsharma "Code") | [Ramanpreet Singh
Ramanpreet Singh](https://github.com/Ramanpreet6262)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=Ramanpreet6262 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=Ramanpreet6262 "Code") | [Anil Khatri
Anil Khatri](https://imkaka.github.io/)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=imkaka "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=imkaka "Code") | -| :---: | :---: | :---: | :---: | :---: | :---: | :---: | -| [Ashwek Swamy
Ashwek Swamy](https://github.com/ashwek)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=ashwek "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=ashwek "Code") | [Dhruv Gupta
Dhruv Gupta](https://github.com/dhruv-gupta14)
[💻](https://github.com/CodeToExpress/dailycodebase/commits?author=dhruv-gupta14 "Code") | [Aadit Kamat
Aadit Kamat](https://sg.linkedin.com/in/aadit-kamat-12a5a8140)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=aaditkamat "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=aaditkamat "Code") | [Shashank jain
Shashank jain](http://www.myshashank.tech)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=Shashankjain12 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=Shashankjain12 "Code") | [Moulik Aggarwal
Moulik Aggarwal](https://github.com/moulikcipherX)
[💬](#question-moulikcipherX "Answering Questions") [📝](#blog-moulikcipherX "Blogposts") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=moulikcipherX "Code") [📖](https://github.com/CodeToExpress/dailycodebase/commits?author=moulikcipherX "Documentation") | [Prateek Surana
Prateek Surana](http://prateeksurana.me)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=prateek3255 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=prateek3255 "Code") | [shivank86
shivank86](https://github.com/shivank86)
[💻](https://github.com/CodeToExpress/dailycodebase/commits?author=shivank86 "Code") | -| [Vishal Shirke
Vishal Shirke](https://github.com/vishalshirke7)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=vishalshirke7 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=vishalshirke7 "Code") | [profgrammer
profgrammer](https://github.com/profgrammer)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=profgrammer "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=profgrammer "Code") | [divyakhetan
divyakhetan](https://github.com/divyakhetan)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=divyakhetan "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=divyakhetan "Code") | [Spreeha Dutta
Spreeha Dutta](https://github.com/Spreeha)
[💻](https://github.com/CodeToExpress/dailycodebase/commits?author=Spreeha "Code") [📖](https://github.com/CodeToExpress/dailycodebase/commits?author=Spreeha "Documentation") | [Chaitanya Bhojwani
Chaitanya Bhojwani](https://github.com/chaitanya-bhojwani)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=chaitanya-bhojwani "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=chaitanya-bhojwani "Code") | [Manaswini Das
Manaswini Das](https://www.linkedin.com/in/manaswini-das/)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=manaswinidas "Documentation") | [Anirudh Jwala
Anirudh Jwala](https://www.linkedin.com/in/anirudh-jwala-533859135/)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=anirudh-jwala "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=anirudh-jwala "Code") | -| [Willian Taiguara Baliza Moura
Willian Taiguara Baliza Moura](https://github.com/willianwt)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=willianwt "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=willianwt "Code") | [Rajashree Parhi
Rajashree Parhi](https://github.com/rajashree23)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=rajashree23 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=rajashree23 "Code") | [Akshit Aggarwal
Akshit Aggarwal](https://github.com/AkshitAggarwal)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=AkshitAggarwal "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=AkshitAggarwal "Code") | [Abhishek
Abhishek](https://github.com/dasabhishek0790)
[💻](https://github.com/CodeToExpress/dailycodebase/commits?author=dasabhishek0790 "Code") | [SAGUN JAISWAL
SAGUN JAISWAL](https://github.com/sagunjaiswal)
[💻](https://github.com/CodeToExpress/dailycodebase/commits?author=sagunjaiswal "Code") | [Abhishek Anantharam
Abhishek Anantharam](https://github.com/abhishek0405)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=abhishek0405 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=abhishek0405 "Code") | [Prabhat Malhotra
Prabhat Malhotra](https://github.com/malhotra1432)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=malhotra1432 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=malhotra1432 "Code") | -| [Hrishikesh K Thakkar
Hrishikesh K Thakkar](https://github.com/Hrishikesh-Thakkar)
[💻](https://github.com/CodeToExpress/dailycodebase/commits?author=Hrishikesh-Thakkar "Code") | [GAURAV KUMAR
GAURAV KUMAR](https://github.com/gaurav01k3)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=gaurav01k3 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=gaurav01k3 "Code") | [wboccard
wboccard](https://github.com/wboccard)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=wboccard "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=wboccard "Code") | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

MADHAV BAHL

💻 📝 📖 🎨

Rajdeep Roy Chowdhury

💻 📖

Hrishi

📖 💻

Bhanu Ailani

📖 💻

Deepak Sharma

📖 💻

Ramanpreet Singh

📖 💻

Anil Khatri

📖 💻

Ashwek Swamy

📖 💻

Dhruv Gupta

💻

Aadit Kamat

📖 💻

Shashank jain

📖 💻

Moulik Aggarwal

💬 📝 💻 📖

Prateek Surana

📖 💻

shivank86

💻

Vishal Shirke

📖 💻

profgrammer

📖 💻

divyakhetan

📖 💻

Spreeha Dutta

💻 📖

Chaitanya Bhojwani

📖 💻

Manaswini Das

📖

Anirudh Jwala

📖 💻

Willian Taiguara Baliza Moura

📖 💻

Rajashree Parhi

📖 💻

Akshit Aggarwal

📖 💻

Abhishek

💻

SAGUN JAISWAL

💻

Abhishek Anantharam

📖 💻

Prabhat Malhotra

📖 💻

Hrishikesh K Thakkar

💻

GAURAV KUMAR

📖 💻

wboccard

📖 💻

d-l-mcbride

📖 💻
+ + + + This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind are welcome! From 1982f9080e8c881fd31b44b43945a48b7db3aa2d Mon Sep 17 00:00:00 2001 From: d-l-mcbride Date: Sun, 11 Oct 2020 22:15:56 -0700 Subject: [PATCH 02/15] Add Kotlin solution for string reversal and palindrome validation. --- Day2/Kotlin/ReverseAndPalinedrome.kts | 34 +++++++++++++++++++++ Day2/README.md | 43 +++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 Day2/Kotlin/ReverseAndPalinedrome.kts diff --git a/Day2/Kotlin/ReverseAndPalinedrome.kts b/Day2/Kotlin/ReverseAndPalinedrome.kts new file mode 100644 index 00000000..cc542d6c --- /dev/null +++ b/Day2/Kotlin/ReverseAndPalinedrome.kts @@ -0,0 +1,34 @@ +/** + * @author: d-l-mcbride + * @date: 10/11/2020 + **/ + +fun reverse(subject:String):String { + var reversed = StringBuilder() + + for( j in (subject.length -1) downTo 0){ + reversed.append(subject[j]) + } + return reversed.toString() +} + + +fun palindrome(subject:String){ + val reversed = reverse(subject) + if (reversed == subject) println("${subject} is a palindrome") else println("${subject} is not a palindrome") +} + +val hello = "Hello" +val goodbye = "Goodbye" +val single = "S" + +println("Reverse String Tests") +println("${hello} reversed is ${reverse(hello)}") +println("${goodbye} reversed is ${reverse(goodbye)}") +println ("${single} reversed is ${reverse(single)}") + +println("\n\nPalindrome Tests") +palindrome("I") +palindrome("otto") +palindrome("tacocat") +palindrome("dog") diff --git a/Day2/README.md b/Day2/README.md index c0743faf..7834d9f4 100644 --- a/Day2/README.md +++ b/Day2/README.md @@ -981,6 +981,49 @@ public class StringReverseAndPalin { } ``` +## Kotlin Implementation + +### [FizzBuzz.kts](./Kotlin/ReverseAndPalindrome.kts) + +##### To run this script `kotlinc -script ReverseAndPalindrome.kts` + _*Prereq: Kotlin must be installed._ +``` +/** + * @author: d-l-mcbride + * @date: 10/11/2020 + **/ + +fun reverse(subject:String):String { + var reversed = StringBuilder() + + for( j in (subject.length -1) downTo 0){ + reversed.append(subject[j]) + } + return reversed.toString() +} + + +fun palindrome(subject:String){ + val reversed = reverse(subject) + if (reversed == subject) println("${subject} is a palindrome") else println("${subject} is not a palindrome") +} + +val hello = "Hello" +val goodbye = "Goodbye" +val single = "S" + +println("Reverse String Tests") +println("${hello} reversed is ${reverse(hello)}") +println("${goodbye} reversed is ${reverse(goodbye)}") +println ("${single} reversed is ${reverse(single)}") + +println("\n\nPalindrome Tests") +palindrome("I") +palindrome("otto") +palindrome("tacocat") +palindrome("dog") +``` + ### Have Another solution? The beauty of programming lies in the fact that there is never a single solution to any problem. From 5099b850597c1a6d4bc2b19078dc32150f2c3a21 Mon Sep 17 00:00:00 2001 From: d-l-mcbride Date: Mon, 12 Oct 2020 06:45:02 -0700 Subject: [PATCH 03/15] Add Kotlin solution for Day3 and fix Typo in Day2 README.md --- Day2/README.md | 2 +- Day3/Kotlin/HammingDistance.kts | 27 +++++++++++++++++++++++ Day3/README.md | 39 +++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 Day3/Kotlin/HammingDistance.kts diff --git a/Day2/README.md b/Day2/README.md index 7834d9f4..e065cd0f 100644 --- a/Day2/README.md +++ b/Day2/README.md @@ -983,7 +983,7 @@ public class StringReverseAndPalin { ## Kotlin Implementation -### [FizzBuzz.kts](./Kotlin/ReverseAndPalindrome.kts) +### [ReverseAndPalindrome.kts](./Kotlin/ReverseAndPalindrome.kts) ##### To run this script `kotlinc -script ReverseAndPalindrome.kts` _*Prereq: Kotlin must be installed._ diff --git a/Day3/Kotlin/HammingDistance.kts b/Day3/Kotlin/HammingDistance.kts new file mode 100644 index 00000000..122aa459 --- /dev/null +++ b/Day3/Kotlin/HammingDistance.kts @@ -0,0 +1,27 @@ +/** + * @author: d-l-mcbride + * @date: 10/12/2020 + **/ + +fun hammingDistance(first: String, second: String ):Int { + var distance = 0 + for(i in first.indices) { + if (first[i] != second[i]) distance++ + } + return distance +} + +val DOG = "dog" +val LOG = "log" +val LARRY = "larry" +val LASSI ="lassi" +val EMPTY = "" +val ALSO_EMPTY = "" +val ABCDE = "abcde" +val BADEC = "badec" + +println("Hamming Distance of ${DOG} and ${LOG} = ${hammingDistance(DOG,LOG)}") +println("Hamming Distance of ${LOG} and ${LOG} = ${hammingDistance(LOG,LOG)}") +println("Hamming Distance of ${LARRY} and ${LASSI} = ${hammingDistance(LARRY,LASSI)}") +println("Hamming Distance of ${ABCDE} and ${BADEC} = ${hammingDistance(ABCDE,BADEC)}") +println("Hamming Distance of two empty strings = ${hammingDistance(EMPTY,ALSO_EMPTY)}") diff --git a/Day3/README.md b/Day3/README.md index dfcc3a21..2a81cde2 100644 --- a/Day3/README.md +++ b/Day3/README.md @@ -402,6 +402,8 @@ print("list of unmatched characters are:",k) print("number of characters not matching are:",len(k)) ``` + +``` /* @date 4/09/2020 * @author Shashwat Gupta (shashwatxdevelop) */ @@ -434,7 +436,44 @@ public class HammingDistance { } } +``` +## Kotlin Implementation + +### [HammingDistance.kts](./Kotlin/HammingDistance.kts) + +##### To run this script `kotlinc -script HammingDistance.kts` + _*Prereq: Kotlin must be installed._ + +``` +/** + * @author: d-l-mcbride + * @date: 10/12/2020 + **/ + +fun hammingDistance(first: String, second: String ):Int { + var distance = 0 + for(i in first.indices) { + if (first[i] != second[i]) distance++ + } + return distance +} + +val DOG = "dog" +val LOG = "log" +val LARRY = "larry" +val LASSI ="lassi" +val EMPTY = "" +val ALSO_EMPTY = "" +val ABCDE = "abcde" +val BADEC = "badec" + +println("Hamming Distance of ${DOG} and ${LOG} = ${hammingDistance(DOG,LOG)}") +println("Hamming Distance of ${LOG} and ${LOG} = ${hammingDistance(LOG,LOG)}") +println("Hamming Distance of ${LARRY} and ${LASSI} = ${hammingDistance(LARRY,LASSI)}") +println("Hamming Distance of ${ABCDE} and ${BADEC} = ${hammingDistance(ABCDE,BADEC)}") +println("Hamming Distance of two empty strings = ${hammingDistance(EMPTY,ALSO_EMPTY)}") +``` ## Why Hamming Distance? From 69485f46284a3327074eeec52cace43839d009d1 Mon Sep 17 00:00:00 2001 From: d-l-mcbride Date: Mon, 12 Oct 2020 18:27:33 -0700 Subject: [PATCH 04/15] Add Kotlin solution for day4. --- day4/Kotlin/NumVowelsAndMaxChars.kts | 50 +++++++++++++++++++++++ day4/README.md | 61 +++++++++++++++++++++++++++- 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 day4/Kotlin/NumVowelsAndMaxChars.kts diff --git a/day4/Kotlin/NumVowelsAndMaxChars.kts b/day4/Kotlin/NumVowelsAndMaxChars.kts new file mode 100644 index 00000000..58e4d08b --- /dev/null +++ b/day4/Kotlin/NumVowelsAndMaxChars.kts @@ -0,0 +1,50 @@ +/** + * @author: d-l-mcbride + * @date: 10/11/2020 + **/ + +fun numberOfVowels(subject: String):Int{ + val vowels = hashSetOf('a','e','i','o','u') + var count = 0 + subject.forEach { + when(it.toLowerCase()) { + in vowels -> count++ + } + } + return count +} + +fun maxChars(subject: String):Char { + var maxChar = subject[0] + var maxCount = 0 + var count:Int + for(i in 0 until subject.length -1) { + count = 0 + for(j in i+1 until subject.length) { + if (subject[i] == subject[j]) count++ + } + if( count > maxCount) { + maxCount = count + maxChar = subject[i] + } + } + return maxChar +} + + + +val TWO_VOWELS = "hello" +val TWO_VOWELS_WITH_CAPS = "HELLO" +val NO_VOWELS = "qrzmtlnz" +println("${TWO_VOWELS} contains ${numberOfVowels(TWO_VOWELS)} vowels.") +println("${TWO_VOWELS_WITH_CAPS} contains ${numberOfVowels(TWO_VOWELS_WITH_CAPS)} vowels.") +println("${NO_VOWELS} contains ${numberOfVowels(NO_VOWELS)} vowels.") + +val THREE_MID = "helllo" +val ONE_EACH = "abcd" +val FOUR_END = "byeeee" +val FOUR_BEG = "yyyyes" +println("The letter with the most occurences in ${THREE_MID} is ${maxChars(THREE_MID)}") +println("The letter with the most occurences in ${ONE_EACH} is ${maxChars(ONE_EACH)}") +println("The letter with the most occurences in ${FOUR_END} is ${maxChars(FOUR_END)}") +println("The letter with the most occurences in ${FOUR_BEG} is ${maxChars(FOUR_BEG)}") diff --git a/day4/README.md b/day4/README.md index e9c5f930..dd577e03 100644 --- a/day4/README.md +++ b/day4/README.md @@ -887,10 +887,69 @@ print "Enter a string: " str = gets str.chomp! puts "The most frequent character in #{str} is : #{most_frequent_character(str)}" +``` +## Kotlin Implementation + +### [NumVowelsAndMaxChars.kts](./Kotlin/NumVowelsAndMaxChars.kts) + +##### To run this script `kotlinc -script NumVowelsAndMaxChars.kts` + +``` +/** + * @author: d-l-mcbride + * @date: 10/11/2020 + **/ + +fun numberOfVowels(subject: String):Int{ + val vowels = hashSetOf('a','e','i','o','u') + var count = 0 + subject.forEach { + when(it.toLowerCase()) { + in vowels -> count++ + } + } + return count +} + +fun maxChars(subject: String):Char { + var maxChar = subject[0] + var maxCount = 0 + var count:Int + for(i in 0 until subject.length -1) { + count = 0 + for(j in i+1 until subject.length) { + if (subject[i] == subject[j]) count++ + } + if( count > maxCount) { + maxCount = count + maxChar = subject[i] + } + } + return maxChar +} + + + +val TWO_VOWELS = "hello" +val TWO_VOWELS_WITH_CAPS = "HELLO" +val NO_VOWELS = "qrzmtlnz" +println("${TWO_VOWELS} contains ${numberOfVowels(TWO_VOWELS)} vowels.") +println("${TWO_VOWELS_WITH_CAPS} contains ${numberOfVowels(TWO_VOWELS_WITH_CAPS)} vowels.") +println("${NO_VOWELS} contains ${numberOfVowels(NO_VOWELS)} vowels.") + +val THREE_MID = "helllo" +val ONE_EACH = "abcd" +val FOUR_END = "byeeee" +val FOUR_BEG = "yyyyes" +println("The letter with the most occurences in ${THREE_MID} is ${maxChars(THREE_MID)}") +println("The letter with the most occurences in ${ONE_EACH} is ${maxChars(ONE_EACH)}") +println("The letter with the most occurences in ${FOUR_END} is ${maxChars(FOUR_END)}") +println("The letter with the most occurences in ${FOUR_BEG} is ${maxChars(FOUR_BEG)}") + ``` ### Have Another solution? The beauty of programming lies in the fact that there is never a single solution to any problem. -In case you have an alternative way to solve this problem, do contribute to this repository (https://github.com/CodeToExpress/dailycodebase) :) \ No newline at end of file +In case you have an alternative way to solve this problem, do contribute to this repository (https://github.com/CodeToExpress/dailycodebase) :) From 3c48b376f0acd2a65605d601b6b09996b725045b Mon Sep 17 00:00:00 2001 From: d-l-mcbride <46550732+d-l-mcbride@users.noreply.github.com> Date: Thu, 15 Oct 2020 06:38:59 -0700 Subject: [PATCH 05/15] Day one Kotlin for Hacktoberfest (#358) * Add @d-l-mcbride as a contributor * Add Kotlin solution for FizzBuzz Co-authored-by: d-l-mcbride --- .all-contributorsrc | 13 ++++++++- CONTRIBUTORS.md | 57 +++++++++++++++++++++++++++++++++++----- Day1/Kotlin/FizzBuzz.kts | 21 +++++++++++++++ Day1/README.md | 30 +++++++++++++++++++++ 4 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 Day1/Kotlin/FizzBuzz.kts diff --git a/.all-contributorsrc b/.all-contributorsrc index 86d86a78..4342ac5d 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -318,6 +318,17 @@ "doc", "code" ] + }, + { + "login": "d-l-mcbride", + "name": "d-l-mcbride", + "avatar_url": "https://avatars3.githubusercontent.com/u/46550732?v=4", + "profile": "https://github.com/d-l-mcbride", + "contributions": [ + "doc", + "code" + ] } - ] + ], + "commitConvention": "none" } diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 5b193e77..39699d08 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -5,13 +5,56 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): - -| [MADHAV BAHL
MADHAV BAHL](http://madhavbahl.tech/)
[💻](https://github.com/CodeToExpress/dailycodebase/commits?author=MadhavBahlMD "Code") [📝](#blog-MadhavBahlMD "Blogposts") [📖](https://github.com/CodeToExpress/dailycodebase/commits?author=MadhavBahlMD "Documentation") [🎨](#design-MadhavBahlMD "Design") [✅](#tutorial-MadhavBahlMD "Tutorials") | [Rajdeep Roy Chowdhury
Rajdeep Roy Chowdhury](http://www.linkedin.com/in/razdeeproychowdhury)
[💻](https://github.com/CodeToExpress/dailycodebase/commits?author=Razdeep "Code") [📖](https://github.com/CodeToExpress/dailycodebase/commits?author=Razdeep "Documentation") [✅](#tutorial-Razdeep "Tutorials") | [Hrishi
Hrishi](https://hrishi1999.github.io)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=Hrishi1999 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=Hrishi1999 "Code") | [Bhanu Ailani
Bhanu Ailani](https://github.com/Bhanu0202)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=Bhanu0202 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=Bhanu0202 "Code") | [Deepak Sharma
Deepak Sharma](https://sourcerer.io/dsdsharma)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=dsdsharma "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=dsdsharma "Code") | [Ramanpreet Singh
Ramanpreet Singh](https://github.com/Ramanpreet6262)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=Ramanpreet6262 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=Ramanpreet6262 "Code") | [Anil Khatri
Anil Khatri](https://imkaka.github.io/)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=imkaka "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=imkaka "Code") | -| :---: | :---: | :---: | :---: | :---: | :---: | :---: | -| [Ashwek Swamy
Ashwek Swamy](https://github.com/ashwek)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=ashwek "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=ashwek "Code") | [Dhruv Gupta
Dhruv Gupta](https://github.com/dhruv-gupta14)
[💻](https://github.com/CodeToExpress/dailycodebase/commits?author=dhruv-gupta14 "Code") | [Aadit Kamat
Aadit Kamat](https://sg.linkedin.com/in/aadit-kamat-12a5a8140)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=aaditkamat "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=aaditkamat "Code") | [Shashank jain
Shashank jain](http://www.myshashank.tech)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=Shashankjain12 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=Shashankjain12 "Code") | [Moulik Aggarwal
Moulik Aggarwal](https://github.com/moulikcipherX)
[💬](#question-moulikcipherX "Answering Questions") [📝](#blog-moulikcipherX "Blogposts") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=moulikcipherX "Code") [📖](https://github.com/CodeToExpress/dailycodebase/commits?author=moulikcipherX "Documentation") | [Prateek Surana
Prateek Surana](http://prateeksurana.me)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=prateek3255 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=prateek3255 "Code") | [shivank86
shivank86](https://github.com/shivank86)
[💻](https://github.com/CodeToExpress/dailycodebase/commits?author=shivank86 "Code") | -| [Vishal Shirke
Vishal Shirke](https://github.com/vishalshirke7)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=vishalshirke7 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=vishalshirke7 "Code") | [profgrammer
profgrammer](https://github.com/profgrammer)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=profgrammer "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=profgrammer "Code") | [divyakhetan
divyakhetan](https://github.com/divyakhetan)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=divyakhetan "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=divyakhetan "Code") | [Spreeha Dutta
Spreeha Dutta](https://github.com/Spreeha)
[💻](https://github.com/CodeToExpress/dailycodebase/commits?author=Spreeha "Code") [📖](https://github.com/CodeToExpress/dailycodebase/commits?author=Spreeha "Documentation") | [Chaitanya Bhojwani
Chaitanya Bhojwani](https://github.com/chaitanya-bhojwani)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=chaitanya-bhojwani "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=chaitanya-bhojwani "Code") | [Manaswini Das
Manaswini Das](https://www.linkedin.com/in/manaswini-das/)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=manaswinidas "Documentation") | [Anirudh Jwala
Anirudh Jwala](https://www.linkedin.com/in/anirudh-jwala-533859135/)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=anirudh-jwala "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=anirudh-jwala "Code") | -| [Willian Taiguara Baliza Moura
Willian Taiguara Baliza Moura](https://github.com/willianwt)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=willianwt "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=willianwt "Code") | [Rajashree Parhi
Rajashree Parhi](https://github.com/rajashree23)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=rajashree23 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=rajashree23 "Code") | [Akshit Aggarwal
Akshit Aggarwal](https://github.com/AkshitAggarwal)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=AkshitAggarwal "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=AkshitAggarwal "Code") | [Abhishek
Abhishek](https://github.com/dasabhishek0790)
[💻](https://github.com/CodeToExpress/dailycodebase/commits?author=dasabhishek0790 "Code") | [SAGUN JAISWAL
SAGUN JAISWAL](https://github.com/sagunjaiswal)
[💻](https://github.com/CodeToExpress/dailycodebase/commits?author=sagunjaiswal "Code") | [Abhishek Anantharam
Abhishek Anantharam](https://github.com/abhishek0405)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=abhishek0405 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=abhishek0405 "Code") | [Prabhat Malhotra
Prabhat Malhotra](https://github.com/malhotra1432)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=malhotra1432 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=malhotra1432 "Code") | -| [Hrishikesh K Thakkar
Hrishikesh K Thakkar](https://github.com/Hrishikesh-Thakkar)
[💻](https://github.com/CodeToExpress/dailycodebase/commits?author=Hrishikesh-Thakkar "Code") | [GAURAV KUMAR
GAURAV KUMAR](https://github.com/gaurav01k3)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=gaurav01k3 "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=gaurav01k3 "Code") | [wboccard
wboccard](https://github.com/wboccard)
[📖](https://github.com/CodeToExpress/dailycodebase/commits?author=wboccard "Documentation") [💻](https://github.com/CodeToExpress/dailycodebase/commits?author=wboccard "Code") | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

MADHAV BAHL

💻 📝 📖 🎨

Rajdeep Roy Chowdhury

💻 📖

Hrishi

📖 💻

Bhanu Ailani

📖 💻

Deepak Sharma

📖 💻

Ramanpreet Singh

📖 💻

Anil Khatri

📖 💻

Ashwek Swamy

📖 💻

Dhruv Gupta

💻

Aadit Kamat

📖 💻

Shashank jain

📖 💻

Moulik Aggarwal

💬 📝 💻 📖

Prateek Surana

📖 💻

shivank86

💻

Vishal Shirke

📖 💻

profgrammer

📖 💻

divyakhetan

📖 💻

Spreeha Dutta

💻 📖

Chaitanya Bhojwani

📖 💻

Manaswini Das

📖

Anirudh Jwala

📖 💻

Willian Taiguara Baliza Moura

📖 💻

Rajashree Parhi

📖 💻

Akshit Aggarwal

📖 💻

Abhishek

💻

SAGUN JAISWAL

💻

Abhishek Anantharam

📖 💻

Prabhat Malhotra

📖 💻

Hrishikesh K Thakkar

💻

GAURAV KUMAR

📖 💻

wboccard

📖 💻

d-l-mcbride

📖 💻
+ + + + This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind are welcome! diff --git a/Day1/Kotlin/FizzBuzz.kts b/Day1/Kotlin/FizzBuzz.kts new file mode 100644 index 00000000..9d534b99 --- /dev/null +++ b/Day1/Kotlin/FizzBuzz.kts @@ -0,0 +1,21 @@ +/** + * @author: d-l-mcbride + * @date: 10/11/2020 + **/ + +fun fizzBuzz (fizzList: List) { + + var output: String + + fizzList.forEach { + output = when { + it % 15 == 0 -> "FizzBuzz" + it % 5 == 0 -> "Buzz" + it % 3 == 0 -> "Fizz" + else -> "${it}" + } + println(output) + } +} + +fizzBuzz((1..15).toList()) diff --git a/Day1/README.md b/Day1/README.md index 7ebb734b..7ddf0e28 100644 --- a/Day1/README.md +++ b/Day1/README.md @@ -595,6 +595,36 @@ int main() } ``` +## Kotlin Implementation + +### [FizzBuzz.kts](./Kotlin/FizzBuzz.kts) + +##### To run this script `kotlinc -script FizzBuzz.kts` + _*Prereq: Kotlin must be installed._ +``` +/** + * @author: d-l-mcbride + * @date: 10/11/2020 + **/ + +fun fizzBuzz (fizzList: List) { + + var output: String + + fizzList.forEach { + output = when { + it % 15 == 0 -> "FizzBuzz" + it % 5 == 0 -> "Buzz" + it % 3 == 0 -> "Fizz" + else -> "${it}" + } + println(output) + } +} + +fizzBuzz((1..15).toList()) +``` + ### Have Another solution? The beauty of programming lies in the fact that there is never a single solution to any problem. From 5626a6b34f6dbb29b8aa276df1dae2538c58cd99 Mon Sep 17 00:00:00 2001 From: d-l-mcbride Date: Sun, 11 Oct 2020 22:15:56 -0700 Subject: [PATCH 06/15] Add Kotlin solution for string reversal and palindrome validation. --- Day2/Kotlin/ReverseAndPalinedrome.kts | 34 +++++++++++++++++++++ Day2/README.md | 43 +++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 Day2/Kotlin/ReverseAndPalinedrome.kts diff --git a/Day2/Kotlin/ReverseAndPalinedrome.kts b/Day2/Kotlin/ReverseAndPalinedrome.kts new file mode 100644 index 00000000..cc542d6c --- /dev/null +++ b/Day2/Kotlin/ReverseAndPalinedrome.kts @@ -0,0 +1,34 @@ +/** + * @author: d-l-mcbride + * @date: 10/11/2020 + **/ + +fun reverse(subject:String):String { + var reversed = StringBuilder() + + for( j in (subject.length -1) downTo 0){ + reversed.append(subject[j]) + } + return reversed.toString() +} + + +fun palindrome(subject:String){ + val reversed = reverse(subject) + if (reversed == subject) println("${subject} is a palindrome") else println("${subject} is not a palindrome") +} + +val hello = "Hello" +val goodbye = "Goodbye" +val single = "S" + +println("Reverse String Tests") +println("${hello} reversed is ${reverse(hello)}") +println("${goodbye} reversed is ${reverse(goodbye)}") +println ("${single} reversed is ${reverse(single)}") + +println("\n\nPalindrome Tests") +palindrome("I") +palindrome("otto") +palindrome("tacocat") +palindrome("dog") diff --git a/Day2/README.md b/Day2/README.md index c0743faf..7834d9f4 100644 --- a/Day2/README.md +++ b/Day2/README.md @@ -981,6 +981,49 @@ public class StringReverseAndPalin { } ``` +## Kotlin Implementation + +### [FizzBuzz.kts](./Kotlin/ReverseAndPalindrome.kts) + +##### To run this script `kotlinc -script ReverseAndPalindrome.kts` + _*Prereq: Kotlin must be installed._ +``` +/** + * @author: d-l-mcbride + * @date: 10/11/2020 + **/ + +fun reverse(subject:String):String { + var reversed = StringBuilder() + + for( j in (subject.length -1) downTo 0){ + reversed.append(subject[j]) + } + return reversed.toString() +} + + +fun palindrome(subject:String){ + val reversed = reverse(subject) + if (reversed == subject) println("${subject} is a palindrome") else println("${subject} is not a palindrome") +} + +val hello = "Hello" +val goodbye = "Goodbye" +val single = "S" + +println("Reverse String Tests") +println("${hello} reversed is ${reverse(hello)}") +println("${goodbye} reversed is ${reverse(goodbye)}") +println ("${single} reversed is ${reverse(single)}") + +println("\n\nPalindrome Tests") +palindrome("I") +palindrome("otto") +palindrome("tacocat") +palindrome("dog") +``` + ### Have Another solution? The beauty of programming lies in the fact that there is never a single solution to any problem. From 816033cd700c35117411827d106c98c6369b222e Mon Sep 17 00:00:00 2001 From: d-l-mcbride Date: Mon, 12 Oct 2020 06:45:02 -0700 Subject: [PATCH 07/15] Add Kotlin solution for Day3 and fix Typo in Day2 README.md --- Day2/README.md | 2 +- Day3/Kotlin/HammingDistance.kts | 27 +++++++++++++++++++++++ Day3/README.md | 39 +++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 Day3/Kotlin/HammingDistance.kts diff --git a/Day2/README.md b/Day2/README.md index 7834d9f4..e065cd0f 100644 --- a/Day2/README.md +++ b/Day2/README.md @@ -983,7 +983,7 @@ public class StringReverseAndPalin { ## Kotlin Implementation -### [FizzBuzz.kts](./Kotlin/ReverseAndPalindrome.kts) +### [ReverseAndPalindrome.kts](./Kotlin/ReverseAndPalindrome.kts) ##### To run this script `kotlinc -script ReverseAndPalindrome.kts` _*Prereq: Kotlin must be installed._ diff --git a/Day3/Kotlin/HammingDistance.kts b/Day3/Kotlin/HammingDistance.kts new file mode 100644 index 00000000..122aa459 --- /dev/null +++ b/Day3/Kotlin/HammingDistance.kts @@ -0,0 +1,27 @@ +/** + * @author: d-l-mcbride + * @date: 10/12/2020 + **/ + +fun hammingDistance(first: String, second: String ):Int { + var distance = 0 + for(i in first.indices) { + if (first[i] != second[i]) distance++ + } + return distance +} + +val DOG = "dog" +val LOG = "log" +val LARRY = "larry" +val LASSI ="lassi" +val EMPTY = "" +val ALSO_EMPTY = "" +val ABCDE = "abcde" +val BADEC = "badec" + +println("Hamming Distance of ${DOG} and ${LOG} = ${hammingDistance(DOG,LOG)}") +println("Hamming Distance of ${LOG} and ${LOG} = ${hammingDistance(LOG,LOG)}") +println("Hamming Distance of ${LARRY} and ${LASSI} = ${hammingDistance(LARRY,LASSI)}") +println("Hamming Distance of ${ABCDE} and ${BADEC} = ${hammingDistance(ABCDE,BADEC)}") +println("Hamming Distance of two empty strings = ${hammingDistance(EMPTY,ALSO_EMPTY)}") diff --git a/Day3/README.md b/Day3/README.md index dfcc3a21..2a81cde2 100644 --- a/Day3/README.md +++ b/Day3/README.md @@ -402,6 +402,8 @@ print("list of unmatched characters are:",k) print("number of characters not matching are:",len(k)) ``` + +``` /* @date 4/09/2020 * @author Shashwat Gupta (shashwatxdevelop) */ @@ -434,7 +436,44 @@ public class HammingDistance { } } +``` +## Kotlin Implementation + +### [HammingDistance.kts](./Kotlin/HammingDistance.kts) + +##### To run this script `kotlinc -script HammingDistance.kts` + _*Prereq: Kotlin must be installed._ + +``` +/** + * @author: d-l-mcbride + * @date: 10/12/2020 + **/ + +fun hammingDistance(first: String, second: String ):Int { + var distance = 0 + for(i in first.indices) { + if (first[i] != second[i]) distance++ + } + return distance +} + +val DOG = "dog" +val LOG = "log" +val LARRY = "larry" +val LASSI ="lassi" +val EMPTY = "" +val ALSO_EMPTY = "" +val ABCDE = "abcde" +val BADEC = "badec" + +println("Hamming Distance of ${DOG} and ${LOG} = ${hammingDistance(DOG,LOG)}") +println("Hamming Distance of ${LOG} and ${LOG} = ${hammingDistance(LOG,LOG)}") +println("Hamming Distance of ${LARRY} and ${LASSI} = ${hammingDistance(LARRY,LASSI)}") +println("Hamming Distance of ${ABCDE} and ${BADEC} = ${hammingDistance(ABCDE,BADEC)}") +println("Hamming Distance of two empty strings = ${hammingDistance(EMPTY,ALSO_EMPTY)}") +``` ## Why Hamming Distance? From 946689a8a78145bf6903950a05509d3abe380c95 Mon Sep 17 00:00:00 2001 From: d-l-mcbride Date: Mon, 12 Oct 2020 18:27:33 -0700 Subject: [PATCH 08/15] Add Kotlin solution for day4. --- day4/Kotlin/NumVowelsAndMaxChars.kts | 50 +++++++++++++++++++++++ day4/README.md | 61 +++++++++++++++++++++++++++- 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 day4/Kotlin/NumVowelsAndMaxChars.kts diff --git a/day4/Kotlin/NumVowelsAndMaxChars.kts b/day4/Kotlin/NumVowelsAndMaxChars.kts new file mode 100644 index 00000000..58e4d08b --- /dev/null +++ b/day4/Kotlin/NumVowelsAndMaxChars.kts @@ -0,0 +1,50 @@ +/** + * @author: d-l-mcbride + * @date: 10/11/2020 + **/ + +fun numberOfVowels(subject: String):Int{ + val vowels = hashSetOf('a','e','i','o','u') + var count = 0 + subject.forEach { + when(it.toLowerCase()) { + in vowels -> count++ + } + } + return count +} + +fun maxChars(subject: String):Char { + var maxChar = subject[0] + var maxCount = 0 + var count:Int + for(i in 0 until subject.length -1) { + count = 0 + for(j in i+1 until subject.length) { + if (subject[i] == subject[j]) count++ + } + if( count > maxCount) { + maxCount = count + maxChar = subject[i] + } + } + return maxChar +} + + + +val TWO_VOWELS = "hello" +val TWO_VOWELS_WITH_CAPS = "HELLO" +val NO_VOWELS = "qrzmtlnz" +println("${TWO_VOWELS} contains ${numberOfVowels(TWO_VOWELS)} vowels.") +println("${TWO_VOWELS_WITH_CAPS} contains ${numberOfVowels(TWO_VOWELS_WITH_CAPS)} vowels.") +println("${NO_VOWELS} contains ${numberOfVowels(NO_VOWELS)} vowels.") + +val THREE_MID = "helllo" +val ONE_EACH = "abcd" +val FOUR_END = "byeeee" +val FOUR_BEG = "yyyyes" +println("The letter with the most occurences in ${THREE_MID} is ${maxChars(THREE_MID)}") +println("The letter with the most occurences in ${ONE_EACH} is ${maxChars(ONE_EACH)}") +println("The letter with the most occurences in ${FOUR_END} is ${maxChars(FOUR_END)}") +println("The letter with the most occurences in ${FOUR_BEG} is ${maxChars(FOUR_BEG)}") diff --git a/day4/README.md b/day4/README.md index e9c5f930..dd577e03 100644 --- a/day4/README.md +++ b/day4/README.md @@ -887,10 +887,69 @@ print "Enter a string: " str = gets str.chomp! puts "The most frequent character in #{str} is : #{most_frequent_character(str)}" +``` +## Kotlin Implementation + +### [NumVowelsAndMaxChars.kts](./Kotlin/NumVowelsAndMaxChars.kts) + +##### To run this script `kotlinc -script NumVowelsAndMaxChars.kts` + +``` +/** + * @author: d-l-mcbride + * @date: 10/11/2020 + **/ + +fun numberOfVowels(subject: String):Int{ + val vowels = hashSetOf('a','e','i','o','u') + var count = 0 + subject.forEach { + when(it.toLowerCase()) { + in vowels -> count++ + } + } + return count +} + +fun maxChars(subject: String):Char { + var maxChar = subject[0] + var maxCount = 0 + var count:Int + for(i in 0 until subject.length -1) { + count = 0 + for(j in i+1 until subject.length) { + if (subject[i] == subject[j]) count++ + } + if( count > maxCount) { + maxCount = count + maxChar = subject[i] + } + } + return maxChar +} + + + +val TWO_VOWELS = "hello" +val TWO_VOWELS_WITH_CAPS = "HELLO" +val NO_VOWELS = "qrzmtlnz" +println("${TWO_VOWELS} contains ${numberOfVowels(TWO_VOWELS)} vowels.") +println("${TWO_VOWELS_WITH_CAPS} contains ${numberOfVowels(TWO_VOWELS_WITH_CAPS)} vowels.") +println("${NO_VOWELS} contains ${numberOfVowels(NO_VOWELS)} vowels.") + +val THREE_MID = "helllo" +val ONE_EACH = "abcd" +val FOUR_END = "byeeee" +val FOUR_BEG = "yyyyes" +println("The letter with the most occurences in ${THREE_MID} is ${maxChars(THREE_MID)}") +println("The letter with the most occurences in ${ONE_EACH} is ${maxChars(ONE_EACH)}") +println("The letter with the most occurences in ${FOUR_END} is ${maxChars(FOUR_END)}") +println("The letter with the most occurences in ${FOUR_BEG} is ${maxChars(FOUR_BEG)}") + ``` ### Have Another solution? The beauty of programming lies in the fact that there is never a single solution to any problem. -In case you have an alternative way to solve this problem, do contribute to this repository (https://github.com/CodeToExpress/dailycodebase) :) \ No newline at end of file +In case you have an alternative way to solve this problem, do contribute to this repository (https://github.com/CodeToExpress/dailycodebase) :) From 37cbb90faf0ec405dff5f61a99522ed784816bde Mon Sep 17 00:00:00 2001 From: d-l-mcbride Date: Sun, 11 Oct 2020 22:15:56 -0700 Subject: [PATCH 09/15] Add Kotlin solution for string reversal and palindrome validation. --- Day2/Kotlin/ReverseAndPalinedrome.kts | 34 +++++++++++++++++++++ Day2/README.md | 43 +++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 Day2/Kotlin/ReverseAndPalinedrome.kts diff --git a/Day2/Kotlin/ReverseAndPalinedrome.kts b/Day2/Kotlin/ReverseAndPalinedrome.kts new file mode 100644 index 00000000..cc542d6c --- /dev/null +++ b/Day2/Kotlin/ReverseAndPalinedrome.kts @@ -0,0 +1,34 @@ +/** + * @author: d-l-mcbride + * @date: 10/11/2020 + **/ + +fun reverse(subject:String):String { + var reversed = StringBuilder() + + for( j in (subject.length -1) downTo 0){ + reversed.append(subject[j]) + } + return reversed.toString() +} + + +fun palindrome(subject:String){ + val reversed = reverse(subject) + if (reversed == subject) println("${subject} is a palindrome") else println("${subject} is not a palindrome") +} + +val hello = "Hello" +val goodbye = "Goodbye" +val single = "S" + +println("Reverse String Tests") +println("${hello} reversed is ${reverse(hello)}") +println("${goodbye} reversed is ${reverse(goodbye)}") +println ("${single} reversed is ${reverse(single)}") + +println("\n\nPalindrome Tests") +palindrome("I") +palindrome("otto") +palindrome("tacocat") +palindrome("dog") diff --git a/Day2/README.md b/Day2/README.md index c0743faf..7834d9f4 100644 --- a/Day2/README.md +++ b/Day2/README.md @@ -981,6 +981,49 @@ public class StringReverseAndPalin { } ``` +## Kotlin Implementation + +### [FizzBuzz.kts](./Kotlin/ReverseAndPalindrome.kts) + +##### To run this script `kotlinc -script ReverseAndPalindrome.kts` + _*Prereq: Kotlin must be installed._ +``` +/** + * @author: d-l-mcbride + * @date: 10/11/2020 + **/ + +fun reverse(subject:String):String { + var reversed = StringBuilder() + + for( j in (subject.length -1) downTo 0){ + reversed.append(subject[j]) + } + return reversed.toString() +} + + +fun palindrome(subject:String){ + val reversed = reverse(subject) + if (reversed == subject) println("${subject} is a palindrome") else println("${subject} is not a palindrome") +} + +val hello = "Hello" +val goodbye = "Goodbye" +val single = "S" + +println("Reverse String Tests") +println("${hello} reversed is ${reverse(hello)}") +println("${goodbye} reversed is ${reverse(goodbye)}") +println ("${single} reversed is ${reverse(single)}") + +println("\n\nPalindrome Tests") +palindrome("I") +palindrome("otto") +palindrome("tacocat") +palindrome("dog") +``` + ### Have Another solution? The beauty of programming lies in the fact that there is never a single solution to any problem. From c157ecb25db253aa898dc9f6758556a6720a90b2 Mon Sep 17 00:00:00 2001 From: d-l-mcbride Date: Mon, 12 Oct 2020 06:45:02 -0700 Subject: [PATCH 10/15] Add Kotlin solution for Day3 and fix Typo in Day2 README.md --- Day2/README.md | 2 +- Day3/Kotlin/HammingDistance.kts | 27 +++++++++++++++++++++++ Day3/README.md | 39 +++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 Day3/Kotlin/HammingDistance.kts diff --git a/Day2/README.md b/Day2/README.md index 7834d9f4..e065cd0f 100644 --- a/Day2/README.md +++ b/Day2/README.md @@ -983,7 +983,7 @@ public class StringReverseAndPalin { ## Kotlin Implementation -### [FizzBuzz.kts](./Kotlin/ReverseAndPalindrome.kts) +### [ReverseAndPalindrome.kts](./Kotlin/ReverseAndPalindrome.kts) ##### To run this script `kotlinc -script ReverseAndPalindrome.kts` _*Prereq: Kotlin must be installed._ diff --git a/Day3/Kotlin/HammingDistance.kts b/Day3/Kotlin/HammingDistance.kts new file mode 100644 index 00000000..122aa459 --- /dev/null +++ b/Day3/Kotlin/HammingDistance.kts @@ -0,0 +1,27 @@ +/** + * @author: d-l-mcbride + * @date: 10/12/2020 + **/ + +fun hammingDistance(first: String, second: String ):Int { + var distance = 0 + for(i in first.indices) { + if (first[i] != second[i]) distance++ + } + return distance +} + +val DOG = "dog" +val LOG = "log" +val LARRY = "larry" +val LASSI ="lassi" +val EMPTY = "" +val ALSO_EMPTY = "" +val ABCDE = "abcde" +val BADEC = "badec" + +println("Hamming Distance of ${DOG} and ${LOG} = ${hammingDistance(DOG,LOG)}") +println("Hamming Distance of ${LOG} and ${LOG} = ${hammingDistance(LOG,LOG)}") +println("Hamming Distance of ${LARRY} and ${LASSI} = ${hammingDistance(LARRY,LASSI)}") +println("Hamming Distance of ${ABCDE} and ${BADEC} = ${hammingDistance(ABCDE,BADEC)}") +println("Hamming Distance of two empty strings = ${hammingDistance(EMPTY,ALSO_EMPTY)}") diff --git a/Day3/README.md b/Day3/README.md index dfcc3a21..2a81cde2 100644 --- a/Day3/README.md +++ b/Day3/README.md @@ -402,6 +402,8 @@ print("list of unmatched characters are:",k) print("number of characters not matching are:",len(k)) ``` + +``` /* @date 4/09/2020 * @author Shashwat Gupta (shashwatxdevelop) */ @@ -434,7 +436,44 @@ public class HammingDistance { } } +``` +## Kotlin Implementation + +### [HammingDistance.kts](./Kotlin/HammingDistance.kts) + +##### To run this script `kotlinc -script HammingDistance.kts` + _*Prereq: Kotlin must be installed._ + +``` +/** + * @author: d-l-mcbride + * @date: 10/12/2020 + **/ + +fun hammingDistance(first: String, second: String ):Int { + var distance = 0 + for(i in first.indices) { + if (first[i] != second[i]) distance++ + } + return distance +} + +val DOG = "dog" +val LOG = "log" +val LARRY = "larry" +val LASSI ="lassi" +val EMPTY = "" +val ALSO_EMPTY = "" +val ABCDE = "abcde" +val BADEC = "badec" + +println("Hamming Distance of ${DOG} and ${LOG} = ${hammingDistance(DOG,LOG)}") +println("Hamming Distance of ${LOG} and ${LOG} = ${hammingDistance(LOG,LOG)}") +println("Hamming Distance of ${LARRY} and ${LASSI} = ${hammingDistance(LARRY,LASSI)}") +println("Hamming Distance of ${ABCDE} and ${BADEC} = ${hammingDistance(ABCDE,BADEC)}") +println("Hamming Distance of two empty strings = ${hammingDistance(EMPTY,ALSO_EMPTY)}") +``` ## Why Hamming Distance? From acafbd646cdb1f5fde25a4c4f58a3c8fb4df78d4 Mon Sep 17 00:00:00 2001 From: d-l-mcbride Date: Mon, 12 Oct 2020 18:27:33 -0700 Subject: [PATCH 11/15] Add Kotlin solution for day4. --- day4/Kotlin/NumVowelsAndMaxChars.kts | 50 +++++++++++++++++++++++ day4/README.md | 61 +++++++++++++++++++++++++++- 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 day4/Kotlin/NumVowelsAndMaxChars.kts diff --git a/day4/Kotlin/NumVowelsAndMaxChars.kts b/day4/Kotlin/NumVowelsAndMaxChars.kts new file mode 100644 index 00000000..58e4d08b --- /dev/null +++ b/day4/Kotlin/NumVowelsAndMaxChars.kts @@ -0,0 +1,50 @@ +/** + * @author: d-l-mcbride + * @date: 10/11/2020 + **/ + +fun numberOfVowels(subject: String):Int{ + val vowels = hashSetOf('a','e','i','o','u') + var count = 0 + subject.forEach { + when(it.toLowerCase()) { + in vowels -> count++ + } + } + return count +} + +fun maxChars(subject: String):Char { + var maxChar = subject[0] + var maxCount = 0 + var count:Int + for(i in 0 until subject.length -1) { + count = 0 + for(j in i+1 until subject.length) { + if (subject[i] == subject[j]) count++ + } + if( count > maxCount) { + maxCount = count + maxChar = subject[i] + } + } + return maxChar +} + + + +val TWO_VOWELS = "hello" +val TWO_VOWELS_WITH_CAPS = "HELLO" +val NO_VOWELS = "qrzmtlnz" +println("${TWO_VOWELS} contains ${numberOfVowels(TWO_VOWELS)} vowels.") +println("${TWO_VOWELS_WITH_CAPS} contains ${numberOfVowels(TWO_VOWELS_WITH_CAPS)} vowels.") +println("${NO_VOWELS} contains ${numberOfVowels(NO_VOWELS)} vowels.") + +val THREE_MID = "helllo" +val ONE_EACH = "abcd" +val FOUR_END = "byeeee" +val FOUR_BEG = "yyyyes" +println("The letter with the most occurences in ${THREE_MID} is ${maxChars(THREE_MID)}") +println("The letter with the most occurences in ${ONE_EACH} is ${maxChars(ONE_EACH)}") +println("The letter with the most occurences in ${FOUR_END} is ${maxChars(FOUR_END)}") +println("The letter with the most occurences in ${FOUR_BEG} is ${maxChars(FOUR_BEG)}") diff --git a/day4/README.md b/day4/README.md index e9c5f930..dd577e03 100644 --- a/day4/README.md +++ b/day4/README.md @@ -887,10 +887,69 @@ print "Enter a string: " str = gets str.chomp! puts "The most frequent character in #{str} is : #{most_frequent_character(str)}" +``` +## Kotlin Implementation + +### [NumVowelsAndMaxChars.kts](./Kotlin/NumVowelsAndMaxChars.kts) + +##### To run this script `kotlinc -script NumVowelsAndMaxChars.kts` + +``` +/** + * @author: d-l-mcbride + * @date: 10/11/2020 + **/ + +fun numberOfVowels(subject: String):Int{ + val vowels = hashSetOf('a','e','i','o','u') + var count = 0 + subject.forEach { + when(it.toLowerCase()) { + in vowels -> count++ + } + } + return count +} + +fun maxChars(subject: String):Char { + var maxChar = subject[0] + var maxCount = 0 + var count:Int + for(i in 0 until subject.length -1) { + count = 0 + for(j in i+1 until subject.length) { + if (subject[i] == subject[j]) count++ + } + if( count > maxCount) { + maxCount = count + maxChar = subject[i] + } + } + return maxChar +} + + + +val TWO_VOWELS = "hello" +val TWO_VOWELS_WITH_CAPS = "HELLO" +val NO_VOWELS = "qrzmtlnz" +println("${TWO_VOWELS} contains ${numberOfVowels(TWO_VOWELS)} vowels.") +println("${TWO_VOWELS_WITH_CAPS} contains ${numberOfVowels(TWO_VOWELS_WITH_CAPS)} vowels.") +println("${NO_VOWELS} contains ${numberOfVowels(NO_VOWELS)} vowels.") + +val THREE_MID = "helllo" +val ONE_EACH = "abcd" +val FOUR_END = "byeeee" +val FOUR_BEG = "yyyyes" +println("The letter with the most occurences in ${THREE_MID} is ${maxChars(THREE_MID)}") +println("The letter with the most occurences in ${ONE_EACH} is ${maxChars(ONE_EACH)}") +println("The letter with the most occurences in ${FOUR_END} is ${maxChars(FOUR_END)}") +println("The letter with the most occurences in ${FOUR_BEG} is ${maxChars(FOUR_BEG)}") + ``` ### Have Another solution? The beauty of programming lies in the fact that there is never a single solution to any problem. -In case you have an alternative way to solve this problem, do contribute to this repository (https://github.com/CodeToExpress/dailycodebase) :) \ No newline at end of file +In case you have an alternative way to solve this problem, do contribute to this repository (https://github.com/CodeToExpress/dailycodebase) :) From 4857b802c36d3e06cb56185370de4e1316667181 Mon Sep 17 00:00:00 2001 From: d-l-mcbride Date: Sun, 11 Oct 2020 22:15:56 -0700 Subject: [PATCH 12/15] Add Kotlin solution for string reversal and palindrome validation. --- Day2/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/Day2/README.md b/Day2/README.md index e065cd0f..83017d80 100644 --- a/Day2/README.md +++ b/Day2/README.md @@ -982,9 +982,7 @@ public class StringReverseAndPalin { ``` ## Kotlin Implementation - ### [ReverseAndPalindrome.kts](./Kotlin/ReverseAndPalindrome.kts) - ##### To run this script `kotlinc -script ReverseAndPalindrome.kts` _*Prereq: Kotlin must be installed._ ``` From fa75ee170d69991dc5aeded076f4bceef3c1d6b5 Mon Sep 17 00:00:00 2001 From: d-l-mcbride Date: Mon, 12 Oct 2020 06:45:02 -0700 Subject: [PATCH 13/15] Add Kotlin solution for Day3 and fix Typo in Day2 README.md --- Day2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Day2/README.md b/Day2/README.md index 83017d80..f3bfc44e 100644 --- a/Day2/README.md +++ b/Day2/README.md @@ -983,6 +983,7 @@ public class StringReverseAndPalin { ## Kotlin Implementation ### [ReverseAndPalindrome.kts](./Kotlin/ReverseAndPalindrome.kts) + ##### To run this script `kotlinc -script ReverseAndPalindrome.kts` _*Prereq: Kotlin must be installed._ ``` From 79ab4f4193fe7bb00c0afac69198d57848f6f916 Mon Sep 17 00:00:00 2001 From: d-l-mcbride Date: Thu, 15 Oct 2020 07:10:06 -0700 Subject: [PATCH 14/15] Add check for different length strings --- Day3/Kotlin/HammingDistance.kts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Day3/Kotlin/HammingDistance.kts b/Day3/Kotlin/HammingDistance.kts index 122aa459..e3051432 100644 --- a/Day3/Kotlin/HammingDistance.kts +++ b/Day3/Kotlin/HammingDistance.kts @@ -4,6 +4,8 @@ **/ fun hammingDistance(first: String, second: String ):Int { + if (first.length != second.length) return -1 + var distance = 0 for(i in first.indices) { if (first[i] != second[i]) distance++ @@ -19,9 +21,12 @@ val EMPTY = "" val ALSO_EMPTY = "" val ABCDE = "abcde" val BADEC = "badec" +val DIFF_ONE ="ab" +val DIFF_TWO ="abcd" println("Hamming Distance of ${DOG} and ${LOG} = ${hammingDistance(DOG,LOG)}") println("Hamming Distance of ${LOG} and ${LOG} = ${hammingDistance(LOG,LOG)}") println("Hamming Distance of ${LARRY} and ${LASSI} = ${hammingDistance(LARRY,LASSI)}") println("Hamming Distance of ${ABCDE} and ${BADEC} = ${hammingDistance(ABCDE,BADEC)}") println("Hamming Distance of two empty strings = ${hammingDistance(EMPTY,ALSO_EMPTY)}") +println("Hamming Distance of different length strings = ${hammingDistance(DIFF_ONE,DIFF_TWO)}") From 5495a78d0c6bc664fbbbe921d321ae962898eb48 Mon Sep 17 00:00:00 2001 From: d-l-mcbride Date: Thu, 15 Oct 2020 07:17:33 -0700 Subject: [PATCH 15/15] Update README.md to reflect updated Kotlin solution --- Day3/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Day3/README.md b/Day3/README.md index 2a81cde2..3ec670db 100644 --- a/Day3/README.md +++ b/Day3/README.md @@ -452,6 +452,8 @@ public class HammingDistance { **/ fun hammingDistance(first: String, second: String ):Int { + if (first.length != second.length) return -1 + var distance = 0 for(i in first.indices) { if (first[i] != second[i]) distance++ @@ -467,12 +469,15 @@ val EMPTY = "" val ALSO_EMPTY = "" val ABCDE = "abcde" val BADEC = "badec" +val DIFF_ONE ="ab" +val DIFF_TWO ="abcd" println("Hamming Distance of ${DOG} and ${LOG} = ${hammingDistance(DOG,LOG)}") println("Hamming Distance of ${LOG} and ${LOG} = ${hammingDistance(LOG,LOG)}") println("Hamming Distance of ${LARRY} and ${LASSI} = ${hammingDistance(LARRY,LASSI)}") println("Hamming Distance of ${ABCDE} and ${BADEC} = ${hammingDistance(ABCDE,BADEC)}") println("Hamming Distance of two empty strings = ${hammingDistance(EMPTY,ALSO_EMPTY)}") +println("Hamming Distance of different length strings = ${hammingDistance(DIFF_ONE,DIFF_TWO)}") ``` ## Why Hamming Distance?