Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > "Small" Program Challenge.

Reply
Thread Tools

"Small" Program Challenge.

 
 
Roedy Green
Guest
Posts: n/a
 
      06-14-2012
On Wed, 13 Jun 2012 13:45:18 -0700, Daniel Pitts
<(E-Mail Removed)> wrote, quoted or indirectly
quoted someone who said :

>
>I've got mine down to 61 characters. See if you can match that.


here's the obvious solution at 88 chars:

public class C{public static void main(String[]
a){System.out.println("Hello World");}}

--
Roedy Green Canadian Mind Products
http://mindprod.com
Controlling complexity is the essence of computer programming.
~ Brian W. Kernighan 1942-01-01
..
 
Reply With Quote
 
 
 
 
Paul Cager
Guest
Posts: n/a
 
      06-14-2012
On Jun 13, 9:45*pm, Daniel Pitts
<(E-Mail Removed)> wrote:
> I saw a challenge Roedy posted on cljh, and I thought I might have a
> slightly more interesting one.
>
> Write a Java program which outputs "Hello World" followed by a new line
> (and nothing else).
>
> Now, do it using as few characters in the .java source code as possible.
>
> I've got mine down to 61 characters. See if you can match that.


You may also find some of the challenges on http://codegolf.stackexchange.com/
interesting.
 
Reply With Quote
 
 
 
 
Bent C Dalager
Guest
Posts: n/a
 
      06-14-2012
On 2012-06-13, Daniel Pitts <(E-Mail Removed)> wrote:
> I saw a challenge Roedy posted on cljh, and I thought I might have a
> slightly more interesting one.
>
> Write a Java program which outputs "Hello World" followed by a new line
> (and nothing else).
>
> Now, do it using as few characters in the .java source code as possible.


How much are you permitted to offload to the launcher?

Trivial example of offloading:

class A{public static void main(String[] a){System.out.print(a[0]);}}
(69 chars)

with launch instructions:

run like this (bash command line example shown, other launch
environments will have other ways of expressing the newline)

$ java A "Hello World
> "

$


And how much can you offload to a hypothetical "library" function that
just happens to do exactly what you want?

class B{public static void main(String[] a){L.f();}}
(52 chars)

Cheers,

Bent.
--
Bent Dalager - http://www.velocityreviews.com/forums/(E-Mail Removed) - http://www.pvv.org/~bcd
powered by emacs
 
Reply With Quote
 
Hiram Hunt
Guest
Posts: n/a
 
      06-14-2012

"Roedy Green" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Wed, 13 Jun 2012 13:45:18 -0700, Daniel Pitts
> <(E-Mail Removed)> wrote, quoted or indirectly
> quoted someone who said :
>
>>
>>I've got mine down to 61 characters. See if you can match that.

>
> here's the obvious solution at 88 chars:
>
> public class C{public static void main(String[]
> a){System.out.println("Hello World");}}


No need for public on class.

-- Hiram Hunt ((E-Mail Removed))


 
Reply With Quote
 
Hiram Hunt
Guest
Posts: n/a
 
      06-14-2012

"Hiram Hunt" <(E-Mail Removed)> wrote in message
news:4fd9d7d1$0$1727$c3e8da3$(E-Mail Removed) b.com...
>
> "Roedy Green" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> On Wed, 13 Jun 2012 13:45:18 -0700, Daniel Pitts
>> <(E-Mail Removed)> wrote, quoted or indirectly
>> quoted someone who said :
>>
>>>
>>>I've got mine down to 61 characters. See if you can match that.

>>
>> here's the obvious solution at 88 chars:
>>
>> public class C{public static void main(String[]
>> a){System.out.println("Hello World");}}

>
> No need for public on class.
>
> -- Hiram Hunt ((E-Mail Removed))


Sorry, I think I missed your point that this was just the obvious
solution. Other posts are already public-less on class.

-- Hiram Hunt ((E-Mail Removed))


 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      06-14-2012
Bent C Dalager <(E-Mail Removed)> writes:
>$ java A "Hello World
>> "


A mere »System.out.println()« will suffice with

java A -Dline.separator="Hello World
"

, however, some shells might not treat the embedded line
separator as intended.

 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      06-14-2012
Daniel Pitts <(E-Mail Removed)> writes:
>I've got mine down to 61 characters. See if you can match that.


Here is a new variant of the above challenge:

Write a java program (source code) with less than 4000
characters and a java command line with less than 1000
characters that writes »Hello World« followed by a newline
character and nothing else, but does so in a somewhat
surprising or unusual way.

My entry:

public class Main
{ public static void main( final java.lang.String[] args )
{ System.out.println(); System.out.print( '\n' ); }}

java -Dline.separator="Hello World" Main

 
Reply With Quote
 
Daniel Pitts
Guest
Posts: n/a
 
      06-14-2012
On 6/14/12 11:04 AM, Stefan Ram wrote:
> Daniel Pitts<(E-Mail Removed)> writes:
>> I've got mine down to 61 characters. See if you can match that.

>
> Here is a new variant of the above challenge:
>
> Write a java program (source code) with less than 4000
> characters and a java command line with less than 1000
> characters that writes »Hello World« followed by a newline
> character and nothing else, but does so in a somewhat
> surprising or unusual way.
>
> My entry:
>
> public class Main
> { public static void main( final java.lang.String[] args )
> { System.out.println(); System.out.print( '\n' ); }}
>
> java -Dline.separator="Hello World" Main
>


A slightly obfuscated program which illustrates a few surprising things.

public class Hello {
static Object left = "Top", right = "Bottom";
static Object top = "Left";
static Object bottom = "Right";

public static void main(String[] args) throws Exception {
for (int i = 0; i < 2; ++i) {
s.out.print(new Hello());
y(left, right, top, bottom);
}
}

public String toString() {
try {
top = "value";
bottom = "count";
return "enumeration" + top + bottom;
} finally {
return getClass().getName();
}
}

static <T extends java.lang.reflect.AccessibleObject> T t(T t) {
t.setAccessible(true); return t;}

static <T> void y(T l, T r, T... os) throws Exception {
for (Object o : os) {
x(l, o).set(l, x(l, o).get(r));
}
}

private static java.lang.reflect.Field x(Object l, Object o) throws
NoSuchFieldException {
return t(l.getClass().getDeclaredField(o.toString()));
}

{
left = toString();
right = " W" + b + 'r' + a + "d\n";
}

static Object a = "l";
static Object b = "o";
static System s;
}

 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      06-14-2012
On 14 Jun 2012 18:04:46 GMT, http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de (Stefan Ram)
wrote:

>Daniel Pitts <(E-Mail Removed)> writes:
>>I've got mine down to 61 characters. See if you can match that.

>
> Here is a new variant of the above challenge:
>
> Write a java program (source code) with less than 4000
> characters and a java command line with less than 1000
> characters that writes »Hello World« followed by a newline
> character and nothing else, but does so in a somewhat
> surprising or unusual way.
>
> My entry:
>
>public class Main
>{ public static void main( final java.lang.String[] args )
> { System.out.println(); System.out.print( '\n' ); }}
>
>java -Dline.separator="Hello World" Main


The IOCCC (International Obfuscated C Code Contest) has been
running yearly for twenty years. Is someone trying to start an IOJJJ
(International Obfuscated Java Jungle of Junk?)?

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Daniel Pitts
Guest
Posts: n/a
 
      06-15-2012
On 6/14/12 11:04 AM, Stefan Ram wrote:
> Daniel Pitts<(E-Mail Removed)> writes:
>> I've got mine down to 61 characters. See if you can match that.

>
> Here is a new variant of the above challenge:
>
> Write a java program (source code) with less than 4000
> characters and a java command line with less than 1000
> characters that writes »Hello World« followed by a newline
> character and nothing else, but does so in a somewhat
> surprising or unusual way.
>
> My entry:
>
> public class Main
> { public static void main( final java.lang.String[] args )
> { System.out.println(); System.out.print( '\n' ); }}
>
> java -Dline.separator="Hello World" Main
>

Another lesson: Exceptions, and the deprecated (and highly dangerous)
Thread.stop(Throwable) method.

import java.awt.EventQueue;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;

public class Hello extends Exception {
public static void main(String[] args) throws Exception {
Thread.setDefaultUncaughtExceptionHandler(
new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
e.printStackTrace(System.out);
}
});
final Thread thread = Thread.currentThread();
EventQueue.invokeAndWait(new Runnable() {
public void run() {
thread.stop(new Hello());
}
});
}

public void printStackTrace(PrintStream s) {
s.print("Hello World");
}
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to javac a java program w/ another java program which is w/o a main method cjeffwang@yahoo.com Java 1 10-31-2005 04:25 AM
System program/ Application program ?? Parvsandhu Java 2 07-11-2005 09:08 AM
how to convert a java program to an exe program ola Java 3 02-16-2004 09:42 AM
Calling Java program in another Java program Rey Java 4 12-12-2003 10:18 PM
passing data between Java program and C program--help pipi Java 1 07-21-2003 05:02 AM



Advertisments