Skip to content

Instantly share code, notes, and snippets.

View sinanduman's full-sized avatar

Sinan Duman sinanduman

View GitHub Profile
@sinanduman
sinanduman / FindReverse.java
Last active December 13, 2015 17:18
The password is the longest substring that is the same in reverse. As an example, if the input was "I like racecars that go fast" the password would be "racecar".
public class FindReverse {
public static void main(String[] args) {
String longWord = "FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincr
@sinanduman
sinanduman / FindAnagram.java
Last active December 13, 2015 18:39
Code will find the anagrams in a given String array.
package teach;
import java.util.Arrays;
public class FindAnagram {
/**
* Develop code that would match words as anagram. If they are anagram
* your code will change last element of each index from null to "T", else "F".
* And print the results.
* E.g. Tea and Eat, ate are anagram words.
@sinanduman
sinanduman / ProjectEulerProblem4.java
Created March 5, 2013 10:58
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99. Find the largest palindrome made from the product of two 3-digit numbers.
package teach;
public class ProjectEulerProblem4 {
/**
* A palindromic number reads the same both ways. The largest palindrome made
* from the product of two 2-digit numbers is 9009 = 91 x 99.
* Find the largest palindrome made from the product of two 3-digit numbers.
*/
private static final int MAX = 999;
package teach;
public class FindBalance {
/**
* write a recursion function that will state a given string has balanced
* parenthesis.
*/
public static void main(String[] args) {
String[][] words = {
@sinanduman
sinanduman / MirrorsEnd.java
Created March 5, 2013 15:50
Given a string, look for a mirror image (backwards) string at both the beginning and end of the given string. In other words, zero or more characters at the very begining of the given string, and at the very end of the string in reverse order (possibly overlapping). For example, the string "abXYZba" has the mirror end "ab". mirrorEnds("abXYZba")…
package teach;
public class MirrorsEnd {
/**
* @param args
*/
public static void main(String[] args) {
String[] words = { "abXYZba", "abca", "aba", "Hi and iH", "123and then 321" };
@sinanduman
sinanduman / MiddleWordSwap.java
Created July 8, 2013 07:35
Change the middle word with last word.
package learn;
public class MiddleWordSwap {
public static void main(String[] args) {
char[] str = "Java is nice but Scala is even better :)".toCharArray();
char[] goal = "Java is nice but :) is even better Scala".toCharArray();
System.out.println("Original: '" + new String(str) + "'");
str = rearrange(str);
@sinanduman
sinanduman / fib-with-tail-rec.clj
Created October 7, 2015 17:48
Fibonacci numbers with tail recursion optimization
(defn fib
([n]
(fib n 0 1 0) )
([n start prev acc]
(if (= n start)
acc
(fib n (inc start) acc (+ prev acc ) )
)
)
)
@sinanduman
sinanduman / ClientService.java
Last active November 6, 2015 07:06
ServerSocket example using ThreadPool
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;
public class ClientService {
Socket socket = null;
DataInputStream dis = null;
@sinanduman
sinanduman / Tree.java
Created April 29, 2016 05:12
Simple Linked List add and list implementation
package oasis;
public class Tree {
public Student head = null;
public void add(Integer number, String name, String surname) {
Student student = new Student(number, name, surname);
if (head == null) {
head = student;
} else {
@sinanduman
sinanduman / Roman.scala
Last active February 9, 2017 04:13
Lexical ordering Roman Numbers in King Titles
package algo
class Roman(kings: Array[String]) {
val basicLetters = Map(
'I' -> 1,
'V' -> 5,
'X' -> 10,
'L' -> 50,
'C' -> 100,