5
\$\begingroup\$

Your task is to make a program in L that takes n as an input number, output a program p in L that prints its own first n characters.

Rules

  • The program p has to be irreducible, See an example below.

  • PAY ATTENTION TO THIS RULE: If a program takes an input as n, the first n characters of the output would be the same as the first n characters of the program taking n + 1 as input.

  • Standard loopholes apply

  • You have to make a full program.

  • A trailing newline of the output of the program p is allowed if the first n characters of the program p doesn't have a newline

Example

I'm using pseudocode as L

if n = 10, an example of p would be

PRINT "PRINT \"PRI"

but not

// comment
PRINT "// comment"

because it breaks the first rule above (if you removed com and still makes the same output).

This is , so you have to make your program shortest as possible (in bytes).

\$\endgroup\$
0

10 Answers 10

7
\$\begingroup\$

Charcoal, 1 byte

Try it online! Port of @Ausername's Vyxal answer. Explanation: Simply outputs n -s; strings of printable ASCII need no delimiter in Charcoal, so as a program, it just prints the string of -s, i.e. itself.

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

Raku, 20 18 bytes

say 1 x get,".put"

Try it online!

Outputs a number with n digits followed by a .put

\$\endgroup\$
4
\$\begingroup\$

Python 3, 48 bytes

print('a'*int(input())+'=1;print(locals()[-1])')

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ locals() is a dict, so this gives a KeyError. Perhaps print([*locals()][-1]) would be better. \$\endgroup\$ Dec 12, 2022 at 4:13
3
\$\begingroup\$

Vyxal, 3 bytes

\1*

Try it Online! Literally prints that many 1s.

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

Ruby, 26 bytes

$><<?1*gets.to_i+'=>x;p x'

Uses the Ruby 3 pattern match syntax to bind the integer to x.

Attempt This Online!

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

Retina, 13 bytes

.+
*KKK
KK
K`

Try it online! Explanation: Outputs a string of length n+2 alternating between K and `. This creates a program in Retina that outputs the part of the string after the K` which is also equal to the first n characters of the program. Retina can also execute the resulting program for you automatically: Try it online! Or see both the program and its output: Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ I don't think the resulting program is irreducable, since you can just delete the leading _ with the same output \$\endgroup\$
    – Sisyphus
    Dec 8, 2022 at 1:38
  • \$\begingroup\$ @Sisyphus Thanks, I've come up with a new approach now. \$\endgroup\$
    – Neil
    Dec 8, 2022 at 9:56
1
\$\begingroup\$

05AB1E, 5 bytes

1¸sиJ

Try it online!

Sort-of port of emanresu A's Vyxal answer:

1¸sиJ  # Implicit input                 STACK:
1¸     # Push ['1']                     ['1'], 5
  sи   # Repeat input number of times   ['1', '1', '1', '1', '1']
    J  # Join by ''                     '11111'
       # Implicit output
\$\endgroup\$
0
\$\begingroup\$

Julia 1.0, 36 bytes

print('1'^parse(Int,ARGS[]),|>,show)

Try it online!

port of Jo King's answer

will print something like 1111|>show (equivalent to show(1111))

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

///, 65 bytes

/9/8*//8/7*//7/6*//6/5*//5/4*//4/3*//3/2*//2/1*//1/0*//*0/9*//0//

Try it online!

Converts decimal to unary.

///, 0 bytes

Try it online!

Takes input as unary. For me, That's cheating.

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

Bash, 25 bytes

eval echo\ echo\$_{0..$1}

Attempt This Online!

\$\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.