21
\$\begingroup\$

You should write a program or function that receives a positive integer N as input and prints out the first N characters of your code. If N is larger than the length of your code you should continue output your code cyclically.

Reading your source code in any way and reading from file, stdio, etc. are disallowed.

Examples

(assuming your code is yourcode)

Input => Output:

5 => yourc
10 => yourcodeyo
22 => yourcodeyourcodeyour

Clarification

Your program should be at least 1 byte long.

\$\endgroup\$
  • 15
    \$\begingroup\$ Congratulations on posting the 2000th code golf challenge! :) \$\endgroup\$ – Martin Ender Jan 25 '15 at 12:55
  • 3
    \$\begingroup\$ Douglas Hofstadter would love this! \$\endgroup\$ – Luis Mendo Jan 25 '15 at 17:51
  • 1
    \$\begingroup\$ @MartinBüttner Actually, there are over 300 deleted [code-golf] questions. But close enough ;) \$\endgroup\$ – Doorknob Jan 26 '15 at 2:57
  • 11
    \$\begingroup\$ @MartinBüttner Thank you. Only 48 to go until a round number! \$\endgroup\$ – randomra Jan 26 '15 at 9:29
  • 5
    \$\begingroup\$ Maybe it's time you mentioned explicitly that empty programs are invalid? \$\endgroup\$ – Martin Ender Jan 26 '15 at 20:42

32 Answers 32

0
\$\begingroup\$

05AB1E, 17 bytes

0"D34çýI∍"D34çýI∍

Try it online.

Explanation:

0                    # Push a 0 to the stack
                     #  STACK: [0]
 "D34çýI∍"           # Push the string 'D34çýI∍' to the stack
                     #  STACK: [0, 'D34çýI∍']
          D          # Duplicate this string
                     #  STACK: [0, 'D34çýI∍', 'D34çýI∍']
           34çý      # Join the entire stack by the character '"'
                     #  STACK: ['0"D34çýI∍"D34çýI∍']
               I     # Take the input
                ∍    # Shorten/lenghten the string to that size (and output implicitly)
                     #  i.e. 3 → '0"D'
                     #  i.e. 25 → '0"D34çýI∍"D34çýI∍0"D34çýI'
\$\endgroup\$
-1
\$\begingroup\$

Tcl, 31 bytes

puts [read [open $argv0] $argv]

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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