Puzzle: You have two container - one can contain exactly 3 litres of water and the other can contain exactly 5 litres of water. How many minimum steps will you take to get exactly 4 litres of water without using any other container? You can assume the availability of sufficient quantity of water.
Solution: Find below the steps:-
Step #1: fill the 5 litres container (3L - 0, 5L - 5)
Step #2: fill the 3 litres container with the filled 5 litres container (3L - 3, 5L - 2)
Step #3: empty the just filled 3 litres container (3L -0, 5L - 2)
Step #4: transfer the 2 litres of water left in 5 litres container into 3 litres container (3L - 2, 5L - 0)
Step #5: fill the 5 litres container (3L - 2, 5L - 5)
Step #6: fill the 3 litres container (having 2L currently) using just filled 5 litres container (3L - 3, 5L - 4)
So in a minimum of 6 steps you get exactly 4L of water in the 5 litres container.
Thursday, June 30, 2011
Friday, June 10, 2011
Java - Sonar: Fix for "POM 'org.codehaus.mojo:sonar-maven-plugin' not found in repository"
This posting is meant for Java developers who has configured the code quality/metrics tool sonar and if it throws "Reason: POM 'org.codehaus.mojo:sonar-maven-plugin' not found in repository: Unable to download the artifact from any repository " while executing "mvn sonar:sonar" to publish the code quality metrics.
Reason for failure: This issue is related to maven. You can read about the actual issue here.
Fix: I'd recommend multiple work-around and try which ever works for you.
1. Try this command : 'mvn -U sonar:sonar' - This will update the local repo files. [OR]
2. Goto your Maven repo home and delete 'mojo' folder from org/codehaus/mojo(in windows:C:\Documents and Settings\\.m2\repository\org\codehaus\mojo) and rerun the sonar(mvn sonar:sonar). [OR]
3. Add the following plugin into your pom.xml and it will solve the issue(In the below code, you can provide the version you are interested in. You may go to Maven local repo and this file :org\codehaus\mojo\sonar-maven-plugin\maven-metadata-central.xml and see the version you are interested in).
Below is the exception message thrown while executing maven.
Project ID: org.codehaus.mojo:sonar-maven-plugin
Reason: POM 'org.codehaus.mojo:sonar-maven-plugin' not found in repository: Unable to download the artifact from any repository
org.codehaus.mojo:sonar-maven-plugin:pom:2.0-SNAPSHOT
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
for project org.codehaus.mojo:sonar-maven-plugin
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Unable to build project information for plugin 'org.codehaus.mojo:sonar-maven-plugin': POM 'org.codehaus.mojo:sonar-maven-plugin' not found in repository: Unable to download the artifact from any repository
org.codehaus.mojo:sonar-maven-plugin:pom:2.0-SNAPSHOT
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
for project org.codehaus.mojo:sonar-maven-plugin
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.verifyPlugin(DefaultLifecycleExecutor.java:1557)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor(DefaultLifecycleExecutor.java:1851)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.segmentTaskListByAggregationNeeds(DefaultLifecycleExecutor.java:462)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:175)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.InvalidPluginException: Unable to build project information for plugin 'org.codehaus.mojo:sonar-maven-plugin': POM 'org.codehaus.mojo:sonar-maven-plugin' not found in repository: Unable to download the artifact from any repository
Reason for failure: This issue is related to maven. You can read about the actual issue here.
Fix: I'd recommend multiple work-around and try which ever works for you.
1. Try this command : 'mvn -U sonar:sonar' - This will update the local repo files. [OR]
2. Goto your Maven repo home and delete 'mojo' folder from org/codehaus/mojo(in windows:C:\Documents and Settings\
3. Add the following plugin into your pom.xml and it will solve the issue(In the below code, you can provide the version you are interested in. You may go to Maven local repo and this file :org\codehaus\mojo\sonar-maven-plugin\maven-metadata-central.xml and see the version you are interested in).
<plugin>
<groupid>org.codehaus.mojo</groupid>
<artifactid>sonar-maven-plugin</artifactid>
<version>1.0-beta-2</version>
</plugin>
Below is the exception message thrown while executing maven.
Project ID: org.codehaus.mojo:sonar-maven-plugin
Reason: POM 'org.codehaus.mojo:sonar-maven-plugin' not found in repository: Unable to download the artifact from any repository
org.codehaus.mojo:sonar-maven-plugin:pom:2.0-SNAPSHOT
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
for project org.codehaus.mojo:sonar-maven-plugin
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Unable to build project information for plugin 'org.codehaus.mojo:sonar-maven-plugin': POM 'org.codehaus.mojo:sonar-maven-plugin' not found in repository: Unable to download the artifact from any repository
org.codehaus.mojo:sonar-maven-plugin:pom:2.0-SNAPSHOT
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
for project org.codehaus.mojo:sonar-maven-plugin
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.verifyPlugin(DefaultLifecycleExecutor.java:1557)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor(DefaultLifecycleExecutor.java:1851)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.segmentTaskListByAggregationNeeds(DefaultLifecycleExecutor.java:462)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:175)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.InvalidPluginException: Unable to build project information for plugin 'org.codehaus.mojo:sonar-maven-plugin': POM 'org.codehaus.mojo:sonar-maven-plugin' not found in repository: Unable to download the artifact from any repository
Thursday, April 21, 2011
Wednesday, April 13, 2011
File manipulation - Recursively (including subdirectories)
Some times you may want to manipulate particular file pattern from the current directory and all it's sub-directories. Here, I've demonstrated how to loop through the .txt file then display them using echo then delete it. Likewise, you can manipulate them inside loop.
echo off
rem ********************************************************************
rem * *
rem * Author: Raghunathan K Semburakkiannan *
rem * *
rem ********************************************************************
echo ~~~~~~~~~~~ List of files ~~~~~~~~~~~
echo.
pushd .
for /F "tokens=*" %%i in ('dir /s /b *.txt') do (
echo %%i
del %%i
)
popd
echo.
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo.
pause
Thursday, January 6, 2011
Sum of numbers until single digit
When you buy a vehicle in india the registration number assignment for the vehicle will stay for ever(per my knowledge, not sure if there any way to change the number some time later). Always people prefer and think certain numbers(sum of numbers until signle digit) are considered to be auspicious. So they usually say, I want a number 9 or 3 or 1 etc.(between 0 to 9).
If you pay some money, Motor registry office will provide you 1000 numbers(like choose number between 853 to 1852) and you can choose one number from that 1000 numbers(there is a possibility that some number might have taken already with in that 1000. So you have to keep telling your favorite numbers and choose the one available in that).
I also ran into this situation and want to choose the lucky number 9. It's hard to list all numbers its sum is 9. So I wrote a small Java program where you can specify the lucky number, starting number and end number, it will print out all the numbers matching you lucky number. I thought it might be useful for some of you, so putting this program in blog.
If you pay some money, Motor registry office will provide you 1000 numbers(like choose number between 853 to 1852) and you can choose one number from that 1000 numbers(there is a possibility that some number might have taken already with in that 1000. So you have to keep telling your favorite numbers and choose the one available in that).
I also ran into this situation and want to choose the lucky number 9. It's hard to list all numbers its sum is 9. So I wrote a small Java program where you can specify the lucky number, starting number and end number, it will print out all the numbers matching you lucky number. I thought it might be useful for some of you, so putting this program in blog.
public class VehicleLuckyNumber {
final static int LUCKY_NUMBER = 9;
final static int STARTING_NUMBER = 853;
final static int END_NUMBER = 1852;
public static void main(String[] args) {
int count=0;
for (int i=STARTING_NUMBER;i<= END_NUMBER; i++) {
if (sumValue(i)== LUCKY_NUMBER){
System.out.println(i);
count+=1;
}
}
System.out.println("Total count in lucky number("+LUCKY_NUMBER+") :"+count);
}
public static int sumValue(int number){
int sum = 0;
int digit = 0;
while(number > 0){
digit = number%10;
sum += digit;
number = number/10;
}
if (sum > 10) sum = sumValue(sum);
return sum;
}
}
Subscribe to:
Posts (Atom)