Challenge #295 [Easy] Letter by letter

This is a programming challenge that was posted to /r/dailyprogrammer. It received over 200 comments and solutions in languages such as Python, Java, C#, Haskell, Scheme, and DOS assembly.

>Change a sentence to another sentence, letter by letter.
>The sentences will always have the same length.

Sample input:
floor
brake
Sample output:
floor
bloor
broor
braor
brakr
brake

Sample input:
wood
book
Sample output:
wood
bood
book

Sample input:
a fall to the floor
braking the door in
Sample output:
a fall to the floor
b fall to the floor
brfall to the floor
braall to the floor
brakll to the floor
brakil to the floor
brakin to the floor
brakingto the floor
braking o the floor
braking t the floor
braking ththe floor
braking thehe floor
braking the e floor
braking the d floor
braking the dofloor
braking the dooloor
braking the dooroor
braking the door or
braking the door ir
braking the door in


You should be able to solve this, or this crow will stab you.

string a, b;
if len(a) = len(b) then
print a;
for i = 0 to (len(a)-1) do
if a[i] = b[i] continue;
a[i] = b[i];
print a;
next;
end if

I don't care whether it's some existing language, but I'd have a good laugh if the language I wrote exists.

pls dont stab
s1, s2 = input(), input()
for i, (a, b) in enumerate(zip(s1, s2)):
if a != b:
print(s2[:i] + s1[i:])
print(s2)

replace a n c = take n a ++ c ++ drop n (tail a)
unique x = foldr (\a y -> if a == head y then y else a:y) [last x] x
tran from to = from:[replace (tran from to !! x) x [to !! x] | x

cd ..
cd code
ls
cd ../code
cd ../..
cd code

JavaScript:

(a,b)=>[...a.split('').map((c,i)=>c==b[i]?0:b.substr(0,i)+a.substring(i)).filter(s=>s),b]


Problem is, I'm not that great at code golf.

I was confused by the question and thought we weren't given the second line. I was about to kill myself since it was considered easy.

Audible laughter

#include
#include

int main(void) {
const char *str1 = "KEK", *str2 = "MOOT";
int i = strlen(str1), j = 0;
puts (str1);

while((j = printf ("%.*s", ++j, str2)) < i)
printf ("%s\n", (str1+j));
puts ("");
return 0;
}

yaaawn
with Ada.Text_IO; use Ada.Text_IO;

procedure Str is
Original : String := Get_Line;
Converted : String := Get_Line;

begin -- Str

pragma Assert (Original'length = Converted'length);

for I in Original'first .. Original'last + 1 loop
Put_Line (Converted(Converted'first .. I - 1) & Original(I .. Original'Last));
end loop;

end Str;

function s(a,b)for i=0,#a,1 do print(b:sub(1,i)..a:sub(i+1))end end

Lua.

function changeAndPrintSentenceLetterByLetter(s1, s2){

if(s1 != null && s2 != null && s1.length == s2.length){

var s3 = '';
document.write(s1 + '');
for(var i = 0; i < s1.length; i++){
s3 = s2.substring(0, i + 1) + s1.substring(i + 1, s1.length);
document.write(s3 + '');
}
}
}

changeAndPrintSentenceLetterByLetter('a fall to the floor','braking the door in');

#include
#include

int main (int argc, char** argv)
{
unsigned int length, i;

if (argc < 3)
{
printf("Invalid number of arguments");
return 1;
}

if ((length = strlen (argv[1])) != strlen (argv[2]))
{
printf("Invalid input, arguments must be the same length");
return 1;
}

printf("%s\n", argv[1]);
for (i = 0; i < length; ++i)
{
if (argv[1][i] == argv[2][i])
{
continue;
}

argv[1][i] = argv[2][i];
printf("%s\n", argv[1]);
}

return 0;
}
[\code]

What's with this stupid if statement check?

Look at the wood book case retard. You don't print anything if the characters are the same.

>Retard
Why so mad?

What, you're allowed to have gibberish? Forget that.


>receive sentence
>count number of characters in sentence
>go to your database of sentences
>find one with the same number of characters
>print

t. newfriend

void change(char *a, char *b)
{
char *p=a;
int f;
do {
puts(a);
while(*p && *p==*b) ++p, ++b;
if(f=*p) *p=*b;
} while(f);
}

shitcode/10

Nope.

I like life on the edge.

#include

int main(void)
{
char line[1000];

int i;
for (i = 0; (line[i] = getchar()) != '\n'; ++i);

for (i = 0; (line[i] = getchar()) != '\n'; ++i)
printf ("%s", line);

return 0;
}

Yes.