Skip to content

Instantly share code, notes, and snippets.

@ChrisGuzman
ChrisGuzman / groupanagrams.kt
Created April 6, 2020 16:41
LeetCode 6 Group Anagrams
fun main(args: Array<String>) {
groupAnagrams(arrayOf("eat", "tea", "tan", "ate", "nat", "bat"))
}
fun groupAnagrams(strs: Array<String>): List<List<String>> {
//Loop through array
val myMap = mutableMapOf<String, MutableList<String>>()
strs.forEach {
//take word and put in alphabetical order
val alphaOrdered = it.toCharArray().sorted().joinToString("")
//use alphabetized string as hash key
@ChrisGuzman
ChrisGuzman / movezeroes.kt
Last active April 4, 2020 22:49
4 move zeroes
fun main(args: Array<String>) {
val nums = intArrayOf(0,1,0,3,12)
moveZeroes(nums)
nums.map {
print("$it, ")
}
}
fun moveZeroes(nums: IntArray): Unit {
val zeroesCount = nums.count { it == 0 }
@ChrisGuzman
ChrisGuzman / maximum_subarray.kt
Created April 3, 2020 21:27
LeetCode #3 Maximum Subarray
fun main(args: Array<String>) {
maxSubArray(intArrayOf(-2,1,-3,4,-1,2,1,-5,4))
}
fun maxSubArray(nums: IntArray): Int {
val maxSums = mutableListOf<Int>()
nums.toList()
var i = 0
while (i < nums.size) {
val subList = nums.toList().subList(i, nums.size)
@ChrisGuzman
ChrisGuzman / happyNumber.kt
Created April 2, 2020 21:59
LeetCode #2 Happy Number
fun main(args: Array<String>) {
println(isHappy(1111111))
}
fun isHappy(n: Int): Boolean {
val mathed = doTheMath(n)
println(mathed)
return mathed == 1
}
@ChrisGuzman
ChrisGuzman / shakespeare.json
Created July 24, 2018 22:18
Shakespeare speaking
[
{
"action": "talk",
"voiceName": "Russell",
"text": "You have done that you should be sorry for. There is no terror, Cassius, in your threats, For I am arm'd so strong in honesty That they pass by me as the idle wind, Which I respect not. I did send to you For certain sums of gold, which you denied me: For I can raise no money by vile means: By heaven, I had rather coin my heart, And drop my blood for drachmas, than to wring From the hard hands of peasants their vile trash By any indirection: I did send To you for gold to pay my legions, Which you denied me: was that done like Cassius? Should I have answer'd Caius Cassius so? When Marcus Brutus grows so covetous, To lock such rascal counters from his friends, Be ready, gods, with all your thunderbolts; Dash him to pieces!"
}
]
[
{
"action": "talk",
"text": "Thank you for calling Chris"
},
{
"action": "connect",
"from": "19177176397",
"endpoint": [
{
@ChrisGuzman
ChrisGuzman / install.sh
Created May 7, 2018 14:59
Ruby Nexmo Client pre-reqs
gem install nexmo
@ChrisGuzman
ChrisGuzman / install.sh
Last active July 25, 2018 16:48
ruby webhook pre-requisites
gem install sinatra
gem install sinatra-contrib
conversation.on("member:media", (member, event) => {
console.log(`*** Member changed media state`, member, event)
})
conversation.sendText("Hello World!")
.then(() => console.log('text sent'))