| Bytes | Lang | Time | Link |
|---|---|---|---|
| 100 | R | 240605T200701Z | int 21h |
| 091 | Java JDK | 180305T142633Z | Olivier |
| 072 | PowerShell | 190312T091650Z | mazzy |
| 062 | Ruby | 180305T151847Z | Asone Tu |
| 069 | Python 2 / 3 | 180305T170355Z | Asone Tu |
| 153 | Java | 180307T155532Z | Amir M |
| 025 | Husk | 180312T051211Z | Esolangi |
| 025 | CJam | 180311T173017Z | Esolangi |
| 030 | APL Dyalog Classic | 180310T150939Z | ngn |
| 033 | K oK | 180310T151707Z | ngn |
| 085 | PHP | 180307T224757Z | M4tini |
| 053 | Ruby | 180307T135909Z | Kirill L |
R, 100 bytes
\(S,`!`=utf8ToInt,x=diff(!S)-1)o=Map(\(j,k)cat(intToUtf8(c(rep(!"TAPE",6)[0:j],k))),c(0,x*(x>0)),!S)
This solution is based on the subtraction of two adjacent characters codes (diff). TAPE repeated 6 times gives 24 chars, which corresponds to the maximal distance - from \$A\$ to \$Z\$. This long vector is being subset each time to the appropriate length (from 0 to 24) and inserted between the pairs of letters.
Java (JDK), 91 bytes
s->{var p='z';for(var c:s)System.out.print("ETAP".repeat(9).substring(1,c>p?c-p:1)+(p=c));}
Explanation
s->{ // char[]-accepting lambda consumer, printing a String
var p='z'; // store the previous character
for(var c:s){ // for each character of the string
System.out.print( // print...
"ETAP".repeat(9) // "ETAP" repeated 9 times (to go above 26 chars)
.substring(1, // of which, we substring c-p -1 characters
c>p?c-p:1 //
) //
+(p=c) // and append c, while also storing the previous character
);
Credits
- -2 bytes thanks to R.M
- -4 bytes thanks to ceilingcat, by upgrading to Java 10+ and switching types to
var - -3 bytes thanks to Kevin Cruijssen, by printing the result of my (previously) alternate version instead of returning it
PowerShell, 72 bytes
-join($args|% t*y|%{for(;$p*(++$p-lt$_)){'TAPE'[$i++%4]}$i=0;$p=+$_;$_})
Ruby, 78 77 64 62 bytes
-1 byte thanks to Kevin Cruijssen
f=->s,*t{t[0]?s+('TAPE'*6)[0,[0,t[0].ord+~s.ord].max]+f[*t]:s}
Python 2 / 3, 70 69 bytes
f=lambda s,*t:t and s+('TAPE'*6)[:max(ord(t[0])+~ord(s),0)]+f(*t)or s
Java , 213 166 153 bytes
i->{String o="";for(int a=0,l=i.length;++a<=l;){char u=i[a-1],n;o+=u;if(a<l){n=i[a];o+="TAPETAPETAPETAPETAPETAPET".substring(0,n-u>0?n+~u:0);}}return o;}
String o = "";
for (int a = 0, l = i.length; ++a <= l; ) { // for each character
char u = i[a - 1]; // current character
o += u; // add current character to output string
if (a < l) { // if it's not the last one
char n = i[a]; // next character
o += "TAPETAPETAPETAPETAPETAPET".substring(0, n - u > 0 ? n +~ u : 0); // fill with enough tape but only forward
}
}
return o;
Please help me make it better.
Thanks to @cairdcoinheringaahing for the tip on whitespaces. Thanks to @R.M for the tip on tape string. Thanks to @KevinCruijssen for the lambda and expressions tips.
CJam, 27 25 bytes
q_:i2ew.{:-~0e>_"TAPE"*<}
Far, far from the other golfing languages, but I'm proud of this golf anyway.
Explanation
q Read the input
ew And take windows of size
2 2
i from the code points
: of each of its characters.
{ } For each of these windows:
: Reduce with
- subtraction.
Since there are only 2 elements, this just subtracts them.
e> Take the maximum
~ of this difference's bitwise negation
0 and zero.
This returns -n-1 if n is negative, and 0 otherwise.
Call this new value m.
* Repeat
"TAPE" the string "TAPE" m times.
_ < And then take the first m elements.
The result of this will be an array of strings which consist of
the string "TAPE" repeated the proper amount of times.
. Zip this array with the original input.
Since the original input is one element longer than this array,
the nothing is pushed after the final character.
Implicitly print everything.
APL (Dyalog Classic), 30 bytes
{∊⍵,¨⍨⍴∘'TAPE'¨0,0⌈-1+2-/⎕a⍳⍵}
{ } anonymous function with argument ⍵
⎕a⍳⍵ find indices of its chars in the alphabet
2-/ pairwise differences (prev minus next)
1+ add 1
- negate
0⌈ max(0, ...)
0, prepend a 0
⍴∘'TAPE'¨ reshape cyclically the string 'TAPE' to each
⍵,¨⍨ append each char from the argument to the corresponding reshaped string
∊ flatten
K (oK), 33 bytes
{,/((0|-1+0,1_-':x)#\:"TAPE"),'x}
{ } anonymous function with argument x
-':x subtract each prior (use an imaginary 0 before the first item)
1_ drop first item
0, prepend a 0
-1+ add -1
0| max(0, ...)
(...)#\:"TAPE" reshape the string "TAPE" to each item from the list on the left
(...),'x append the corresponding character from x to each reshaped string
,/ concatenate all
PHP, 85 bytes
$s=str_split($argv[1]);foreach($s as$l)echo str_pad($l,ord(next($s))-ord($l),'TAPE');
Explanation
$s = str_split($argv[1]); // convert the parameter string to an array
foreach($s as $l) // loop the array
echo str_pad( // print
$l, // the letter
ord(next($s)) - ord($l), // calculate the distance to the next letter using ASCII values
'TAPE' // padding string
); // profit!
Ruby, 59 53 bytes
->s{s.reduce{|x,y|x+y.rjust(y.ord-x[-1].ord,"TAPE")}}
This is actually pretty straightforward - we take input as split our string into an array of chars (thanks to Asone Tuhid for pointing this out) and apply reduce operation, where we justify each char to the required length using "TAPE" as filler string.