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

71
\$\begingroup\$

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.
\$\endgroup\$
2
  • 51
    \$\begingroup\$ Convert 15973600 to base ["Hare", "Rama", "Krishna"] Thank goodness you explained that further, because that made no sense. \$\endgroup\$
    – anon
    Commented Apr 30, 2017 at 7:20
  • 17
    \$\begingroup\$ I need to use base ["Hare", "Rama", "Krishna"] more. \$\endgroup\$
    – ATaco
    Commented May 11, 2017 at 4:09
67
\$\begingroup\$

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

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.

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

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

\$\endgroup\$
1
  • \$\begingroup\$ I didn't know you can index cell like that in Octave (unlike MATLAB)! \$\endgroup\$
    – Memming
    Commented Apr 30, 2017 at 12:01
20
\$\begingroup\$

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.

\$\endgroup\$
16
\$\begingroup\$

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!

\$\endgroup\$
14
\$\begingroup\$

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

\$\endgroup\$
2
  • 2
    \$\begingroup\$ 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.) \$\endgroup\$
    – manatwork
    Commented Apr 27, 2017 at 20:20
  • \$\begingroup\$ I liked the root idea. ♥️ \$\endgroup\$ Commented May 10, 2020 at 2:49
12
\$\begingroup\$

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

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

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

\$\endgroup\$
10
\$\begingroup\$

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.

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

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
\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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/… \$\endgroup\$ Commented Jun 27, 2017 at 22:32
8
\$\begingroup\$

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.

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

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>
\$\endgroup\$
1
  • 2
    \$\begingroup\$ (Hare,Krishna,Rama) saves two bytes in your first code. \$\endgroup\$
    – Dada
    Commented May 4, 2017 at 12:27
6
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ 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!). \$\endgroup\$ Commented Apr 28, 2017 at 18:42
  • 2
    \$\begingroup\$ Instead of a spoiler tag, I figured out how to share via a link. Try it online! \$\endgroup\$ Commented Apr 28, 2017 at 21:04
  • \$\begingroup\$ @JeffFreeman nice one, shaved two more off that on the newline and array - down to 52, beating almost all the non-golfing languages. \$\endgroup\$
    – colsw
    Commented May 2, 2017 at 9:03
5
\$\begingroup\$

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!

\$\endgroup\$
7
  • \$\begingroup\$ or 126 bytes if the trailing new line is allowed \$\endgroup\$
    – user13267
    Commented Apr 28, 2017 at 11:23
  • \$\begingroup\$ @2501: haha that's great. Actually I think it's 105 bytes may be you should post it as an answer \$\endgroup\$
    – user13267
    Commented Apr 28, 2017 at 11:32
  • 5
    \$\begingroup\$ I'm pretty sure further improvements are possible. \$\endgroup\$
    – 2501
    Commented Apr 28, 2017 at 12:11
  • 1
    \$\begingroup\$ FYI, TIO supports Octave :) tio.run/nexus/… \$\endgroup\$
    – Beta Decay
    Commented Apr 28, 2017 at 16:47
  • 1
    \$\begingroup\$ x={'Hare ','Krishna ','Rama ',10};[x{'ababdbbaadacacdccaa'-96}] is 64 bytes. :P (translating @Stewie Griffin's octave submission) \$\endgroup\$
    – Memming
    Commented Apr 30, 2017 at 12:06
5
\$\begingroup\$

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
\$\endgroup\$
2
  • \$\begingroup\$ You can remove all AS . \$\endgroup\$
    – manatwork
    Commented Apr 29, 2017 at 15:11
  • \$\begingroup\$ Good trick, I'll definitely be using this method for some challenges. \$\endgroup\$
    – BradC
    Commented Jun 27, 2017 at 20:07
5
\$\begingroup\$

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.

\$\endgroup\$
8
  • \$\begingroup\$ I can't get this to work in TIO \$\endgroup\$
    – Giuseppe
    Commented Apr 28, 2017 at 15:12
  • \$\begingroup\$ Probably needs a print() or something. \$\endgroup\$
    – BLT
    Commented Apr 28, 2017 at 17:18
  • \$\begingroup\$ @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 :) \$\endgroup\$
    – Masclins
    Commented Apr 29, 2017 at 8:31
  • 1
    \$\begingroup\$ @AlbertMasclans no I'm getting an error saying object 'h' not found tio.run/nexus/… \$\endgroup\$
    – Giuseppe
    Commented Apr 29, 2017 at 14:26
  • 2
    \$\begingroup\$ I think you need to replace the h= with h<- inside the calls to p \$\endgroup\$
    – Giuseppe
    Commented Apr 29, 2017 at 14:31
5
\$\begingroup\$

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

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.

\$\endgroup\$
1
  • \$\begingroup\$ 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 \$\endgroup\$
    – Aaron
    Commented Apr 28, 2017 at 13:21
4
\$\begingroup\$

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!

\$\endgroup\$
1
  • \$\begingroup\$ Make :Hare a Symbol. \$\endgroup\$
    – manatwork
    Commented Apr 28, 2017 at 7:42
4
\$\begingroup\$

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}"
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Nice first try. May I suggest a couple of minor improvements? pastebin.com/0bYQF26n \$\endgroup\$
    – manatwork
    Commented Apr 29, 2017 at 10:13
  • \$\begingroup\$ @manatwork you should add it as your answer. \$\endgroup\$
    – Pandya
    Commented Apr 29, 2017 at 14:27
  • 1
    \$\begingroup\$ 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" \$\endgroup\$
    – ULick
    Commented Apr 30, 2017 at 16:18
3
\$\begingroup\$

Pyth -- 45 41 bytes

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

Try It

\$\endgroup\$
3
\$\begingroup\$

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.

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

Batch, 75 bytes

@for %%h in (Krishna Rama)do @echo Hare %%h Hare %%h&echo %%h %%h Hare Hare
\$\endgroup\$
3
\$\begingroup\$

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

\$\endgroup\$
3
\$\begingroup\$

ksh / bash / sh, 66 bytes

h=Hare;for j in Krishna Rama;do echo $h $j $h $j"
"$j $j $h $h;done
\$\endgroup\$
2
  • \$\begingroup\$ @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. \$\endgroup\$
    – ULick
    Commented Apr 30, 2017 at 17:58
  • \$\begingroup\$ seems I added a blank in editing, but did subtract one, due to the change from '\n' to <CR> \$\endgroup\$
    – ULick
    Commented Apr 30, 2017 at 18:53
3
\$\begingroup\$

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)

\$\endgroup\$
3
\$\begingroup\$

Haskell, 92 91 bytes

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

Edit: removed concat, used mapM_ for putStr instead

Try it online!

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

Retina, 60

Direct port of my sed answer:


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

Try it online.

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

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.

\$\endgroup\$

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.