76
\$\begingroup\$

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

61 Answers 61

2
\$\begingroup\$

Perl, 76 74 bytes

$_=121202211;$_.=0 .y/2/3/r;print$_?(0,Hare,Krishna,Rama)[$_].$":$/for/./g
\$\endgroup\$
1
  • 1
    \$\begingroup\$ 2 bytes shorter: Try it online! (I'm pretty sure the output is the right one) \$\endgroup\$
    – Dada
    Commented Apr 28, 2017 at 19:35
2
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ Could you replace Hare, Krishna, and Rama with their own macros? \$\endgroup\$ Commented Apr 28, 2017 at 21:19
  • \$\begingroup\$ @ETHproductions Maybe I could, but that wouldn't be too interesting ;) \$\endgroup\$
    – Okx
    Commented Apr 28, 2017 at 21:26
2
\$\begingroup\$

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
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Good start! Here are some tips: gist.github.com/arodland/c061dd7b0207a9b77a768391c3ff3e64 \$\endgroup\$
    – hobbs
    Commented Apr 29, 2017 at 4:21
  • \$\begingroup\$ And the PPCG Perl golfing tips \$\endgroup\$
    – hobbs
    Commented Apr 29, 2017 at 4:22
  • \$\begingroup\$ Retaining the ideas from yours but just golfing it harder puts it within a few bytes of the best perl solutions \$\endgroup\$
    – hobbs
    Commented Apr 29, 2017 at 4:31
  • \$\begingroup\$ Nice work, have revised the answer accordingly. \$\endgroup\$
    – steve
    Commented Apr 29, 2017 at 8:26
2
\$\begingroup\$

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.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ How long would it be to output the original raw string directly? \$\endgroup\$
    – Cœur
    Commented May 1, 2017 at 16:12
  • 1
    \$\begingroup\$ @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. \$\endgroup\$
    – Lord Yuuma
    Commented May 11, 2017 at 15:11
2
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to Programming Puzzles and Code Golf! :) \$\endgroup\$
    – Adnan
    Commented May 1, 2017 at 11:44
2
\$\begingroup\$

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

\$\endgroup\$
2
\$\begingroup\$

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);}
\$\endgroup\$
2
\$\begingroup\$

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"
\$\endgroup\$
2
\$\begingroup\$

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());
    }
}
\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Commented May 2, 2017 at 13:14
2
\$\begingroup\$

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"])
\$\endgroup\$
1
2
\$\begingroup\$

///, 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)

\$\endgroup\$
2
\$\begingroup\$

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]*/"
"}
}
\$\endgroup\$
2
\$\begingroup\$

Batch, 117 111 103 89 bytes

@set a=Hare 
@for %%A in ("Krishna " "Rama ") do @echo %a%%%~A%a%%%~A^

%%~A%%~A%a%%a%

Down to 103 now that trailing newlines are allowed. Down to 89 after adapting the Powershell answer.

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

\$\endgroup\$
2
\$\begingroup\$

CSS 3 logo

CSS: 132 Bytes

No use of HTML. Not the best, not the worst but the Brainfuck (No. of bytes) and Matlab solutions (Direct output) made me post this. Can some CSS wizards help save some bytes?

body:after{content:"Hare Krishna Hare Krishna\AKrishna Krishna Hare Hare\AHare Rama Hare Rama\ARama Rama Hare Hare";white-space:pre}


SASS logo

CSS with superpowers could not beat it until someone can prove me wrong.

SASS: 163 Bytes

$a:Hare;$b:Krishna;$c:Rama;body:after{content:"#{$a} #{$b} #{$a} #{$b}\A#{$b} #{$b} #{$a} #{$a}\A#{$a} #{$c} #{$a} #{$c}\A#{$c} #{$c} #{$a} #{$a}";white-space:pre}

Run it on:

Code Sandbox demo

\$\endgroup\$
2
\$\begingroup\$

Raku (Perl 6) (rakudo), 61 60 56 bytes

$!="Hare ";"$!$_ $!$_
$_ $_ $!$!".say for <Krishna Rama>

Attempt This Online!

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
7
  • \$\begingroup\$ 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?! \$\endgroup\$
    – yo'
    Commented May 3, 2017 at 11:44
  • 1
    \$\begingroup\$ Is is not very clever of semi boring \$\endgroup\$
    – user63187
    Commented May 5, 2017 at 15:00
  • \$\begingroup\$ 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. \$\endgroup\$
    – BradC
    Commented Jun 27, 2017 at 19:37
  • \$\begingroup\$ mothereff.in/byte-counter this site would beg to differ with your byte count \$\endgroup\$
    – Brian H.
    Commented Sep 12, 2017 at 13:49
  • \$\begingroup\$ @BrianH. Right, it should be even lower; I'm not sure how I counted, I probably considered <CR> as 2 charaters rather than 1. \$\endgroup\$
    – yo'
    Commented Sep 12, 2017 at 13:59
1
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ @DLosc 05AB1E changed it's base-214 encryption to base-255; this is the reason this submission no longer works. \$\endgroup\$ Commented Jun 27, 2017 at 18:49
  • \$\begingroup\$ @DLosc I think this would be like ~34 bytes now. \$\endgroup\$ Commented Jun 27, 2017 at 18:50
  • \$\begingroup\$ Does 05AB1E also change Krishna to Krishna? \$\endgroup\$
    – m4n0
    Commented May 16, 2020 at 12:23
1
\$\begingroup\$

///, 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.

\$\endgroup\$
1
\$\begingroup\$

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)

\$\endgroup\$
1
\$\begingroup\$

Recursiva, 57 53 bytes

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

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Jq 1.5, 59 57 54 52 bytes

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

Try it online!

\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

Vyxal, 73 bytes

`Hλ½ K≥τ⇧¨ Hλ½ K≥τ⇧¨
K≥τ⇧¨ K≥τ⇧¨ Hλ½ Hλ½
Hλ½ R□• Hλ½ R□•
R□• R□• Hλ½ Hλ½`

Try it Online!

\$\endgroup\$
1
\$\begingroup\$

K (ngn/k), 65 bytes

{`0:,/("Hare ";"Krishna ";"Rama ";"\n")@"ababdbbaadacacdccaa"-97}

Try it online!

This has to be the longest K program I have ever written. Takes "aba..."-97 from the Octave answer.

\$\endgroup\$
1
\$\begingroup\$

Vyxal 3, 39 bytes

"ᶜ₂ᶠ„•;DJ$Ṙd½Jf:•"ᵇcð₇₁„r$•"ᴳ=Ṡ„rJᵛV4Ẇ'

Try it Online!

\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$
4
  • \$\begingroup\$ [set h Hare]? [set r Rama]? \$\endgroup\$ Commented Sep 26, 2017 at 0:45
  • \$\begingroup\$ @Scrooble: What are you trying to ask? set puts the value in a var that can later be consulted if prefixed by $ \$\endgroup\$
    – sergiol
    Commented Sep 26, 2017 at 0:50
  • \$\begingroup\$ Your code does not output quite what the challenge specifies. I was giving corrections; sorry for my lack of clarity. \$\endgroup\$ Commented Sep 26, 2017 at 0:54
  • \$\begingroup\$ @Scrooble: Thanks. Now fixed. Sorry for misunderstanding you \$\endgroup\$
    – sergiol
    Commented Sep 26, 2017 at 0:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.