1, 2, 3, 4, 5, Shaggy
Python 2, 64 63 bytes
Anonymous function with arguments n
and k
, returns the list to output.
lambda n,k:[[i,'Shaggy'][i%k<1or`k`in`i`]for i in range(1,n+1)]
Alternatively, a function which prints to STDOUT
for the same bytecount:
def f(n,k,i=1):exec"print[i,'Shaggy'][i%k<1or`k`in`i`];i+=1;"*n
Pyth, 25 23 bytes
m?|!%dQ}`Q`d"Shaggy"dSE
A program that takes input of two newline-separated integers k, n
and prints a list.
Try it online!
How it works
m?|!%dQ}`Q`d"Shaggy"dSE Program. Inputs: Q, E
m SE Map over [1, 2, 3, 4, ..., E] with varaible d:
? If
%dQ d % Q
! negated is truthy (divisible by H)
| or
`Q str(Q)
} is in
`d str(d):
"Shaggy" Yield "Shaggy"
Else:
d Yield d
Implicitly print
SQL (PostgreSQL flavour), 130 136 bytes
Done as a prepared statement:
prepare p(int,int)as select CASE WHEN i%$2=0or i::char like'%'||$2||'%'THEN'Shaggy'else i::char end from generate_series(1,$1)a(i)
This is executed in the following manner
execute p(20,6)
and the result is output as rows.