Skip to content

Instantly share code, notes, and snippets.

View kylelong's full-sized avatar
🌴
On vacation

Kyle Long kylelong

🌴
On vacation
View GitHub Profile
@kylelong
kylelong / fiftysum.java
Created November 3, 2018 14:34
Given a set of numbers -50 to 50, find all pairs that add up to a given sum. Week of 10/28/2018 cassido newsletter interview problem
/**
Given a set of numbers -50 to 50, find all pairs that add up to a given sum.
* Created by kylel95 on 11/3/18.
*/
import java.util.*;
public class fiftysum {
public static void main(String [] args){
int [] arr = new int[101];
int index = 0;
for(int i = -50; i <= 50; i++){
@kylelong
kylelong / balancedNumber.java
Created November 23, 2018 03:10
Function to determine if the frequency of digits in a given number is balanced.
/**
* Created by kylel95 on 11/22/18.
*/
import java.util.*;
public class balancedNumber {
// Write a function to determine if the frequency of digits in a given number is balanced.
public static void main (String [] args){
System.out.println(freq(1337));
System.out.println(freq(3.1415926535));
System.out.println(freq(12345678));
@kylelong
kylelong / nonprimefactors.java
Last active December 13, 2018 06:14
Calculates the number of non-prime factors a number has.
/**
* Created by kylel95 on 12/13/18.
*/
import java.io.*;
import java.util.*;
/**
* Calculate number of non-prime factors of a number N
*/
public class nonprimefactors {
@kylelong
kylelong / day5.java
Created December 14, 2018 18:38
adventofcodeday5
/**
* Created by kylel95 on 12/5/18.
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class day5 {
public static void main(String [] args) {
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
@kylelong
kylelong / greaterPower.java
Last active December 24, 2018 07:13
Return string form of power function
/**
* Created by kylel95 on 12/24/18.
*/
public class greaterPower {
public static void main(String [] args){
int a = 3;
int b = 5;
int c = 2;
int d = 4;
System.out.println(greaterPow(a, b));
@kylelong
kylelong / pointers.txt
Created January 9, 2019 02:14
Questions about pointers from cassido's 1/7/19 newsletter
- What is the difference between passing by value and passing by reference?
By value: Passes the value of the memory address that the pointer points to.
By reference: Passes an alias to “reference” the variable passed in.
- How can pointers be used with inherited or abstract classes?
Using static methods.
- What does it mean for a pointer to be null?
The pointer does not point to any address in memory.
@kylelong
kylelong / oneFive.java
Last active January 14, 2019 08:32
Week 1/13/19 of cassido's newsletter interview question of the week.
import java.util.*;
/**
* Returns all numbers < n whose digits are 1 or 5.
* Created by Kyle Long on 1/14/19.
*/
public class oneFive {
public static void main(String [] args){
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
@kylelong
kylelong / repeatedSubString.java
Created January 22, 2019 19:55
Week 1/20/19 of Cassido's newsletter
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"));
@kylelong
kylelong / foop.txt
Last active February 10, 2019 00:03
Functional & Object Oriented Programming
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
@kylelong
kylelong / charsToPalindrome.java
Last active February 13, 2019 05:05
Cassido's weekly interview problem (2/10/19)
/**
* 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));