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
#Given an array of integers, find the maximum range between two elements in the array. | |
def maxRange(arr) | |
return arr.max.abs - arr.min.abs | |
end | |
puts maxRange([2,2,1,3]) #2 | |
puts maxRange([0]) #0 | |
puts maxRange([4,3,5,7,1,7,7,6]) #6 |
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
=begin | |
Integer dvision for a / b | |
@param a first number | |
@param b second number | |
@return a / b | |
=end | |
def divide(a, b) | |
sign = (a < 0) ^ (b < 0) ? -1 : 1 | |
a = a.abs | |
b = b.abs |
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
import java.util.HashMap; | |
/** | |
* Created by kylel95 on 5/21/19. | |
* Find the last non-repeating character in a given string. | |
*/ | |
public class lastUnique { | |
public static void main(String [] args){ | |
String s = "candy canes do taste yummy"; |
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
#Given an integer N, find the number of trailing zeroes | |
# in the base 16 representation of the factorial of N. | |
def trailing(number) | |
num = factorial(number).to_s(16) | |
length = num.length | |
chars = num.split('') | |
count = 0 | |
for c in num.split('').reverse() | |
if(c == '0') | |
count += 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
let nums = [] | |
function squareCubeNums(num){ | |
for(var i = 1; i <= num; i++){nums[i] = i;} | |
//Check for perfect square && check for perfect cube | |
nums = nums.filter(number => Math.floor(Math.sqrt(number)) - Math.sqrt(number) == 0 && Math.pow(Math.round(Math.pow(number, 1/3)), 3) == number); | |
console.log(nums); | |
} | |
squareCubeNums(64); |
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
import java.util.*; | |
/** | |
* Created by kylel95 on 3/1/19. | |
*/ | |
public class phonePad { | |
public static void main(String [] args){ | |
String s = "123456"; | |
perm1(makeString(s)); | |
} |
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
/** | |
* Created by Kyle Long on 2/24/19. | |
*/ | |
public class removeOdd { | |
public static void main(String [] args){ | |
System.out.println(removeForOdd(new int[]{2,4,6,7,8})); | |
System.out.println(removeForOdd(new int[]{4,4,4})); | |
System.out.println(removeForOdd(new int[]{1,2,3,4,5,6,7})); | |
} |
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
/** | |
* Created by Kyle Long on 2/12/19. | |
*/ | |
public class charsToPalindrome { | |
public static void main(String [] args){ | |
String s = "hi"; //hi -> hih or ihi | |
String s1 = "xx"; //already palindrome | |
String s2 = "race"; //racecar | |
String s3 = "abcdabc"; //not possible to convert into a palindrome | |
System.out.println(makeAPal(s)); |
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
Functional Programming | |
---------------------- | |
Throughout our daily or weekly lives, we often do several tasks repeatedly. For example, brushing your teeth, | |
introducing yourself to a stranger, making your bed, etc. It would be very convenient if we could snap our fingers | |
and say, "Make my bed" after every night’s rest. Unfortunately, this is not (yet) the case. Well, in programming, there are | |
task that programmers know they will have to do over and over again. Maybe calculating the number of days until Christmas, checking if a number is prime, counting letters in a word, etc. It is often very useful to create functions or blocks of reusable code that a program can invoke to execute a this consistent task instead of writing out the code every single time. Instead of writing code and figuring out the logic everytime, functions can be created. For example, static int numOfLetters(String s) { return s.length();}, calculate how long the word (string) s is. Instead of having to rememver the syntax (s.length()), a p |
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
import java.util.regex.*; | |
/** | |
* Created by kylel95 on 1/22/19. | |
*/ | |
public class repeatedSubString { | |
public static void main(String [] args){ | |
System.out.println(repeat("pi", "pipipipi")); | |
System.out.println(repeat("danger", "cassidy")); |