7
\$\begingroup\$

Using the word “conemon” print each character 2 times more than the last. The first letter, “c”, should be printed 10 times, the second 12 and so on. Each repeated-letter-string should be printed on a new line.

So the end-result becomes:

cccccccccc
oooooooooooo
nnnnnnnnnnnnnn
eeeeeeeeeeeeeeee
mmmmmmmmmmmmmmmmmm
oooooooooooooooooooo
nnnnnnnnnnnnnnnnnnnnnn
\$\endgroup\$
10
  • \$\begingroup\$ Cccccccccc Oooooooooooo Nnnnnnnnnnnnnn And so on the solution should be displaced like that. There should be new line after every character is printed n times \$\endgroup\$
    – Monolica
    Oct 2, 2018 at 10:11
  • 2
    \$\begingroup\$ Welcome to PPCG! I have update the challenge text to reflect your comment above (specifications should be in the post not in the comments). I also fixed up the grammar a little. Feel free to edit it more. \$\endgroup\$ Oct 2, 2018 at 10:17
  • \$\begingroup\$ The less characters the better. \$\endgroup\$
    – Monolica
    Oct 2, 2018 at 10:31
  • \$\begingroup\$ What is the smallest number of characters that could be used to solve this problem using python? \$\endgroup\$
    – Monolica
    Oct 2, 2018 at 13:14
  • 7
    \$\begingroup\$ Don't know if this is of use for anyone, but conemon is rot10(seduced). \$\endgroup\$ Oct 2, 2018 at 13:35

45 Answers 45

10
\$\begingroup\$

R, 50 47 45 bytes

This is some serious R abuse. I create a quote R expression C(O,N,E,M,O,N) and feed it into the string repeat function strrep, which kindly coerces each name inside the quote into a string. Shorter than scan !

write(strrep(quote(C(O,N,E,M,O,N)),5:11*2),1)

Try it online!

\$\endgroup\$
1
  • 2
    \$\begingroup\$ That deserves its own tip. \$\endgroup\$
    – JayCe
    Oct 4, 2018 at 13:07
5
\$\begingroup\$

Python 2, 36 bytes

i=8
for c in'conemon':i+=2;print c*i

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ cccccccccc oooooooooooo nnnnnnnnnnnnnn And so on the solution should be displayed like above \$\endgroup\$
    – Monolica
    Oct 2, 2018 at 10:12
  • \$\begingroup\$ @Monolica Fixed \$\endgroup\$
    – TFeld
    Oct 2, 2018 at 10:17
  • \$\begingroup\$ who would be able to improve this python code to a shorter code. i=8 for c in'conemon':i+=2;print c*i \$\endgroup\$
    – Monolica
    Oct 2, 2018 at 11:10
  • 20
    \$\begingroup\$ @Monolica FYI standard practice on PPCG is to wait quite some time (e.g. 1 week) before accepting an answer. Furthermore, for code-golf many question-posers don't ever actually accept any answer. If you are going to accept an answer, however, it should be the shortest code in bytes, since that is the winning criteria given by code-golf (given two of the same length it would be usual to accept the first to reach such a byte-count). \$\endgroup\$ Oct 2, 2018 at 11:24
4
\$\begingroup\$

K (ngn/k), 20 19 bytes

(2*5+!7)#'"conemon"

Try it online!

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

05AB1E, 16 14 bytes

.•Ω‡h₅•Sā·8+×»

-2 bytes thanks to @Emigna.

Try it online.

Explanation:

.•Ω‡h₅•           # Push "conemon"
       S          # Convert it to a list of character: ["c","o","n","e","m","o","n"]
        ā         # Push a list in the range [1, length]: [1,2,3,4,5,6,7]
         ·        # Double each: [2,4,6,8,10,12,14]
          8+      # Add 8: [10,12,14,16,18,20,22]
            ×     # Repeat the characters that many times
             »    # Join the list by newlines (and output implicitly)

See this 05AB1E tip of mine (section How to compress strings not part of the dictionary?) to understand why .•Ω‡h₅• is "conemon".

\$\endgroup\$
2
  • 1
    \$\begingroup\$ .•Ω‡h₅•Sā·8+×» for 14. \$\endgroup\$
    – Emigna
    Oct 2, 2018 at 10:35
  • \$\begingroup\$ @Emigna I was just looking for a way to remove that map. Smart way with ā·, thanks! \$\endgroup\$ Oct 2, 2018 at 10:40
2
\$\begingroup\$

Java 11, 78 bytes

v->{int i=8;for(var c:"conemon".split(""))System.out.println(c.repeat(i+=2));}

Try it online. (NOTE: String.repeat(int) is emulated as repeat(String,int) for the same byte-count, because Java 11 isn't on TIO yet.)

Explanation:

v->{                     // Method with empty unused parameter and no return-type
  int i=8;               //  Integer `i`, starting at 8
  for(var c:"conemon".split(""))
                         //  Loop over the characters (as Strings) of "codemon"
    System.out.println(  //   Print with trailing new-line:
      c.repeat(          //    The current character repeated
        i+=2));}         //    `i` amount of times, after we've first increased `i` by 2
\$\endgroup\$
2
\$\begingroup\$

Javascript, 55 52 bytes

saved 3 bytes thanks to @Arnauld

s=>[...'conemon'].map(x=>x.repeat(i+=2),i=8).join`
`

f=s=>[...'conemon'].map(x=>x.repeat(i+=2),i=8).join`
`
console.log(f());

\$\endgroup\$
3
  • \$\begingroup\$ This is a kolmogorov-complexity challenge which doesn't take any input, so you'll have to hardcode 'conemon' within the code. On the good news side, you don't need to include f= in your byte count, unless the function is referring to itself -- which is not the case here. \$\endgroup\$
    – Arnauld
    Oct 2, 2018 at 12:18
  • \$\begingroup\$ Hi. Welcome to PPCG. Quick note, you dont need to count f= bytes unless you use recursion so you answer is actually 47 bytes length \$\endgroup\$ Oct 2, 2018 at 12:19
  • \$\begingroup\$ Thank's for the clarification! I updated my answer. \$\endgroup\$
    – zruF
    Oct 2, 2018 at 12:34
2
\$\begingroup\$

Japt -R, 13 bytes

`¬¶n`¬Ë²p5+E

Try it


Explanation

`¬¶n`¬Ë²p5+E
`¦n`            :Compressed string "conemon"
     ¬           :Split
      Ë          :Map each character at 0-based index E
       ²         :  Repeat twice
        p5+E     :  Repeat 5+E times
                 :Implicitly join with new lines and output
\$\endgroup\$
0
2
\$\begingroup\$

Tcl, 78 bytes

set i 8
lmap x {c o n e m o n} {set s ""
time {set s $s$x} [incr i 2]
puts $s}

Try it online!

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

PowerShell, 35 34 bytes

'conemon'|% t*y|%{"$_$_"*(++$j+4)}

Try it online!

-1 byte thanks to mazzy

Literal string 'conemon' is converted toCharArray, then for each character we multiply it out by the appropriate length. This is handled by doubling up the character $_$_ then multiplying by $j+4 with $j pre-incremented each time (i.e., so it'll start at 1+4 = 5, which gets us 10 characters).

Each newly formed string is left on the pipeline, and implicit Write-Output gives us newlines for free.

\$\endgroup\$
2
  • \$\begingroup\$ -1? 'conemon'|% t*y|%{"$_$_"*(++$j+4)}. It is not reentrant. It requires rv j before second run. \$\endgroup\$
    – mazzy
    Oct 2, 2018 at 13:41
  • 1
    \$\begingroup\$ @mazzy Or save it into a .ps1 script and execute the script. Thanks for the byte! \$\endgroup\$ Oct 2, 2018 at 14:50
2
\$\begingroup\$

MathGolf, 15 bytes

╕│Pùmon+ô8î∞+*p

Try it online!

Explanation

╕│P                 Compression of 'cone'
   ùmon             Push 'mon'
       +            Concatenate together
        ô          Foreach over each letter
         8         Push 8
          î∞       Push the index of the loop (1 based) and double it
            +      Add the 8
             *p    Repeat the letter that many times and print with a newline
\$\endgroup\$
3
  • \$\begingroup\$ I'll write an explanation of the string compression in the mathgolf chat, look there in a minute. You could get 2-3 bytes off this solution. \$\endgroup\$
    – maxb
    Oct 2, 2018 at 11:43
  • \$\begingroup\$ This is one byte shorter. \$\endgroup\$
    – maxb
    Oct 2, 2018 at 11:51
  • \$\begingroup\$ The mapping to list of chars should not be needed now, saving one byte \$\endgroup\$
    – maxb
    Oct 2, 2018 at 16:06
2
\$\begingroup\$

Husk, 11 bytes

zR↓4İ0¨cΦ◄‰

Try it online!

Explanation

zR↓4İ0¨cΦ◄‰
      ¨cΦ◄‰        A = The compressed string "conemon"
    İ0             B = The infinite list of even positive numbers
  ↓4                             without its first four elements: [10,12,14,16...]
zR                 Create a list of strings replicating each character in A as many times
                   as the corresponding number in B

A list of strings in Husk is printed by joining them with newlines.

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

K (oK), 29 bytes

{i::8;{i+::2;i#x}'x}"conemon"

Try it online!

I'm not the biggest fan of this solution as it's bad practice (global variables), but it's short. May work on a better solution.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ You'll need to include the "conemon" in your bytecount - take a look at the other K solution for inspiration :) \$\endgroup\$
    – mkst
    Oct 4, 2018 at 20:24
  • \$\begingroup\$ The other K solution is very neat, still coming to grips with this language. Do you know of any resources for k? I work with q, but would like to become more familiar with what's under the hood \$\endgroup\$
    – Thaufeki
    Oct 8, 2018 at 21:48
  • \$\begingroup\$ Q is just syntactic sugar on top of K4, and you can see the underlying K commands by typing the Q command raw into the REPL, e.g. count will return #:. There is a good manual for oK available here (an open source implementation of a mix of K5 and K6) which explains a lot of the commands. I would also suggest you taking a look at all the codegolf answers written in K for inspiration. \$\endgroup\$
    – mkst
    Oct 9, 2018 at 12:55
  • \$\begingroup\$ There's also a Q Idioms page which shows how to perform the same task in Q or K \$\endgroup\$
    – mkst
    Oct 9, 2018 at 12:56
  • \$\begingroup\$ Great, thank you for the link <<<Q is just syntactic sugar on top of K4, and you can see the underlying K commands by typing the Q command raw into the REPL>>> That's literally how I've been writing any of these K answers, writing it in q and then just switching to the underlying K if I can because it's so much more terse Thanks for the link \$\endgroup\$
    – Thaufeki
    Oct 9, 2018 at 12:56
1
\$\begingroup\$

Red, 53 bytes

n: 8 foreach c"conemon"[loop n: n + 2[prin c]print""]

Try it online!

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

Charcoal, 14 bytes

Econemon×ι⁺χ⊗κ

Try it online! Link is to verbose version of code. Explanation:

 conemon        Literal string
E               Map over characters
             κ  Current index
            ⊗   Doubled
           χ    Predefined variable 10
          ⁺     Add
         ι      Current character
        ×       Repeat
                Implicitly print each string on separate lines
\$\endgroup\$
1
\$\begingroup\$

APL (Dyalog Classic), 21 bytes

⎕←↑'conemon'⍴¨⍨8+2×⍳7

Try it online!

\$\endgroup\$
5
  • \$\begingroup\$ I believe you can drop the first 2 bytes \$\endgroup\$
    – Quintec
    Oct 2, 2018 at 12:32
  • \$\begingroup\$ @Quintec Doesn't print anything in TIO without the first 2 bytes, that's why I left them \$\endgroup\$ Oct 2, 2018 at 12:43
  • 1
    \$\begingroup\$ put it in input \$\endgroup\$
    – Quintec
    Oct 2, 2018 at 12:46
  • \$\begingroup\$ @Quintec - I'm not sure if it's acceptable. \$\endgroup\$ Oct 2, 2018 at 13:09
  • 1
    \$\begingroup\$ Actually, for TIO you need to put anything prefixed with ⎕← to display output, or put it in input. For TryAPL and Dyalog application you don't. \$\endgroup\$
    – Quintec
    Oct 3, 2018 at 0:16
1
\$\begingroup\$

Haskell, 44 bytes

i=[0..]
g=["conemon"!!n<$take(10+n*2)i|n<-i]

Try it online!

We generate a list of lists of lengths 10, 12 etc. (by taking the appropriate amount of elements from an infinite list) and then replace each element in each such list with corresponding character from the required string.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ ["conemon"!!n<$[0..9+2*n]|n<-[0..]] (without i). As anonymous functions are allowed, you don't have to give the function a name, so drop the g=. However, I'm not sure whether a list of strings is a valid output format for this particular challenge as it says "each [...] string [...] printed on a new line". \$\endgroup\$
    – nimi
    Oct 2, 2018 at 14:45
1
\$\begingroup\$

Canvas, 14 bytes

conemon{²«8+×]

Try it here!

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

F#, 71 bytes

let d=Seq.iteri(fun i c->System.String(c,10+i*2)|>printfn"%s")"conemon"

Try it online!

Seq.iteri iterates through the sequence and applies the function to the index of the item i and the item itself c. In this case the string, every character in the string conemon.

System.String is a shortform of new System.String, taking the current letter c and repeating it 10+i*2 times, where i is the index of the letter. It then prints the string to the output with a new line.

You can omit the string and shorten it to:

let d=Seq.iteri(fun i c->System.String(c,10+i*2)|>printfn"%s")

And this will work with every string. But given this challenge is specifically for conemon the string is hard-coded.

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

jq, 56 characters

(52 characters code + 4 characters command line options)

[[range(5;12)],"conemon"/""]|transpose[]|.[1]*.[0]*2

Sample run:

bash-4.4$ jq -nr '[[range(5;12)],"conemon"/""]|transpose[]|.[1]*.[0]*2'
cccccccccc
oooooooooooo
nnnnnnnnnnnnnn
eeeeeeeeeeeeeeee
mmmmmmmmmmmmmmmmmm
oooooooooooooooooooo
nnnnnnnnnnnnnnnnnnnnnn

Try it online!

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

Ruby, 48 bytes

->{a=4;'conemon'.each_char{|s|puts s*(a=1+a)*2}}

Try it online!

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

Pyth, 17 bytes

j.e*b+Tyk"conemon

Try it here

Explanation

j.e*b+Tyk"conemon
 .e      "conemon    For each character 'b' and index 'k' in "conemon"...
   *b+Tyk            ... get 2k + 10 copies of b.
j                    Join the result with newlines.
\$\endgroup\$
1
\$\begingroup\$

D, 48 bytes

foreach(i,c;"conemon")c.repeat(10+i*2).writeln;

Explanation:

foreach(i,c;"conemon")                           // Loop over string with index i, char c
                      c.repeat(10+i*2)           // Repeat character 10 + (i*2) times
                                      .writeln;  // Write with newline

Run with rdmd:

$ rdmd --eval='foreach(i,c;"conemon")c.repeat(10+i*2).writeln;'
cccccccccc
oooooooooooo
nnnnnnnnnnnnnn
eeeeeeeeeeeeeeee
mmmmmmmmmmmmmmmmmm
oooooooooooooooooooo
nnnnnnnnnnnnnnnnnnnnnn
\$\endgroup\$
1
\$\begingroup\$

T-SQL, 84 bytes

DECLARE @ INT=1a:PRINT REPLICATE(SUBSTRING('conemon',@,1),2*@+8)SET @+=1IF @<8GOTO a

The variable/loop approach turned out shorter than the best set-based variation I came up with (91 bytes):

SELECT REPLICATE(SUBSTRING('conemon',n,1),2*n+8)FROM(VALUES(1),(2),(3),(4),(5),(6),(7))a(n)

I don't know what it is, but I found this question particularly annoying. Which probably means it's a good question.

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

MBASIC, 80 73 bytes

1 S$="conemon":FOR I=1 TO LEN(S$):PRINT STRING$(8+I*2,MID$(S$,I,1)):NEXT

Saved a loop by using the STRING$ function to generate the string of characters. Saved another 7 bytes by computing the length relative to the loop index.

Output:

cccccccccc
oooooooooooo
nnnnnnnnnnnnnn
eeeeeeeeeeeeeeee
mmmmmmmmmmmmmmmmmm
oooooooooooooooooooo
nnnnnnnnnnnnnnnnnnnnnn
\$\endgroup\$
1
\$\begingroup\$

V, 27 26 bytes

Iµc
¶o
·n
¸e
¹m
±o
±±n<esc>Îä$

<esc> represents the escape character (ascii 27)

Try it online!

Explanation

I                Enter insert mode
µc                Write 5 c and a newline
¶o                Write 6 o and a newline
·n                Write 7 n and a newline
¸e                Write 8 e and a newline
¹m                Write 9 m and a newline
±o                Write 10 o and a newline
±±n               Write 11 n
<esc>            End insert mode
Îä$              Duplicate every line
\$\endgroup\$
1
\$\begingroup\$

Jelly,  14  13 bytes

-1 Thanks to Erik the Outgolfer (pointing me to the real optimal string compressor)
...and, of course, to user202729 (for creating it)!

“¦[Þ⁷ƥ»J+4×ḤY

A full program which prints the output required.

Try it online!

How?

“¦[Þ⁷ƥ»J+4×ḤY - Main Link: no arguments
“¦[Þ⁷ƥ»       - compressed string as a list of characters -> ['c','o','n','e','m','o','n']
              - (...due to this being a leading constant this is now the argument too)
       J      - range of length  -> [ 1, 2, 3, 4, 5, 6, 7]
         4    - literal four
        +     - add (vectorises) -> [ 5, 6, 7, 8, 9,10,11]
          ×   - multiply by the argument -> ['ccccc','oooooo',...,'nnnnnnnnnnn']
           Ḥ  - multiply by 2 (vectorises) -> ['cccccccccc','oooooooooooo',...,'nnnnnnnnnnnnnnnnnnnnnn']
            Y - join with newline characters
              - implicit print
\$\endgroup\$
3
  • \$\begingroup\$ I guess there's no literal for 11 in Jelly? \$\endgroup\$
    – Jo King
    Oct 2, 2018 at 11:08
  • \$\begingroup\$ There is 11 :) \$\endgroup\$ Oct 2, 2018 at 11:10
  • \$\begingroup\$ ¢nṣkœ+¦s⁾ıß. Yes, mon is a word. \$\endgroup\$ Oct 2, 2018 at 15:36
1
\$\begingroup\$

J, 25 24 bytes

 echo'conemon'#"0~2*5+i.7

Try it online!

Note: There are trailing spaces on all lines except the last one.

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

C# (Visual C# Interactive Compiler) 65 64 bytes

for(int i=0;i<7;){WriteLine(new string("conemon"[i],i++*2+10));}

Try it online!

thanks to @Jonathan Frech saving 1 byte

new string(char, int) repeats the char as often as the int value.

C#, 72 bytes without "Console" as static using (example outside interactive compiler):

for(int i=0;i<7;){Console.WriteLine(new string("conemon"[i],i++*2+10));}
\$\endgroup\$
1
  • \$\begingroup\$ I think you can move your i++ into your i*2+10. \$\endgroup\$ Oct 2, 2018 at 16:22
1
\$\begingroup\$

Pyth, 17 16 bytes

V"conemon"*N~+T2

Try it online here.

V"conemon"*N~+T2   Implicit: T=10
V"conemon"         For each character in "conemon", as N:
          *N  T      Repeat N T times, implicit print with newline
            ~+T2     T += 2
\$\endgroup\$
1
\$\begingroup\$

SOGL V0.12, 13 bytes

╝⌠Ei№‘{ē«L+*P

Try it Here!

Explanation:

╝⌠Ei№‘       push "conemon" - 2 words "cone" and "mon" compressed
      {      for each
       ē       push the value of e (default 0), and increment it (aka e++)
        «      multiply that by 2
         L+    add 10 to that
           *   repeat the character that many times
            P  and print it
\$\endgroup\$

Your Answer

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

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