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.
>>60608060string 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 stabs1, 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 <- [0..length to-1]]
solution from to = putStrLn $ unlines $ unique $ tran from to
could be better :/
cd ..
cd code
ls
cd ../code
cd ../..
cd code
>>60608060
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.
>>60608060
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.
>>60609707
Audible laughter
>>60608060#include <stdio.h>
#include <string.h>
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;
}
>>60608060
yaaawnwith 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;
>>60608060function s(a,b)for i=0,#a,1 do print(b:sub(1,i)..a:sub(i+1))end end
Lua.
>>60608060<html>
<script>
function changeAndPrintSentenceLetterByLetter(s1, s2){
if(s1 != null && s2 != null && s1.length == s2.length){
var s3 = '';
document.write(s1 + '<br/>');
for(var i = 0; i < s1.length; i++){
s3 = s2.substring(0, i + 1) + s1.substring(i + 1, s1.length);
document.write(s3 + '<br/>');
}
}
}
changeAndPrintSentenceLetterByLetter('a fall to the floor','braking the door in');
</script>
</html>
#include <stdio.h>
#include <string.h>
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]
>>60612551
>>60608122
What's with this stupid if statement check?
>>60612606
Look at the wood book case retard. You don't print anything if the characters are the same.
>>60612644
>Retard
Why so mad?
>>60608060
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
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);
}
>>60612892
shitcode/10
>>60612952
Nope.
I like life on the edge.#include <stdio.h>
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;
}
>>60612970
Yes.