Hare Krishna Hare Krishna Krishna Krishna Hare Hare

66

14

Recently, I've seen Hare Krishna people with their mantra on the emblem and I've found it may be quite interesting to code golf.

The challenge

Write the Hare Krishna mantra, i.e.:

Hare Krishna Hare Krishna
Krishna Krishna Hare Hare
Hare Rama Hare Rama
Rama Rama Hare Hare

Winning criteria

This is , so shortest code in bytes wins!

Rules

  • Casing must be preserved.
  • Text should contain new lines.
  • Lines may have trailing space(s).
  • Trailing newline is allowed.
  • Parsing from web or any other external resource disallowed.

Dariusz Woźniak

Posted 2017-04-27T19:45:36.203

Reputation: 1 131

2From the title I was expecting something to decode binary strings into ASCII characters. The title represents a backslash. – user253751 – 2017-05-01T23:12:02.403

6All the mantra has 97 bytes. Surpisingly enough, there are answers with more than that many bytes. – Masclins – 2017-05-02T08:03:40.700

Hmm, Why does it surprisingly look like a Rickroll dupe? – Matthew Roh – 2017-05-02T13:07:57.993

Answers

61

Jelly, 22 bytes

“t,ȧṫÞċḅ»Ḳ“¡¥Ɓc’ṃs4K€Y

Try it online!

How it works

“t,ȧṫÞċḅ»Ḳ“¡¥Ɓc’ṃs4K€Y  Main link. No arguments.

“t,ȧṫÞċḅ»               Use Jelly's dictionary to yield the string
                        "Hare Rama Krishna". Fortunately, the words Rama, Krishna,
                        and hare (lowercase H) are in the dictionary.
         Ḳ              Split at spaces, yielding ["Hare", "Rama", "Krishna"].
          “¡¥Ɓc’        Base-250 literal; yielding 15973600.
                ṃ       Convert 15973600 to base ["Hare", "Rama", "Krishna"]
                        (ternary), where "Krishna" = 0, "Hare" = 1, and "Rama" = 2.
                 s4     Split the resulting string array into chunks of length 4.
                   K€   Join each of the four chunks by spaces.
                     Y  Join the resulting strings by linefeeds.

Dennis

Posted 2017-04-27T19:45:36.203

Reputation: 196 637

47Convert 15973600 to base ["Hare", "Rama", "Krishna"] Thank goodness you explained that further, because that made no sense. – Fund Monica's Lawsuit – 2017-04-30T07:20:52.160

12I need to use base ["Hare", "Rama", "Krishna"] more. – ATaco – 2017-05-11T04:09:02.103

64

05AB1E, 38 bytes

Can be shortened by 2 bytes if trailing newlines are okay.

“«Î‡Ä¦í¥Â“#€¦`«'kì)™ð«•2ÍZì•3BSè#4ô¨»?

Try it online!

Explanation

“«Î‡Ä¦í¥Â“                              # push the string "drama share irish dna"
          #                             # split on spaces
           €¦                           # remove the first character of each word
             `                          # split to stack as separate words 
              «'kì                      # concatenate the last 2 and prepend "k"
                  )™                    # wrap in list and title-case
                    ð«                  # append a space to each
                      •2ÍZì•            # push 27073120
                            3B          # convert to base-3: 1212221110100011
                              Sè        # index into the list with each
                                #       # split on spaces
                                 4ô     # split into pieces of 4
                                   ¨    # remove the last
                                    »   # join on spaces and newlines
                                     ?  # print without newline

Emigna

Posted 2017-04-27T19:45:36.203

Reputation: 50 798

59drama share irish dna, really? Where did that idea come from? +1 :) – Stewie Griffin – 2017-04-27T22:13:18.997

14Tell me frankly, did you built a generator of 05AB1E golfed code? – YSC – 2017-04-28T12:13:17.027

1@YSC that's not a bad idea for dictionary compression. I'm on it. – Magic Octopus Urn – 2017-06-27T18:51:48.160

132 bytes – Kevin Cruijssen – 2019-01-29T12:43:05.807

43

Python 2, 60 bytes

a="Hare"
for x in"Krishna","Rama":print a,x,a,x+'\n',x,x,a,a

Try it online!

This seems to beat template-replacement approaches like this attempt.

xnor

Posted 2017-04-27T19:45:36.203

Reputation: 115 687

39

Octave, 74 59 bytes

[{'Hare ','Krishna ','Rama ',10}{'ababdbbaadacacdccaa'-96}]

Verify the output here.

Explanation:

{'Hare ','Krishna ','Rama ',10} creates a cell array with three strings, where the fourth is 10 (ASCII-value for newline).

{'ababdbbaadacacdccaa'-96} is a vector that indexes the cell array above. The vector is [1 2 1 2 4 ...] since we subtract 96 from the string ababd....

The surrounding square brackets are used to concatenate the results, instead of getting ans = Hare; and = Krishna; ans = ...

Stewie Griffin

Posted 2017-04-27T19:45:36.203

Reputation: 43 471

I didn't know you can index cell like that in Octave (unlike MATLAB)! – Memming – 2017-04-30T12:01:56.057

19

Retina, 39 bytes


hkhk¶kkhh
h
Hare 
*`k
Krishna 
k
Rama 

Try it online!

Mostly plain substitutions, the only "trick" is the modifier * which prints the result of the substitution and then reverts the string back to what it was before.

Leo

Posted 2017-04-27T19:45:36.203

Reputation: 8 482

16

PHP, 61 Bytes

<?=strtr("0101
1100
0202
2200",["Hare ","Krishna ","Rama "]);

simply replacement from the digits as key in the array with the values strtr

Try it online!

Jörg Hülsermann

Posted 2017-04-27T19:45:36.203

Reputation: 13 026

12

JavaScript, 75 70 bytes

`0101
1100
0202
2200`.replace(/./g,n=>['Hare ','Krishna ','Rama '][n])

Try it online!

console.log(`0101
1100
0202
2200`.replace(/./g,n=>['Hare ','Krishna ','Rama '][n]))

powelles

Posted 2017-04-27T19:45:36.203

Reputation: 1 277

2Better use literal newline characters in the template string directly instead of digit 3. The template string will have the same length, but you will not have to replace them later. (Will not cause array index issue, because /./ not matches newline characters.) – manatwork – 2017-04-27T20:20:13.273

12

C

154 bytes, 124 bytes, 96 bytes

i;main(){char*c="agagvggaavapapvppaaHare \0Krishna \0Rama \0\n";while(i<19)printf(c+c[i++]-78);}

Try it online!

28 bytes saved, thanks to Dennis

hucancode

Posted 2017-04-27T19:45:36.203

Reputation: 199

1Welcome to Programming Puzzles and Code Golf. – Rohan Jhunjhunwala – 2017-04-28T03:27:07.317

1It's a pretty standard acronym for programming puzzles and code golf, the name of this stack exchange. Sorry, I should have made this clear. Welcome to our site, good first post. – Rohan Jhunjhunwala – 2017-04-28T03:30:58.943

1

This won't work with all compilers, but gcc doesn't require the include statement. Also, if you restrict your submission to C, you can drop the int and declare i globally so it defaults to zero. https://tio.run/nexus/c-gcc#@59pm5uYmaehWZ2ckViklWyrlJiemF6Wnp6YWJZYkFhQVlCQmOiRWJSqEGPgXZRZnJGXCGQFJeaCqJg8JevyjMycVI1MG0NLzYKizLySNI1k7eToTG3tWF1zC03r2v//AQ

– Dennis – 2017-04-28T03:39:05.010

Thanks, I just realized that a few second before you answered. Is it ok if I include my progress in my answer, or just final version? – hucancode – 2017-04-28T03:39:28.193

We usually just leave the final version and post strikethoughs of our previous byte counts. The former versions will still be visible in the revision history. – Dennis – 2017-04-28T03:40:45.170

But that's just what most of us do. It's not a rule and you can keep them if you want to. – Dennis – 2017-04-28T03:41:53.100

Woah cool solution – Robert Fraser – 2017-04-28T04:36:09.507

This is probably OK as K&R C, but not as standard C. Even the first C standard (ANSI C, C89/90) would formally consider this code syntactically incorrect. – AnT – 2017-04-28T08:55:45.243

@Dennis Just because it does not require the include does not mean the code is OK. In pre-C99 C failure to pre-declare a variadic function results in undefined behavior, not in a compile-time diagnostic message.. – AnT – 2017-04-28T08:59:56.853

2@AnT That's correct, but code golf competitions don't require "proper" code. Here on PPCG, we define languages by their implementation. As long as there is a compiler that produces a working executable, the answer is valid. – Dennis – 2017-04-28T13:16:13.023

1main(){for(char*t="BG@ESCB;:N8F6DIBA10Hare \0Krishna \0Rama \0\n";*t^72;printf(t+*t++-48));} Saves 4 bytes. – Johan du Toit – 2017-05-12T09:22:23.103

Thanks, Johan, someone has submitted a similar answer to yours. Very clever. – hucancode – 2017-05-15T01:40:48.947

11

V, 40, 36 bytes

iHare Krishna 
 Rama ç^/ä$Ùdww.$2p

Try it online!

Hexdump:

00000000: 6948 6172 6520 4b72 6973 686e 6120 0a0e  iHare Krishna ..
00000010: 2052 616d 6120 1be7 5e2f e424 d964 7777   Rama ..^/.$.dww
00000020: 2e24 3270                                .$2p

Explanation:

iHare Krishna   " Enter 'Hare Krishna' on line 1
<C-n> Rama      " Enter 'Hare Rama' on line 2. This works because <C-n>
                " autocompletes alphabetically, and 'Hare' comes before 'Krishna'
<esc>           " Return to normal mode
ç^/             " On every line:
   ä$           "   Duplicate the text on the line horizontally
     Ù          "   Make a new copy of the line
      dw        "   Delete a word
        w       "   Move forward a word
         .      "   Delete a word again
          $     "   Move to the end of the line
           2p   "   And paste what we've deleted twice

The <C-n> command is extremely useful for challenges like this. :)

James

Posted 2017-04-27T19:45:36.203

Reputation: 54 537

10

C#, 109 bytes

void a(){Console.Write("{0}{1}{0}{1}\n{1}{1}{0}{0}\n{0}{2}{0}{2}\n{2}{2}{0}{0}","Hare ","Krishna ","Rama ");}

Fairly straightforward, Console.Write implicitly formats the string, and using Write instead of WriteLine not only saves 4 bytes, but avoids a trailing newline. Uses Unix-style newlines so might not work so well on windows, extra 6 bytes for windows by changing \n to \r\n

This method will output directly to the console, if you prefer a method that returns a string:

C#, 118 bytes

string a(){return string.Format("{0}{1}{0}{1}\n{1}{1}{0}{0}\n{0}{2}{0}{2}\n{2}{2}{0}{0}","Hare ","Krishna ","Rama ");}

Alternatively if you need a fully stand-alone and compilable program:

C#, 135 bytes

class A{static void main(){System.Console.Write("{0}{1}{0}{1}\n{1}{1}{0}{0}\n{0}{2}{0}{2}\n{2}{2}{0}{0}","Hare ","Krishna ","Rama ");}}

This should work as a compiled program provided you set A as the entry class.

Skidsdev

Posted 2017-04-27T19:45:36.203

Reputation: 9 656

Looks a bit weird without spaces between the words. – manatwork – 2017-04-28T09:37:45.450

@manatwork good point, thankfully spec says trailing spaces are okay, so only cost 3 bytes – Skidsdev – 2017-04-28T09:40:54.690

Could start a flame war, but you can use var instead of string to reduce the second example even more. – John Baughman – 2017-04-28T15:46:10.383

@JohnBaughman A method's return value cannot be var as far as I know, and var.Format() is definitely not a thing – Skidsdev – 2017-04-28T19:21:49.230

Duh... Didn't think of that. You are correct, I just got myself into lamba world and misinterpreted what I was reading. – John Baughman – 2017-04-28T19:51:27.070

In the full program you can save some Byte by writing System.Consol.Write and removing the using-Statement. – raznagul – 2017-05-02T12:12:11.033

8

C, 85 bytes

i;f(){for(i=0;printf("$0$0900$$9$*$*9**$$)"[i++]-36+"Hare \0Rama \0Krishna \0\n"););}

I would prefer a secular mantra, but I hope this is one of those peaceful religions.

See it work here.

This compacts a naive implementation by 23 bytes.

2501

Posted 2017-04-27T19:45:36.203

Reputation: 748

8

Python 2, 92 88 74 bytes

for i in'0101311003020232200':print['Hare','Krishna','Rama','\n'][int(i)],

Try it online!

No, it's not clever, no, it's not the shortest but hey, I'm new to this and it works.

Another solution (84 80 bytes):

h='Hare'
k='Krishna'
r='Rama'
n='\n'
print h,k,h,k,n+k,k,h,h,n+h,r,h,r,n+r,r,h,h

totallyhuman

Posted 2017-04-27T19:45:36.203

Reputation: 15 378

Swap the zeroes and ones, along with 'Hare' and 'Krishna' in the list. This removes the leading zero. Then convert the new number (1010300113121232211) to hex (0xe054e999f20c553), surround it by backticks, and finally realize xnor's answer is still ahead by 12 bytes! https://tio.run/##K6gsycjPM/r/Py2/SCFTITMvwaAi1cDUJNXS0jLNyCDZ1NQ4waqgKDOvJFrduyizOCMvUV1H3SOxKBVIBSXmgngxeeqx0UAVGpmasTr//wMA

– vroomfondel – 2017-06-27T22:32:17.720

6

Perl, 67 bytes

Inspired by this JavaScript entry.

$_='0101
1100
0202
2200
';s/./qw'Hare Krishna Rama'[$&].$"/ge;print

Perl, 67 bytes

@_=<Hare Krishna Rama>;print"@_[split//]\n"for<0101 1100 0202 2200>

Sinan Ünür

Posted 2017-04-27T19:45:36.203

Reputation: 233

2(Hare,Krishna,Rama) saves two bytes in your first code. – Dada – 2017-05-04T12:27:38.530

5

R, 75 85 83 bytes

cat(x<-c("Hare ","Krishna ","\n")[c(1,2,1:3,2,2,1,1,3)],sub(x[2],"Rama ",x),sep="")

It creates a vector with Hare, Krishna, and the newline, takes the ones needed, and then repeats it replacing Krishna by Rama.

Needed to include the space on every word and sep="" because otherwise cat() would put a space at the beginning of each line.

Masclins

Posted 2017-04-27T19:45:36.203

Reputation: 914

I can't get this to work in TIO

– Giuseppe – 2017-04-28T15:12:35.227

Probably needs a print() or something. – BLT – 2017-04-28T17:18:54.407

@Giuseppe I'm using here that R automatically prints. But depending how you call it, print() or cat() would be needed. That would require way more bytes. I'll post an alternative with them this weekend :) – Masclins – 2017-04-29T08:31:44.533

1

@AlbertMasclans no I'm getting an error saying object 'h' not found https://tio.run/nexus/r#@19gW5BYXJJqXaCRYavkkViUqqSTbavkXZRZnJGXqKSToZOtCZTL1skGMjNAzAydIluloMRcsGQRSKRIpwgs@f8/AA

– Giuseppe – 2017-04-29T14:26:28.220

2I think you need to replace the h= with h<- inside the calls to p – Giuseppe – 2017-04-29T14:31:06.293

Also it outputs a [1] on every line and a bunch of "s. – Flounderer – 2017-05-01T02:56:13.170

@Flounderer solved, though adding extra characters. – Masclins – 2017-05-02T07:50:31.227

Yes, outputting exact strings in R is annoying. – BLT – 2017-05-11T22:06:23.693

5

Matlab 139 136 105 bytes (thanks to @2501)

fprintf('Hare Krishna Hare Krishna\nKrishna Krishna Hare Hare\nHare Rama Hare Rama\nRama Rama Hare Hare')

Try it Online in Octave!

user13267

Posted 2017-04-27T19:45:36.203

Reputation: 151

or 126 bytes if the trailing new line is allowed – user13267 – 2017-04-28T11:23:58.903

@2501: haha that's great. Actually I think it's 105 bytes may be you should post it as an answer – user13267 – 2017-04-28T11:32:07.100

Welcome to PPCG! – Martin Ender – 2017-04-28T11:39:41.297

You can add it to your answer if you want. – 2501 – 2017-04-28T11:43:01.987

5I'm pretty sure further improvements are possible. – 2501 – 2017-04-28T12:11:16.763

1

FYI, TIO supports Octave :) https://tio.run/nexus/octave#@59WUJSZV5Kmoe6RWJSq4F2UWZyRl6iAzInJg4miyIKImDwwMygxFyoIYsXkgfkIQRChrvn/PwA

– Beta Decay – 2017-04-28T16:47:53.940

1x={'Hare ','Krishna ','Rama ',10};[x{'ababdbbaadacacdccaa'-96}] is 64 bytes. :P (translating @Stewie Griffin's octave submission) – Memming – 2017-04-30T12:06:45.197

5

PowerShell, 73 53 52 Bytes

absolutely demolished by Jeff Freeman - using an actual newline instead of \n saves another byte, and also saved one more on the array format. (from (1,2) to ,1,2)

-1 thanks to TesselatingHeckler, no comma in the array notation.

$a="Hare ";"Krishna ","Rama "|%{"$a$_$a$_
$_$_$a$a"}

My old answer - Tried a few other replace methods but all ended up being slightly longer somehow.

$a,$b,$c="Hare ","Krishna ","Rama ";"$a$b$a$b
$b$b$a$a
$a$c$a$c
$c$c$a$a"

there are newlines in the string.

pretty straightforward, uses the fact that powershell will expand variables within doublequotes, and a shorter method of assigning variables to save some bytes.

colsw

Posted 2017-04-27T19:45:36.203

Reputation: 3 195

Good solution, but I challenge you to get it down more by noticing a pattern in the output and pipelining. I've got it down to 55 Bytes. I don't know how to spoiler a comment, so just reply here if you'd like to see it (or if you'd like some hints!). – Jeff Freeman – 2017-04-28T18:42:08.433

2

Instead of a spoiler tag, I figured out how to share via a link. Try it online!

– Jeff Freeman – 2017-04-28T21:04:01.800

@JeffFreeman nice one, shaved two more off that on the newline and array - down to 52, beating almost all the non-golfing languages. – colsw – 2017-05-02T09:03:34.453

5

MySQL, 115 100 bytes

(Thanks @manatwork!)

SELECT CONCAT(a,b,a,b,d,b,b,a,a,d,a,c,a,c,d,c,c,a,a)FROM(SELECT'Hare 'a,'Krishna 'b,'Rama 'c,'\n'd)t

jlmt

Posted 2017-04-27T19:45:36.203

Reputation: 151

You can remove all AS. – manatwork – 2017-04-29T15:11:11.583

Good trick, I'll definitely be using this method for some challenges. – BradC – 2017-06-27T20:07:44.583

4

Ruby, 62 61 bytes

As I worked on this it eventually became almost identical to @xnor's Python answer, except Ruby doesn't have spaces between arguments in its print function, forcing me to use joins instead and resulting in a longer answer...

-1 bytes from @manatwork

%w"Krishna Rama".map{|i|puts [h=:Hare,i]*2*' ',[i,i,h,h]*' '}

Try it online!

Value Ink

Posted 2017-04-27T19:45:36.203

Reputation: 10 608

Make :Hare a Symbol. – manatwork – 2017-04-28T07:42:32.357

4

Sed, 72

Score includes +1 for the -r flag.

s/^/Hari Krishna/
s/.*/& &/
s/(\S+)(.*)\b(.+)/&\n\3\2\1/p
s/K\S+/Rama/g

Try it online.

Digital Trauma

Posted 2017-04-27T19:45:36.203

Reputation: 64 644

Pretty sure there's a way to remove some bytes using change, append or insert instead of substitute. Edit : not that sure anymore ; Edit edit : yeah no that doesn't work because they don't work on the pattern space but instead directly output – Aaron – 2017-04-28T13:21:28.623

4

Bash, 93 90 bytes

h="Hare " k="Krishna " r="Rama " s="$h$k$h$k\n$k$k$h$h\n$h$r$h$r\n$r$r$h$h"
echo -e "${s}"

Katharine Osborne

Posted 2017-04-27T19:45:36.203

Reputation: 141

1

Nice first try. May I suggest a couple of minor improvements? https://pastebin.com/0bYQF26n

– manatwork – 2017-04-29T10:13:13.217

@manatwork you should add it as your answer. – Pandya – 2017-04-29T14:27:34.030

1Without the variable s= it's down to 79 h="Hare " k="Krishna " r="Rama ";echo -e "$h$k$h$k\n$k$k$h$h\n$h$r$h$r\n$r$r$h$h" – ULick – 2017-04-30T16:18:31.167

3

Pyth -- 45 41 bytes

Ms(GHGHbHHGG)K"Hare "gK"Krishna "gK"Rama 

Try It

Maria

Posted 2017-04-27T19:45:36.203

Reputation: 644

3

AHK, 107 92 bytes

This feels ridiculous but I can't find a shorter means in AHK to do this:

h=Hare
k=Krishna
Send %h% %k% %h% %k%`n%k% %k% %h% %h%`n%h% Rama %h% Rama`nRama Rama %h% %h%

Here's what I tried first that was 107 bytes and tried to be fancy. As Digital Trauma pointed out, though, it would have been shorter to just send the raw text.

n=1212422114131343311
a=Hare |Krishna |Rama |`n
StringSplit,s,a,|
Loop,Parse,n
r:=r s%A_LoopField%
Send %r%

StringSplit creates a pseudo-array with 1 as the first index. So the first term is referenced with s1, the second with s2, etc. Otherwise, there's nothing fancy here.

Engineer Toast

Posted 2017-04-27T19:45:36.203

Reputation: 5 769

13The entire output is only 92 bytes. Would it be better simply to Send Hare Krishna ...? – Digital Trauma – 2017-04-27T21:43:28.890

@DigitalTrauma HA! Yes, probably, then. I presumed fancy was better and didn't even check. AHK is not a good language for this. – Engineer Toast – 2017-04-28T12:15:42.767

3

Batch, 75 bytes

@for %%h in (Krishna Rama)do @echo Hare %%h Hare %%h&echo %%h %%h Hare Hare

Neil

Posted 2017-04-27T19:45:36.203

Reputation: 95 035

3

ksh / bash / sh, 66 bytes

h=Hare;for j in Krishna Rama;do echo $h $j $h $j"
"$j $j $h $h;done

ULick

Posted 2017-04-27T19:45:36.203

Reputation: 131

@nimi Thanks. Changed it to an <CR>, makes it even shorter. Can't test it myself, but this should work. At least it works in bash and even (busybox)sh. – ULick – 2017-04-30T17:58:09.607

seems I added a blank in editing, but did subtract one, due to the change from '\n' to <CR> – ULick – 2017-04-30T18:53:08.217

3

C 96 bytes

*v[]={"Hare ","Krishna ","Rama ","\n"};
main(){for(long a=0x30ae2305d10;a/=4;printf(v[a&3]));}

You only need two bits of information to figure out which word from the prayer is needed next, so instead of using a bunch of memory and encoding it as a string, you can just encode it as a 40 bit integer (i.e. inside a long int).

Imran Khan

Posted 2017-04-27T19:45:36.203

Reputation: 31

3

APL (Dyalog), 47 bytes

Requires ⎕IO←0 which is default on many systems.

↑∊¨↓'Krishna ' 'Hare ' 'Rama '[(4⍴3)⊤8×4 1 5 2]

Try it online!

8×4 1 5 2 multiply; [32,8,40,16]

(4⍴3)⊤ convert to 4-digit base 3; matrix [[1,0,1,0],[0,0,1,1],[1,2,1,2],[2,2,1,1]]

[] index

 split into list of lists

∊¨ enlist (flatten each)

 mix into matrix (padding with spaces)

Adám

Posted 2017-04-27T19:45:36.203

Reputation: 37 779

2

Retina, 60

Direct port of my sed answer:

Hari Krishna
.+
$0 $0
:`(\S+)(.*)\b(.+)
$0¶$3$2$1
K\S+
Rama

Try it online.

Digital Trauma

Posted 2017-04-27T19:45:36.203

Reputation: 64 644

2

Perl, 98 72 bytes

@a=("Hare ","Krishna ","Rama ","\n");foreach(split//,'ababdbbaadacacdccaad'){print $a[ord($_)-97]}

98 now reduced to 72, following @hobbs reworking, nice.

print+("Hare ","Krishna ","Rama ",$/)[$_]for'01013110030202322003'=~/./g

steve

Posted 2017-04-27T19:45:36.203

Reputation: 2 276

1

Good start! Here are some tips: https://gist.github.com/arodland/c061dd7b0207a9b77a768391c3ff3e64

– hobbs – 2017-04-29T04:21:58.600

And the PPCG Perl golfing tips

– hobbs – 2017-04-29T04:22:11.070

Retaining the ideas from yours but just golfing it harder puts it within a few bytes of the best perl solutions – hobbs – 2017-04-29T04:31:44.830

Nice work, have revised the answer accordingly. – steve – 2017-04-29T08:26:15.900

2

Perl, 76 74 bytes

$_=121202211;$_.=0 .y/2/3/r;print$_?(0,Hare,Krishna,Rama)[$_].$":$/for/./g

ephemient

Posted 2017-04-27T19:45:36.203

Reputation: 1 601

1

2 bytes shorter: Try it online! (I'm pretty sure the output is the right one)

– Dada – 2017-04-28T19:35:11.760

2

Java 7, 104 103 bytes

String c(){return"xyxy\nyyxx\nxRama xRama\nRama Rama xx".replace("x","Hare ").replace("y","Krishna ");}

Explanation:

String c(){                                      // Method without parameters and String return-type
  return"xyxy\nyyxx\nxRama xRama\nRama Rama xx"  //  Return this String
    .replace("x","Hare ")                        //  after we've replaced all "x" with "Hare "
    .replace("y","Krishna ");                    //  and all "y" with "Krishna "
}                                                // End of method

Try it here.

Kevin Cruijssen

Posted 2017-04-27T19:45:36.203

Reputation: 67 575

2

Hack 68 bytes

<?hh echo strtr("0101
1100
0202
2200",["Hare ","Krishna ","Rama "]);

Straight port of the PHP Answer, just wanted to finally get an excuse to use hack in PPCG :D

Skidsdev

Posted 2017-04-27T19:45:36.203

Reputation: 9 656

2

Batch, 117 111 103 bytes

@set a=Hare &set b=Krishna &set c=Rama 
@echo %a%%b%%a%%b%^

%b%%b%%a%%a%^

%a%%c%%a%%c%^

%c%%c%%a%%a%

Down to 103 now that trailing newlines are allowed.

^\n\n is used to insert a newline at the end of the first three lines and there's a space after Rama.

SomethingDark

Posted 2017-04-27T19:45:36.203

Reputation: 211

2

Brainfuck Substitutor, 277 bytes

{--y{-z[<]w++v->u>+<t-[x[-]Hxtuyy-]>-.ax+[ty<]>>-]<-.rx>+[-vwz>-]>.ext>w<y{]>-. x>tt-<]>u]>-.Kxtuyy-]>w.ix+[v-z>{]>.sx+[vv-z>{]>.hx+[v-z>{]>-.nxt>{<yy-]>.!xwwwww.Rxtuy]>y.mx+[v-z>+>{]>.
Hare Krishna Hare Krishna!Krishna Krishna Hare Hare!Hare Rama Hare Rama!Rama Rama Hare Hare

Brainfuck Substitutor (or BFS for short) can redefine characters to be replaced with other characters.

This program redefines the characters of the Hare Krishna mantra with brainfuck 'mini' programs that prints the appropiate characters.

As this is run in succinct mode (which doesn't need any command line arguments and is on my default), we can't redefine newlines (at least, in the current version) so I use the character ! instead - but it still outputs a newline.

This first bit of the program: {--y{-z[<]w++v->u>+<t-[x[-] is short replacements for patterns that come up often in the future.

The interpreter breaks them down like this:

{ equals --
y equals {- equals ---
z equals [<]
w equals ++
v equals ->
u equals >+<
t equals -[
x equals [-]

Similar thing goes for every other character. I used the shortest brainfuck constants on the esolangs wiki page to get my algorithms, and replaced common patterns. There may be other patterns I can replace (my original attempt was 320 bytes), but this is what I have for now.

Okx

Posted 2017-04-27T19:45:36.203

Reputation: 15 025

Could you replace Hare, Krishna, and Rama with their own macros? – ETHproductions – 2017-04-28T21:19:08.990

@ETHproductions Maybe I could, but that wouldn't be too interesting ;) – Okx – 2017-04-28T21:26:31.267

2

Emacs Lisp, 109 bytes

(lambda()(apply'concat(mapcar(lambda(x)(nth(- x ?a)'("Hare ""Krishna ""Rama ""\n")))"ababdbbaadacacdccaad")))

Can theoretically be reduced to 103 bytes by using ^@,^A,^B and ^C instead of a, b, c and d and x instead of (nth(- x ?a)), but then it could not be pasted due to NULL characters.

Lord Yuuma

Posted 2017-04-27T19:45:36.203

Reputation: 587

1How long would it be to output the original raw string directly? – Cœur – 2017-05-01T16:12:41.800

1@Cœur 91 as the length of the string itself, +2 for quotes, +10 if you wrap it in a lambda, resulting in 103 total. Emacs Lisp is not a good language for golfing. – Lord Yuuma – 2017-05-11T15:11:14.310

2

Wolfram Mathematica, 71 75 bytes

{"Krishna ","Hare ","Rama ","\n"}[[IntegerDigits[73825885093,4]+1]]<>""

Every part of result was encoded as an index in a list, and every index was encoded as digit of 4-ary integer.

Sauron

Posted 2017-04-27T19:45:36.203

Reputation: 41

Welcome to Programming Puzzles and Code Golf! :) – Adnan – 2017-05-01T11:44:58.530

2

Perl 6, 61 60

my $a="Hare ";"$a$_ $a$_\n$_ $_ $a$a".say for <Krishna Rama>

bb94

Posted 2017-04-27T19:45:36.203

Reputation: 1 831

2

C++ 158 Bytes

#include <iostream>
#define H "Hare "
#define K "Krishna "
#define R "Rama "
#define N "\n"
void m(){std::cout<<(H K H K N K K H H N H R H R N R R H H);}

Pharap

Posted 2017-04-27T19:45:36.203

Reputation: 195

2

C# 103 99 Bytes

()=>{string a="Hare ",b="Krishna ",c="Rama ",d="\n";return a+b+a+b+d+b+b+a+a+d+a+c+a+c+d+c+c+a+a;};

Ungolfed full program:

class A
{
    static void Main()
    {
        System.Func<string> f =
            () =>
            {
                string a = "Hare ",
                    b = "Krishna ",
                    c = "Rama ",
                    d = "\n";
                return a + b + a + b + d + b + b + a + a + d + a + c + a + c + d + c + c + a + a;
            };
        System.Console.Write(f());
    }
}

raznagul

Posted 2017-04-27T19:45:36.203

Reputation: 424

1

You could golf it by 1 byte by using a port of my Java 7 answer: ()=>{return"xyxy\nyyxx\nxRama xRama\nRama Rama xx".Replace("x","Hare ").Replace("y","Krishna ");}; Try it here.

– Kevin Cruijssen – 2017-05-02T13:14:36.603

2

Clojure(Script), 70 bytes (69 bytes?)

(def a"Hare")(run! #(println a % a %(str"\n"%)% a a)["Krishna""Rama"])

This version with 69 bytes will only work at the repl, because map is lazy and I don't use the return value for anything. Dunno how the rules work in this case...

(def a"Hare")(map #(println a % a %(str"\n"%)% a a)["Krishna""Rama"])

madstap

Posted 2017-04-27T19:45:36.203

Reputation: 141

Welcome to Programming Puzzles & Code Golf! I'd say that your 69-byte solution is correct, because here on PPCG, a language is defined by its implementation.

– Steadybox – 2017-05-02T22:23:49.457

2

Haskell, 92 91 bytes

g=mapM_ putStr$(!!)["Hare ","Krishna ","Rama ","\n"]<$>(read.(:[]))<$>"0101311003020232200"

Edit: removed concat, used mapM_ for putStr instead

Try it online!

maple_shaft

Posted 2017-04-27T19:45:36.203

Reputation: 421

2

///, 46 bytes

/4/Hare //k/Krishna //X/4k4k
kk44/X
/k/Rama /X

Try it online!

There was already one answer in ///, but this one adds a bit of complexity to remove some bytes.

In pseudocode this could translate to:

4="Hare "
k="Krishna "
X=4+k+4+k+'\n'+k+k+4+4
print(X+'\n')
replace k with "Rama "
print(X)

(I wanted to use h as the letter to substitute with "Hare ", but "Krishna" also contains an h, so that messed up the substitutions and I had to switch it with 4)

Leo

Posted 2017-04-27T19:45:36.203

Reputation: 8 482

2

Husk, 22 bytes

ṁSeÖ>m´+Πmw¶¨Hȧeȷ#,R□m

Try it online!

I've worked for quite some time on this answer since I wanted to beat the "compressed number" algorithm of the current top answer by exploiting more of the regularities in the text.

In the end I "only" managed to tie its score. I actually have in mind a couple of builtins for Husk that could easily save more bytes, but implementing them before posting this answer would have felt too much like cheating.

Explanation

Husk automatically prints a matrix of strings by joining them with spaces and newlines. In this case we are actually trying to build the matrix

[["Hare","Krishna","Hare","Krishna"],
["Krishna","Krishna","Hare","Hare"],
["Hare","Rama","Hare","Rama"],
["Rama","Rama","Hare","Hare"]]

which will implicitly get printed to StdOut as the required text. For simplicity, I will show each step of computation as if it was printed by a full program, joining strings with spaces and newlines.

We need to work with "Hare" and ("Krishna" and "Rama"): mw¶¨Hȧeȷ#,R□m

¨Hȧeȷ#,R□m is a compressed string; Husk has a dictionary containing common n-grams (sequences of characters) which are encoded with symbols possibly reminding of the original n-gram. For example, the H here is a plain "H", while ȧe is "are\n". The plaintext string this decodes to is "Hare\nKrishna Rama" (where \n is an actual newline). splits this string on the newline, and mw splits each line into words. The output we get up to here is:

Hare
Krishna Rama

"Hare" should pair with both of the other words: Π

Cartesian product of all the lines. This means that we pair each element of the first line with each element of the second line. Our result is:

Hare Krishna
Hare Rama

The first and third lines are just those words repeated twice: m´+

Concatenate each of the lines with itself. (´ makes + use a single argument twice, and m maps this function to each line). We get:

Hare Krishna Hare Krishna
Hare Rama Hare Rama

The other lines are the previous lines sorted in reverse alphabetical order: ṁSeÖ>

This is not as weird as it looks. Ö> sorts a list in descending order. With SeÖ> we create a two-element list with the original argument before and after having been sorted. maps this function to each line, and concatenates the resulting lists. This is finally:

Hare Krishna Hare Krishna
Krishna Krishna Hare Hare
Hare Rama Hare Rama
Rama Rama Hare Hare

Leo

Posted 2017-04-27T19:45:36.203

Reputation: 8 482

2

Wren, 91 bytes

Fn.new{
var n="Hare"
return["Krishna","Rama"].map{|i|[n,i,n,i,"
"+i,i,n,n].join(" ")+"
"}
}

Try it online!

Explanation

Fn.new{                                    // New anonymous function
var n="Hare"                               // Define a template constant
return["Krishna","Rama"].map{|i|[n,i,n,i,  /* Map using the rule*/"
"+i,i,n,n].join(" ")+                      /* [n,i,n,i,"\n",i,i,n,n]*/"
"}
}

user85052

Posted 2017-04-27T19:45:36.203

Reputation:

1

Fourier, 94 bytes

|72a97a114a101a32a|H|75a114a-9a115a104a+6a97a32a|K|82a97a109a97a32a|RHKHK10aKKHH10aHRHR10aRRHH

Try it on FourIDE!

Makes good use of functions: H for Hare, K for Krishna and R for Rama.

Now I can't get the song My Sweet Lord out of my head :P

Beta Decay

Posted 2017-04-27T19:45:36.203

Reputation: 21 478

1

05AB1E, 54 bytes

•4Ñ••}ò´••9Ä•)©\•2}¾S•3BRv®yè8ÝJ"ahrekisnm"‡})4ôvyðý™,

Try it online!

•4Ñ•                          # Hare
    •}ò´•                     # Krishnu
         •9Ä•)©\              # Rama
                •2}¾S•3BR     # Sequencing data.
v®yè8ÝJ"ahrekisnm"‡}          # For each sequence part, push the right word.
                    )4ôvyðý™, # Format it correctly.

05AB1E changed its base-214 encryption to base-255; this is the reason this submission no longer works; however, it was valid at the time.

Magic Octopus Urn

Posted 2017-04-27T19:45:36.203

Reputation: 19 422

@DLosc 05AB1E changed it's base-214 encryption to base-255; this is the reason this submission no longer works. – Magic Octopus Urn – 2017-06-27T18:49:40.393

@DLosc I think this would be like ~34 bytes now. – Magic Octopus Urn – 2017-06-27T18:50:34.637

1

Haskell 103 95 Bytes

main=putStr$concat$concat$[[h,x,h,x,n,x,x,h,h,n]|x<-["Krishna ","Rama "]]where h="Hare ";n="\n"

Old 103 Bytes:

main=putStr$concat[h,k,h,k,n,k,k,h,h,n,h,r,h,r,n,r,r,h,h] where h="Hare ";k="Krishna ";r="Rama ";n="\n"

Pharap

Posted 2017-04-27T19:45:36.203

Reputation: 195

1

SmileBASIC 3, 76 bytes

Straightforward answer with string multiplication. ? is print.

?"Hare Krishna "*2?"Krishna "*2+"Hare "*2?"Hare Rama "*2?"Rama "*2+"Hare "*2

snail_

Posted 2017-04-27T19:45:36.203

Reputation: 1 982

1

cat 97 bytes

Hare Krishna Hare Krishna<CR>
Krishna Krishna Hare Hare<CR>
Hare Rama Hare Rama<CR>
Rama Rama Hare Hare<^D>

I consider <^D> as two characters, whence 97

yo'

Posted 2017-04-27T19:45:36.203

Reputation: 563

I would really like to know what's wrong with the answer. It's working, and it's shorter than many "clever" answers by people around. So what?! – yo' – 2017-05-03T11:44:14.160

1Is is not very clever of semi boring – Christopher – 2017-05-05T15:00:36.223

There are many puzzles where the "trivial" output is, in fact, the shortest. Even if it isn't, I always start with the trivial solution so I have something to compare against. This answer is straight-forward, but perfectly fine. – BradC – 2017-06-27T19:37:36.473

https://mothereff.in/byte-counter this site would beg to differ with your byte count – Brian H. – 2017-09-12T13:49:47.093

@BrianH. Right, it should be even lower; I'm not sure how I counted, I probably considered <CR> as 2 charaters rather than 1. – yo' – 2017-09-12T13:59:55.127

it's giving 107 bytes... – Brian H. – 2017-09-12T14:03:02.557

@BrianH. Well, <CR> stands for carriage return, i.e., enter (1 keypress). – yo' – 2017-09-12T14:03:55.347

1

Groovy, 82 bytes

a=["Hare ","Krishna ","Rama ","\n"]
"0101311003020232200".each{print a[it as int]}

An improvement of my previous answer (1 byte longer)

h="Hare "
k="Krishna "
r="Rama "
n="\n"
print h+k+h+k+n+k+k+h+h+n+h+r+h+r+n+r+r+h+h

staticmethod

Posted 2017-04-27T19:45:36.203

Reputation: 191

1

Recursiva, 57 53 bytes

r2r1r0"0101/n1100/n0202/n2200"'Hare ''Krishna ''Rama 

Try it online!

officialaimm

Posted 2017-04-27T19:45:36.203

Reputation: 2 739

1

///, 49 bytes

/#/Hare //k/Krishna //j/Rama /#k#k
kk##
#j#j
jj##

Try it online!

Although /// is an esoteric language, this one is shorter than most of the other (non-golfing, and a bad implementation of this problem in Retina) languages here. Mostly because /// has too few functionalities, that they can be represented in few bytes.

user202729

Posted 2017-04-27T19:45:36.203

Reputation: 14 620

1

Javascript 85 bytes

I know there's a better answer already, but i wanted to give it a try anyway, the method is pretty different as you'll see:

a=["Krishna ","Rama "];q="Hare ";b=(z)=>q+a[z]+q+a[z]+`
`+a[z]+a[z]+q+q+`
`;b(0)+b(1)

a=["Krishna ","Rama "];q="Hare ";b=(z)=>q+a[z]+q+a[z]+`
`+a[z]+a[z]+q+q+`
`;console.log(b(0)+b(1));

Please note that i had to put the console.log() in a weird spot, if you just paste the code block into the console it'll print the mantra.

dumbded down better golfed version 76 bytes:

a="Krishna ";b="Rama ";c="Hare ";d=`
`;c+a+c+a+d+a+a+c+c+d+c+b+c+b+d+b+b+c+c

a="Krishna ";b="Rama ";c="Hare ";d=`
`;console.log(c+a+c+a+d+a+a+c+c+d+c+b+c+b+d+b+b+c+c)

Brian H.

Posted 2017-04-27T19:45:36.203

Reputation: 513

1

Jq 1.5, 59 57 54 52 bytes

def h:"Hare "+.;"Krishna ","Rama "|h*2,.*2+"Hare "*2

Try it online!

jq170727

Posted 2017-04-27T19:45:36.203

Reputation: 411

1

J, 49 41 bytes

;"1{&(<;.2'Hare Krishna Rama ')(,-)#:5 12

How it works

                                   #:5 12 to binary [(0 1 0 1), (1 1 0 0)] 
                               ( -)       negate    [(0-1 0-1),(-1-1 0 0)]
                               (, )       append    [(0 1 0 1),(1 1 0 0),(0-1 0-1),(-1-1 0 0)] 
     (<;. 'Hare Krishna Rama ')           split by 
         2                                the last character, keep it in
   {&                                     negative argument selects from the end
;"1                                       get rid of the ASCII boxes

Try it online!

FrownyFrog

Posted 2017-04-27T19:45:36.203

Reputation: 3 112

1

SmileBASIC, 58 bytes

We can use the fact that the second half is the same as the first, with "Krishna" replaced by "Rama"

P"Krishna 
P"Rama 
DEF P K?("Hare "+K)*2?K*2;"Hare "*2
END

(Note trailing spaces)

Storing "Hare " in a variable is the same length.

12Me21

Posted 2017-04-27T19:45:36.203

Reputation: 6 110

0

Tcl, 87 bytes

puts "[set h Hare] [set k Krishna] $h $k
$k $k $h $h
$h [set r Rama] $h $r
$r $r $h $h"

Try it online!

sergiol

Posted 2017-04-27T19:45:36.203

Reputation: 3 055

[set h Hare]? [set r Rama]? – Khuldraeseth na'Barya – 2017-09-26T00:45:02.573

@Scrooble: What are you trying to ask? set puts the value in a var that can later be consulted if prefixed by $ – sergiol – 2017-09-26T00:50:21.433

Your code does not output quite what the challenge specifies. I was giving corrections; sorry for my lack of clarity. – Khuldraeseth na'Barya – 2017-09-26T00:54:29.053

@Scrooble: Thanks. Now fixed. Sorry for misunderstanding you – sergiol – 2017-09-26T00:56:58.140