Skip to main content
Used the 63 byte version, thanks to O.P.
Source Link
Ismael Miguel
  • 7.9k
  • 2
  • 25
  • 38

SimpleTemplate 0.84, 9292 63 bytes

This challenge was simple, yet fun!

Simply checks if the input is just "hhh...." and outputs the text, or throws an exception with the contentoutputs "err". to STDOUT:

{@ifargv.0 matches"@^h+$@"M}{@eachM.0}Hello World{@/}{@else}{@phpthrow new Exception("err")}err

There is no built-in to throw an exception, so, I had to resortThe big byte saving was due to PHP.

If just outputting err to STDOUT is fine, this can be reduced to 63 bytesthe-cobalt's comment:

{@ifargv.0 matches"@^h+$@"M}{@eachM.0}Hello World{@/}{@else}err

Outputting to STDOUT is fine, so you could use your 63 byte version.


Ungolfed:

Below is a more readable version of the code:

{@if argv.0 matches "@^h+$@"}
    {@each argv.0 as h}
        {@echo "Hello World"}
    {@/}
{@else}
    {@php throw new@echo Exception("err")}
{@/}

You can try this on: http://sandbox.onlinephpfunctions.com/code/0f87b846cadde59a01a9fae12b924ce3a406a4c6http://sandbox.onlinephpfunctions.com/code/e35a07dfbf6b3b56c2608aa86028b395ef457129

SimpleTemplate 0.84, 92 bytes

This challenge was simple, yet fun!

Simply checks if the input is just "hhh...." and outputs the text, or throws an exception with the content "err".

{@ifargv.0 matches"@^h+$@"M}{@eachM.0}Hello World{@/}{@else}{@phpthrow new Exception("err")}

There is no built-in to throw an exception, so, I had to resort to PHP.

If just outputting err to STDOUT is fine, this can be reduced to 63 bytes:

{@ifargv.0 matches"@^h+$@"M}{@eachM.0}Hello World{@/}{@else}err

Ungolfed:

Below is a more readable version of the code:

{@if argv.0 matches "@^h+$@"}
    {@each argv.0 as h}
        {@echo "Hello World"}
    {@/}
{@else}
    {@php throw new Exception("err")}
{@/}

You can try this on: http://sandbox.onlinephpfunctions.com/code/0f87b846cadde59a01a9fae12b924ce3a406a4c6

SimpleTemplate 0.84, 92 63 bytes

This challenge was simple, yet fun!

Simply checks if the input is just "hhh...." and outputs the text, or outputs "err" to STDOUT:

{@ifargv.0 matches"@^h+$@"M}{@eachM.0}Hello World{@/}{@else}err

The big byte saving was due to the-cobalt's comment:

Outputting to STDOUT is fine, so you could use your 63 byte version.


Ungolfed:

Below is a more readable version of the code:

{@if argv.0 matches "@^h+$@"}
    {@each argv.0 as h}
        {@echo "Hello World"}
    {@/}
{@else}
    {@echo "err"}
{@/}

You can try this on: http://sandbox.onlinephpfunctions.com/code/e35a07dfbf6b3b56c2608aa86028b395ef457129

Source Link
Ismael Miguel
  • 7.9k
  • 2
  • 25
  • 38

SimpleTemplate 0.84, 92 bytes

This challenge was simple, yet fun!

Simply checks if the input is just "hhh...." and outputs the text, or throws an exception with the content "err".

{@ifargv.0 matches"@^h+$@"M}{@eachM.0}Hello World{@/}{@else}{@phpthrow new Exception("err")}

There is no built-in to throw an exception, so, I had to resort to PHP.

If just outputting err to STDOUT is fine, this can be reduced to 63 bytes:

{@ifargv.0 matches"@^h+$@"M}{@eachM.0}Hello World{@/}{@else}err

Ungolfed:

Below is a more readable version of the code:

{@if argv.0 matches "@^h+$@"}
    {@each argv.0 as h}
        {@echo "Hello World"}
    {@/}
{@else}
    {@php throw new Exception("err")}
{@/}

You can try this on: http://sandbox.onlinephpfunctions.com/code/0f87b846cadde59a01a9fae12b924ce3a406a4c6