[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Challenge #295 [Easy] Letter by letter

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 22
Thread images: 2

File: 1495612204871.jpg (142KB, 1200x630px) Image search: [Google]
1495612204871.jpg
142KB, 1200x630px
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.
>>
>>60608060
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 <- [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
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;
>>
>>60608060
function 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
>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);
}
>>
>>60612892
shitcode/10
>>
>>60612952
Nope.
>>
File: 1495187431708.gif (5KB, 200x175px) Image search: [Google]
1495187431708.gif
5KB, 200x175px
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.
Thread posts: 22
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.