Archive

Archive for the ‘Umum’ Category

Why I like her?

February 13, 2016 Leave a comment

Once upon a time she asked me why I like her. A difficult question to answer. Because at that time I don’t understand why can fall in love with her. I kept asking myself why I fell in love with her. It takes a few weeks for me to be able to answer that question.

12631490_1050134991705806_6977998918762181846_n

So, this is six main reasons why I love her: Read more…

Categories: Umum

Moving git repository to new server

1. Fetch all of the remote branches and tags from the existing repository to our local index

git fetch origin

2. Check all branch

git branch -a

01
3. Add new ssh config for new server. Create new file with text editor, I use notepad++, name with config. For windows save in C:\Users\sashihara\.ssh. After this you will have 3 file, config, id_rsa, id_rsa_aws.

Host host1 ip_host1
 HostName ip_host1
 IdentityFile C:\Users\sashihara\.ssh\id_rsa
 User gituser

Host host2 ip_host2
 HostName ip_host2
 IdentityFile C:\Users\sashihara\.ssh\id_rsa_aws
 User gituser

4. Add new remote origin, give different name. You must already have new git repository  (repo/app/new.git)

git remote add origin-new ssh://gituser@ip_host2/repo/app/new.git

5. Push to a new origin

git push --all origin-new

6. Push tags to a new origin

git push --tags new-origin

7. [optional] remove origin and rename new origin

git remote rm origin
git remote rename origin-new origin

 

Categories: Umum

Export PUTTY Sessions list

Type this command on command prompt

regedit /e "%userprofile%\desktop\putty-sessions.reg" HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions

That command will export putty session list to putty-sessions.req file locate on Desktop

If you want to export all setting, use this command

regedit /e "%userprofile%\desktop\putty.reg" HKEY_CURRENT_USER\Software\SimonTatham
Categories: Umum

Handshake

February 22, 2015 Leave a comment

Problem Statement

At the annual meeting of Board of Directors of Acme Inc, every one starts shaking hands with everyone else in the room. Given the fact that any two persons shake hand exactly once, Can you tell the total count of handshakes?

Input Format
The first line contains the number of test cases T, T lines follow.
Each line then contains an integer N, the total number of Board of Directors of Acme.

Output Format

Print the number of handshakes for each test-case in a new line.

Constraints

1 <= T <= 1000
0 < N < 106

This problem is about combinations. The formula is

For factorial calculation I’m using recursive with memoization to optimization process. Read more…

The Love-Letter Mystery

February 22, 2015 Leave a comment

James found a love letter his friend Harry has written for his girlfriend. James is a prankster, so he decides to meddle with the letter. He changes all the words in the letter into palindromes.

To do this, he follows 2 rules:

  1. He can reduce the value of a letter, e.g. he can change ‘d’ to ‘c’, but he cannot change ‘c’ to ‘d’.
  2. In order to form a palindrome, if he has to repeatedly reduce the value of a letter, he can do it until the letter becomes ‘a’. Once a letter has been changed to ‘a’, it can no longer be changed.

Each reduction in the value of any letter is counted as a single operation. Find the minimum number of operations required to convert a given string into a palindrome.

Read more…

Categories: Umum Tags: , ,

Maximizing XOR

Problem:

Given two integers: L and R, find the maximal values of A xor B given, L ≤ A ≤ B ≤ R

Java code:


import java.util.Scanner;

public class MaximizingXOR {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int l = in.nextInt();
int r = in.nextInt();
int max = 0;
for(int b=l; b<= r; b++) {
for(int a=b ; a <=r; a++) {
max = max > (a ^ b) ? max : (a ^ b);
}
}
System.out.println(max);
in.close();
}
}

Result for input 1 and 10:

maximizingXOR1

Result for input 10 and 15:

maximizingXOR2

Source:

https://www.hackerrank.com/challenges/maximizing-xor

Categories: Umum Tags: , ,

Lonely Integer

Problem:

There are N integers in an array A. All but one integer occur in pairs. Your task is to find out the number that occurs only once.

The solution I choose is using XOR operator. XOR operator have following characteristic:

  1. x (+) 0 = x
    XORing with 0 gives you back the same number.
    Thus, 0 is the identity for XOR.
  2. x (+) 1 = \x
    XORing with 1 gives you back the negation of the bit. Again, this comes from the truth table. For bitwise XOR, the property is slightly different: x ^ ~0 = ~x .
    That is, if you XOR with all 1’s, the result will be the bitwise negation of x.
  3. x (+) x = 0
    XORing x with itself gives you 0.
    That’s because x is either 0 or 1, and 0 (+) 0 = 0 and 1 (+) 1 = 0.
  4. XOR is associative.
    That is: (x (+) y) (+) z = x (+) (y (+) z).
    You can verify this by using truth tables.
  5. XOR is commutative.
    That is: x (+) y = y (+) x.
    You can verify this by using truth tables.

note: (+) is symbol for XOR operator.

Java code: Read more…