# Hare Krishna Hare Krishna Krishna Krishna Hare Hare

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.
• From the title I was expecting something to decode binary strings into ASCII characters. The title represents a backslash. May 1, 2017 at 23:12
• All the mantra has 97 bytes. Surpisingly enough, there are answers with more than that many bytes. May 2, 2017 at 8:03

# 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.

• Convert 15973600 to base ["Hare", "Rama", "Krishna"] Thank goodness you explained that further, because that made no sense.
– anon
Apr 30, 2017 at 7:20
• I need to use base ["Hare", "Rama", "Krishna"] more. May 11, 2017 at 4:09

# 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

• drama share irish dna, really? Where did that idea come from? +1 :) Apr 27, 2017 at 22:13
• Tell me frankly, did you built a generator of 05AB1E golfed code?
– YSC
Apr 28, 2017 at 12:13
• @YSC that's not a bad idea for dictionary compression. I'm on it. Jun 27, 2017 at 18:51
• 32 bytes Jan 29, 2019 at 12:43
• How did nobody notice that this is the same length as without any compression at all? Feb 16 at 19:07

# 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.

# Octave, 74 59 bytes

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


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 = ...

• I didn't know you can index cell like that in Octave (unlike MATLAB)! Apr 30, 2017 at 12:01

# 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.

# 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!

# 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]))

• Better 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.) Apr 27, 2017 at 20:20
• I liked the root idea. ♥️ May 10, 2020 at 2:49

# 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

• Welcome to Programming Puzzles and Code Golf. Apr 28, 2017 at 3:27
• It'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. Apr 28, 2017 at 3:30
• 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. tio.run/nexus/… Apr 28, 2017 at 3:39
• @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. Apr 28, 2017 at 13:16
• main(){for(char*t="BG@ESCB;:N8F6DIBA10Hare \0Krishna \0Rama \0\n";*t^72;printf(t+*t++-48));} Saves 4 bytes.
– jdt
May 12, 2017 at 9:22

# 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'
ç^/             " 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. :)

# 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.

• Looks a bit weird without spaces between the words. Apr 28, 2017 at 9:37
• @manatwork good point, thankfully spec says trailing spaces are okay, so only cost 3 bytes Apr 28, 2017 at 9:40
• Could start a flame war, but you can use var instead of string to reduce the second example even more. Apr 28, 2017 at 15:46
• @JohnBaughman A method's return value cannot be var as far as I know, and var.Format() is definitely not a thing Apr 28, 2017 at 19:21
• Duh... Didn't think of that. You are correct, I just got myself into lamba world and misinterpreted what I was reading. Apr 28, 2017 at 19:51

# Python 2, 9288 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

• 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! tio.run/##K6gsycjPM/r/Py2/… Jun 27, 2017 at 22:32

## 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.

## 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>  • (Hare,Krishna,Rama) saves two bytes in your first code. – Dada May 4, 2017 at 12:27 # PowerShell, 7353 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. • 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!). Apr 28, 2017 at 18:42 • Instead of a spoiler tag, I figured out how to share via a link. Try it online! Apr 28, 2017 at 21:04 • @JeffFreeman nice one, shaved two more off that on the newline and array - down to 52, beating almost all the non-golfing languages. May 2, 2017 at 9:03 # 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! • or 126 bytes if the trailing new line is allowed Apr 28, 2017 at 11:23 • @2501: haha that's great. Actually I think it's 105 bytes may be you should post it as an answer Apr 28, 2017 at 11:32 • I'm pretty sure further improvements are possible. – 2501 Apr 28, 2017 at 12:11 • FYI, TIO supports Octave :) tio.run/nexus/… Apr 28, 2017 at 16:47 • x={'Hare ','Krishna ','Rama ',10};[x{'ababdbbaadacacdccaa'-96}] is 64 bytes. :P (translating @Stewie Griffin's octave submission) Apr 30, 2017 at 12:06 # 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  • You can remove all AS . Apr 29, 2017 at 15:11 • Good trick, I'll definitely be using this method for some challenges. Jun 27, 2017 at 20:07 # R, 7585 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. • I can't get this to work in TIO Apr 28, 2017 at 15:12 • Probably needs a print() or something. – BLT Apr 28, 2017 at 17:18 • @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 :) Apr 29, 2017 at 8:31 • @AlbertMasclans no I'm getting an error saying object 'h' not found  tio.run/nexus/… Apr 29, 2017 at 14:26 • I think you need to replace the h= with h<- inside the calls to p Apr 29, 2017 at 14:31 # 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  # 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  • 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 Apr 28, 2017 at 13:21 # 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! • Make :Hare a Symbol. Apr 28, 2017 at 7:42 # 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}"

• Nice first try. May I suggest a couple of minor improvements? pastebin.com/0bYQF26n Apr 29, 2017 at 10:13
• Without 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" Apr 30, 2017 at 16:18

# Pyth -- 45 41 bytes

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


Try It

# 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% RamanRama 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.

• The entire output is only 92 bytes. Would it be better simply to Send Hare Krishna ...? Apr 27, 2017 at 21:43
• @DigitalTrauma HA! Yes, probably, then. I presumed fancy was better and didn't even check. AHK is not a good language for this. Apr 28, 2017 at 12:15

## Batch, 75 bytes

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


# 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).

# ksh / bash / sh, 66 bytes

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

• @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. Apr 30, 2017 at 17:58
• seems I added a blank in editing, but did subtract one, due to the change from '\n' to <CR> Apr 30, 2017 at 18:53

# 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)

K\S+
Rama


# 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.