r/badcode • • Aug 21 '20

python Fucking legend (codewars)

Post image
774 Upvotes

67 comments sorted by

165

u/lerg1 Aug 21 '20

Waiting for image transcription :)

107

u/ConzT Aug 21 '20

I think even bots are too lazy to read that

57

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20

There is a bot that tries to help transcribe text posts, but it couldn't read this properly; it was all broken. Luckily, most of this is repeated code which made transcribing it easier. If it were all unique I might have gone insane.

I still had to post it across 4 comments, though.

11

u/ConzT Aug 21 '20

Dude you are crazy, I guess you had a lot of practice copying homework in school? (not judging you, I'm speaking from experience)

13

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20

Not homework, but I do have a lot of practice typing while reading and that sort of thing. We used to get a lot of code on paper, back in Computing class, which we'd then have to copy into repl.it, so I can type pretty quickly. This still took an hour, though; the main reason I was able to do it was because I had nothing better to do.

89

u/DoomSlayer_C137 Aug 21 '20

But why?

120

u/MeDotPy Aug 21 '20

To flex coding skills by making a code that generates this I guess, if it wasn't auto-generated then probably they just like to suffer

28

u/[deleted] Aug 21 '20

Still don't like the final result, I would prefer something like:

def format_duration(seconds):
	if not seconds:
		return 'now'
	times = ((1, 'second'), (60, 'minute'), (3600, 'hour'), (86400, 'day'), (31536000, 'year'))
	final = []
	for duration, name in reversed(times):
		time = seconds // duration
		if time:
			seconds %= duration
			final.append(f'{time} {name}{"s" if time > 0 else ""}')
	return ' and '.join(final).replace(' and ', ', ', len(final) - 2)

2

u/MeDotPy Aug 21 '20

Wow, that's something I forgot, nice use of the pythonic methods!

10

u/ArkWaltz Aug 21 '20

Wow, learned something new. Had no idea Python had a dedicated floor division operator.

6

u/Gillemonger Aug 21 '20

Theres also the divmod function which does both modulus and integer divison (would've saved you 1 line).

3

u/LeeHide Aug 21 '20

its better to have readable, easy understood code, than "less lines"

5

u/Gillemonger Aug 21 '20

I agree. But to be fair, the divmod function is a built-in function in Python that has existed as far back version 1.4 (1996) so would argue that its use falls into that category.

68

u/JasperP5 Aug 21 '20

welcome to yandere sim 2.0

27

u/MeDotPy Aug 21 '20

This is something he would literally do, char by char

18

u/MisterPyromaniac shameless Aug 21 '20

My God, what is that?

35

u/MeDotPy Aug 21 '20

A program that tells the time with input in seconds as "days, hours, minutes and seconds" without those that are 0. Since it has commas and 'and' you have to put those somehow in the returned string.

Ex: 3727 -> '1 hour, 2 minutes and 7 seconds'

2

u/Jo-C23 Aug 21 '20

What color scheme and font is this?

2

u/MeDotPy Aug 21 '20

The color scheme is the same as it appears in codewars for Python, and the font is Monofonto, I like that one a lot.

135

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20 edited Aug 21 '20

Image Transcription: Code


[There are two sections of code in the post by user karthikbhoshale. The first contains the following code:]

def format_duration(seconds):
    if seconds==0:
        return "now"
    #if seconds ==132375840:
        #return '4 years, 68 days, 3 hours and 4 minutes'
    minu, sec = divmod(seconds, 60)
    hour, minu = divmod(minu, 60)
    day,hour=divmod(hour,24)
    year,day=divmod(day,365)
    if year==0:
        if day==0:
            if hour==0:
                if minu==0:
                    if sec==1:
                        return str(sec)+' second'
                    return str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(minu)+' minute'
                    if sec==1:
                        return str(minu)+' minute and '+str(sec)+' second'
                    return str(minu)+' minute and '+str(sec)+' seconds'
                if minu>1:
                    if sec==0:
                        return str(minu)+' minutes'
                    if sec==1:
                        return str(minu)+' minute and '+str(sec)+' second'
                    return str(minu)+' minute and '+str(sec)+' seconds'

            if hour==1:
                if minu==0:
                    if sec==0:
                        return str(hour)+' hour'

                    if sec==1:
                        return str(hour)+' hour and '+str(sec)+' second'
                    return str(hour)+' hour and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(hour)+' hour, '+str(minu)+' minute'

                    if sec==1:
                        return str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                    return str(hour)+' hour, '+str(minu)+' minutes'

                if sec==1:
                    return str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds'
            if hour>1:
                if minu==0:
                    if sec==0:
                        return str(hour)+' hours'

                    if sec==1:
                        return str(hour)+' hours and '+str(sec)+' second'
                    return str(hour)+' hours and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(hour)+' hours, '+str(minu)+' minute'

                    if sec==1:
                        return str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                    return str(hour)+' hours, '+str(minu)+' minutes'

                if sec==1:
                    return str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds'

        if day==1:
            if hour==0:
                if minu==0:
                    if sec==0:
                        return str(day)+' day'
                    if sec==1:
                        return str(day)+' day and '+str(sec)+' second'
                    return str(day)+' day and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(day)+' day and '+str(minu)+' minute'
                    if sec==1:
                        return str(day)+' day, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(day)+' day, '+str(minu)+' minute and '+str(sec)+' seconds'
                if minu>1:
                    if sec==0:
                        return str(day)+' day and '+str(minu)+' minutes'
                    if sec==1:
                        return str(day)+' day, '+str(minu)+' minutes and '+str(sec)+' second'
                    return str(day)+' day, '+str(minu)+' minutes and '+str(sec)+' seconds'
            
            if hour==1:
                if minu==0:
                    if sec==0:
                        return str(day)+' day and '+str(hour)+' hour and '+str(sec)
                    
                    if sec==1:
                        return str(day)+' day, '+str(hour)+' hour and '+str(sec)+' second'
                    return str(day)+' day, '+str(hour)+' hour and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute'
                    
                    if sec==1:
                        return str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                    return str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes'
                    
                if sec==1:
                    return str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds'
            if hour>1:
                if minu==0:
                    if sec==0:
                        return str(day)+' day and '+str(hour)+' hours'
                    
                    if sec==1:
                        return str(day)+' day, '+str(hour)+' hours and '+str(sec)+' second'
                    return str(day)+' day, '+str(hour)+' hours and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute'
                    
                    if sec==1:
                        return str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                    return str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes'
                    
                if sec==1:
                    return str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds'
        if day>1:
            if hour==0:
                if minu==0:
                    if sec==0:
                        return str(day)+' days'
                    if sec==1:
                        return str(day)+' days and '+str(sec)+' second'
                    return str(day)+' day and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(day)+' days and '+str(minu)+' minute'
                    if sec==1:
                        return str(day)+' days, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(day)+' days, '+str(minu)+' minute and '+str(sec)+' seconds'
                if minu>1:
                    if sec==0:
                        return str(day)+' days and '+str(minu)+' minutes'
                    if sec==1:
                        return str(day)+' days, '+str(minu)+' minutes and '+str(sec)+' second'
                    return str(day)+' days, '+str(minu)+' minutes and '+str(sec)+' seconds'
            
            if hour==1:
                if minu==0:
                    if sec==0:
                        return str(day)+' days and '+str(hour)+' hour and '+str(sec)
                    
                    if sec==1:
                        return str(day)+' days, '+str(hour)+' hour and '+str(sec)+' second'
                    return str(day)+' days, '+str(hour)+' hour and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute'
                    
                    if sec==1:
                        return str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                    return str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes'
                    
                if sec==1:
                    return str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds'

91

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20 edited Aug 22 '20
            if hour>1:
                if minu==0:
                    if sec==0:
                        return str(day)+' days and '+str(hour)+' hours'
                    
                    if sec==1:
                        return str(day)+' days, '+str(hour)+' hours and '+str(sec)+' second'
                    return str(day)+' days, '+str(hour)+' hours and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute'
                    
                    if sec==1:
                        return str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                    return str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes'
                    
                if sec==1:
                    return str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds'
    if year==1:
        if day==0:
            if hour==0:
                if minu==0:
                    if sec==0:
                        return str(year)+' year'
                    if sec==1:
                        return str(year)+' year and '+str(sec)+' second'
                    return str(year)+' year and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' year and '+str(minu)+' minute'
                    if sec==1:
                        return str(year)+' year, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' year, '+str(minu)+' minute and '+str(sec)+' seconds'
                if minu>1:
                    if sec==0:
                        return str(year)+' year and '+str(minu)+' minutes'
                    if sec==1:
                        return str(year)+' year, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' year, '+str(minu)+' minute and '+str(sec)+' seconds'

            if hour==1:
                if minu==0:
                    if sec==0:
                        str(year)+' year and '+str(hour)+' hour'

                    if sec==1:
                        return str(year)+' year, '+str(hour)+' hour and '+str(sec)+' second'
                    return str(year)+' year, '+str(hour)+' hour and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' year, '+str(hour)+' hour, '+str(minu)+' minute'

                    if sec==1:
                        return str(year)+' year, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                    return str(year)+' year, '+str(hour)+' hour, '+str(minu)+' minutes'

                if sec==1:
                    return str(year)+' year, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(year)+' year, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds'
            if hour>1:
                if minu==0:
                    if sec==0:
                        str(year)+' year and '+str(hour)+' hours'

                    if sec==1:
                        return str(year)+' year, '+str(hour)+' hours and '+str(sec)+' second'
                    return str(year)+' year, '+str(hour)+' hours and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' year, '+str(hour)+' hours, '+str(minu)+' minute'

                    if sec==1:
                        return str(year)+' year, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' year, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                    return str(year)+' year, '+str(hour)+' hours, '+str(minu)+' minutes'

                if sec==1:
                    return str(year)+' year, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(year)+' year, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds'

        if day==1:
            if hour==0:
                if minu==0:
                    if sec==0:
                        return str(year)+' year and '+str(day)+' day'
                    if sec==1:
                        return str(year)+' year, '+str(day)+' day and '+str(sec)+' second'
                    return str(year)+' year, '+str(day)+' day and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' year, '+str(day)+' day and '+str(minu)+' minute'
                    if sec==1:
                        return str(year)+' year, '+str(day)+' day, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' year, '+str(day)+' day, '+str(minu)+' minute and '+str(sec)+' seconds'
                if minu>1:
                    if sec==0:
                        return str(year)+' year, '+str(day)+' day and '+str(minu)+' minutes'
                    if sec==1:
                        return str(year)+' year, '+str(day)+' day, '+str(minu)+' minutes and '+str(sec)+' second'
                    return str(year)+' year, '+str(day)+' day, '+str(minu)+' minutes and '+str(sec)+' seconds'
            
            if hour==1:
                if minu==0:
                    if sec==0:
                        return str(year)+' year, '+str(day)+' day and '+str(hour)+' hour and '+str(sec)
                    
                    if sec==1:
                        return str(year)+' year, '+str(day)+' day, '+str(hour)+' hour and '+str(sec)+' second'
                    return str(year)+' year, '+str(day)+' day, '+str(hour)+' hour and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' year, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute'
                    
                    if sec==1:
                        return str(year)+' year, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' year, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                    return str(year)+' year, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes'
                    
                if sec==1:
                    return str(year)+' year, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(year)+' year, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds'
            if hour>1:
                if minu==0:
                    if sec==0:
                        return str(year)+' year, '+str(day)+' day and '+str(hour)+' hours and '+str(sec)
                    
                    if sec==1:
                        return str(year)+' year, '+str(day)+' day, '+str(hour)+' hours and '+str(sec)+' second'
                    return str(year)+' year, '+str(day)+' day, '+str(hour)+' hours and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' year, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute'
                    
                    if sec==1:
                        return str(year)+' year, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' year, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                    return str(year)+' year, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes'
                    
                if sec==1:
                    return str(year)+' year, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(year)+' year, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds'

85

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20 edited Aug 21 '20
        if day>1:
            if hour==0:
                if minu==0:
                    if sec==0:
                        return str(year)+' year, and '+str(day)+' days'
                    if sec==1:
                        return str(year)+' year, '+str(day)+' days and '+str(sec)+' second'
                    return str(year)+' year, '+str(day)+' day and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' year, '+str(day)+' days and '+str(minu)+' minute'
                    if sec==1:
                        return str(year)+' year, '+str(day)+' days, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' year, '+str(day)+' days, '+str(minu)+' minute and '+str(sec)+' seconds'
                if minu>1:
                    if sec==0:
                        return str(year)+' year, '+str(day)+' days and '+str(minu)+' minutes'
                    if sec==1:
                        return str(year)+' year, '+str(day)+' days, '+str(minu)+' minutes and '+str(sec)+' second'
                    return str(year)+' year, '+str(day)+' days, '+str(minu)+' minutes and '+str(sec)+' seconds'
            
            if hour==1:
                if minu==0:
                    if sec==0:
                        return str(year)+' year, '+str(day)+' days and '+str(hour)+' hour and '+str(sec)
                    
                    if sec==1:
                        return str(year)+' year, '+str(day)+' days, '+str(hour)+' hour and '+str(sec)+' second'
                    return str(year)+' year, '+str(day)+' days, '+str(hour)+' hour and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' year, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute'
                    
                    if sec==1:
                        return str(year)+' year, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' year, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                    return str(year)+' year, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes'
                    
                if sec==1:
                    return str(year)+' year, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(year)+' year, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds'
            if hour>1:
                if minu==0:
                    if sec==0:
                        return str(year)+' year, '+str(day)+' days and '+str(hour)+' hours'
                    
                    if sec==1:
                        return str(year)+' year, '+str(day)+' days, '+str(hour)+' hours and '+str(sec)+' second'
                    return str(year)+' year, '+str(day)+' days, '+str(hour)+' hours and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' year, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute'
                    
                    if sec==1:
                        return str(year)+' year, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' year, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                    return str(year)+' year, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes'
                    
                if sec==1:
                    return str(year)+' year, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(year)+' year, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds'
    if year>1:
        if day==0:
            if hour==0:
                if minu==0:
                    if sec==0:
                        return str(year)+' years'
                    if sec==1:
                        return str(year)+' years and '+str(sec)+' second'
                    return str(year)+' years and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' years and '+str(minu)+' minute'
                    if sec==1:
                        return str(year)+' years, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' years, '+str(minu)+' minute and '+str(sec)+' seconds'
                if minu>1:
                    if sec==0:
                        return str(year)+' years and '+str(minu)+' minutes'
                    if sec==1:
                        return str(year)+' years, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' years, '+str(minu)+' minute and '+str(sec)+' seconds'

            if hour==1:
                if minu==0:
                    if sec==0:
                        str(year)+' years and '+return str(hour)+' hour'

                    if sec==1:
                        return str(year)+' years, '+str(hour)+' hour and '+str(sec)+' second'
                    return str(year)+' years, '+str(hour)+' hour and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' years, '+str(hour)+' hour, '+str(minu)+' minute'

                    if sec==1:
                        return str(year)+' years, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                        return str(year)+' years, '+str(hour)+' hour, '+str(minu)+' minutes'

                if sec==1:
                    return str(year)+' years, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(year)+' years, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds'
            if hour>1:
                if minu==0:
                    if sec==0:
                        str(year)+' years and '+return str(hour)+' hours'

                    if sec==1:
                        return str(year)+' years, '+str(hour)+' hours and '+str(sec)+' second'
                    return str(year)+' years, '+str(hour)+' hours and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' years, '+str(hour)+' hours, '+str(minu)+' minute'

                    if sec==1:
                        return str(year)+' years, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' years, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                        return str(year)+' years, '+str(hour)+' hours, '+str(minu)+' minutes'

                if sec==1:
                    return str(year)+' years, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(year)+' years, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds'

        if day==1:
            if hour==0:
                if minu==0:
                    if sec==0:
                        return str(year)+' years and '+str(day)+' day'
                    if sec==1:
                        return str(year)+' years, '+str(day)+' day and '+str(sec)+' second'
                    return str(year)+' years, '+str(day)+' day and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' years, '+str(day)+' day and '+str(minu)+' minute'
                    if sec==1:
                        return str(year)+' years, '+str(day)+' day, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' years, '+str(day)+' day, '+str(minu)+' minute and '+str(sec)+' seconds'
                if minu>1:
                    if sec==0:
                        return str(year)+' years, '+str(day)+' day and '+str(minu)+' minutes'
                    if sec==1:
                        return str(year)+' years, '+str(day)+' day, '+str(minu)+' minutes and '+str(sec)+' second'
                    return str(year)+' years, '+str(day)+' day, '+str(minu)+' minutes and '+str(sec)+' seconds'

138

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20 edited Aug 21 '20
            if hour==1:
                if minu==0:
                    if sec==0:
                        return str(year)+' years, '+str(day)+' day and '+str(hour)+' hour and '+str(sec)
                    
                    if sec==1:
                        return str(year)+' years, '+str(day)+' day, '+str(hour)+' hour and '+str(sec)+' second'
                    return str(year)+' years, '+str(day)+' day, '+str(hour)+' hour and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' years, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute'
                    
                    if sec==1:
                        return str(year)+' years, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' years, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                        return str(year)+' years, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes'
                    
                if sec==1:
                    return str(year)+' years, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(year)+' years, '+str(day)+' day, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds'
            if hour>1:
                if minu==0:
                    if sec==0:
                        return str(year)+' years, '+str(day)+' day and '+str(hour)+' hours and '+str(sec)
                    
                    if sec==1:
                        return str(year)+' years, '+str(day)+' day, '+str(hour)+' hours and '+str(sec)+' second'
                    return str(year)+' years, '+str(day)+' day, '+str(hour)+' hours and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' years, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute'
                    
                    if sec==1:
                        return str(year)+' years, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' years, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                        return str(year)+' years, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes'
                    
                if sec==1:
                    return str(year)+' years, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(year)+' years, '+str(day)+' day, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds'
        if day>1:
            if hour==0:
                if minu==0:
                    if sec==0:
                        return str(year)+' years, and '+str(day)+' days'
                    if sec==1:
                        return str(year)+' years, '+str(day)+' days and '+str(sec)+' second'
                    return str(year)+' years, '+str(day)+' day and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' years, '+str(day)+' days and '+str(minu)+' minute'
                    if sec==1:
                        return str(year)+' years, '+str(day)+' days, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' years, '+str(day)+' days, '+str(minu)+' minute and '+str(sec)+' seconds'
                if minu>1:
                    if sec==0:
                        return str(year)+' years, '+str(day)+' days and '+str(minu)+' minutes'
                    if sec==1:
                        return str(year)+' years, '+str(day)+' days, '+str(minu)+' minutes and '+str(sec)+' second'
                    return str(year)+' years, '+str(day)+' days, '+str(minu)+' minutes and '+str(sec)+' seconds'
            
            if hour==1:
                if minu==0:
                    if sec==0:
                        return str(year)+' years, '+str(day)+' days and '+str(hour)+' hour and '+str(sec)
                    
                    if sec==1:
                        return str(year)+' years, '+str(day)+' days, '+str(hour)+' hour and '+str(sec)+' second'
                    return str(year)+' years, '+str(day)+' days, '+str(hour)+' hour and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' years, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute'
                    
                    if sec==1:
                        return str(year)+' years, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' years, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                        return str(year)+' years, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes'
                    
                if sec==1:
                    return str(year)+' years, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(year)+' years, '+str(day)+' days, '+str(hour)+' hour, '+str(minu)+' minutes and '+str(sec)+' seconds'
            if hour>1:
                if minu==0:
                    if sec==0:
                        return str(year)+' years, '+str(day)+' days and '+str(hour)+' hours'
                    
                    if sec==1:
                        return str(year)+' years, '+str(day)+' days, '+str(hour)+' hours and '+str(sec)+' second'
                    return str(year)+' years, '+str(day)+' days, '+str(hour)+' hours and '+str(sec)+' seconds'
                if minu==1:
                    if sec==0:
                        return str(year)+' years, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute'
                    
                    if sec==1:
                        return str(year)+' years, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' second'
                    return str(year)+' years, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minute and '+str(sec)+' seconds'
                if sec==0:
                        return str(year)+' years, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes'
                    
                if sec==1:
                    return str(year)+' years, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' second'
                return str(year)+' years, '+str(day)+' days, '+str(hour)+' hours, '+str(minu)+' minutes and '+str(sec)+' seconds'

[The second section contains the following code:]

def format_duration (seconds):
    if seconds:
        times = (1, 60, 3600, 86400, 31536000), ('second', 'minute', 'hour', 'day', 'year')
        final = []
        for i in (4, 3, 2, 1, 0):
            time = seconds // times [0] [i]
            if time:
                seconds %= times [0] [i]
                final.append (str (time) + ' ' + times [1] [i] + ('s' if time - 1 else ''))
        return ' and '.join (final).replace (' and ', ', ', len (final) - 2)
    return 'now'

[Beneath the post is a comment]

Nova-Striker: We got out yanderdev


I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

94

u/[deleted] Aug 21 '20

That's some dedication

96

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20

Haha, thanks. Fortunately, most of it's repeated code I can copy-paste then adjust (if it were all unique I'd have lost the will to live). Still took an hour, but I think it was well spent.

23

u/drdrero Aug 21 '20

and i thought you are a bot

20

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20

I wish; then I wouldn't get tired. Unfortunately, we don't currently have the technology for bots to successfully transcribe. We have one in training but its attempt at this post was totally broken.

7

u/MaddyBeCheesy Aug 21 '20

This is really cool what you did here, is there any way we could get ahold of this code without copying from each comment individually? Many thanks

7

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20

This comment has a link in it, but I think you need a codewars account. Otherwise, I don't know of any other way without going from each comment as you said.

→ More replies (0)

6

u/itsTyrion Aug 21 '20

You have 2 misplaced `return`s mid-line and your replace function also replaced `str(year)` with `str(years)`
Yes, I'm going to be THAT guy

5

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 21 '20

You're not being "that guy", you're being helpful! We want the transcriptions to be as accurate as possible, after all.

I've changed the str(years) back to str(year)'s (can't believe I missed that on my proof-read, but hey, when your eyes are tired...), and I think I've corrected the misplaced returns as well? I noticed quite a few actually, certainly more than 2, that had been indented more than they should've been. If those weren't the ones you meant, please say.

5

u/itsTyrion Aug 21 '20 edited Aug 21 '20

I only noticed after pasting it into VS Code to see if this even works^

Please tell me you didn't look through this monstrosity by hand but used something with error checking? D:

Oh and the indentation looked fine to me, there were to mid line between a plus and str() call. Example, there were 4

Error checked/tested there you go.

2

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 22 '20

Ah, thank you! They should be fixed now. There were actually a few that had slightly too much indentation, but I don't think that would've been picked up by error checking so I, uh, I'm glad I'm a masochist, I suppose?

Yeah, I did look through it by hand. I feel more than a little silly.

5

u/Ukacelody Aug 21 '20

GOOD HUMAN. MAYBE EVEN GOODEST HUMAN, DARE I SAY.

4

u/highphilosopher7 Aug 28 '20

Definitely the Goodest!

4

u/GoldenKela Aug 21 '20

a true hero

3

u/DamnOrangeCat Aug 21 '20

Very good human

14

u/__Zuki__ evil Aug 21 '20

When you are paid per line

9

u/[deleted] Aug 21 '20

i wasn't ready for that

6

u/HTTP_404_NotFound bool isEven(int num) => num%2==0 Aug 21 '20

so, to get this straight....

If I want to farm karma here- I just need to create a low-effort script, to just generate a bunch of code which would normally be handled in a much easier to read method, right?

4

u/Dr_Insano_MD Aug 21 '20

Just make a shitload of bad IsEven functions and post it here. I even made a sub for that! /r/badIsEven

2

u/HTTP_404_NotFound bool isEven(int num) => num%2==0 Aug 21 '20

I think I can do even better..... stand-by...

2

u/HTTP_404_NotFound bool isEven(int num) => num%2==0 Aug 21 '20

3

u/Deltaflyer666 Sep 08 '20

I'm not sure... that looks pretty easy to read..... I would do it more like this...

public static bool isEven(int A)
{
Func<int, int, int, int> test = delegate (int X, int Y, int Z) { while ((X < 0 ? 0 - X : X) > (Y / 2)) { X -= (Z < 0 ? -Y : Y); } return X; };
return (test(A, 2, A) == 0 ? true : false);
}

and it works :D

Number Answer
--------------------
-3 False
-2 True
-1 False
0 True
1 False
2 True
3 False

6

u/Sastii Aug 21 '20

Take this guy's keyboard

6

u/Slippn_Jimmy Aug 21 '20

Maybe his life

5

u/Pinio1 Aug 21 '20

Wow finally a post where I can take a quick glanse and know why it's bad ^ ^

3

u/Dads101 Aug 21 '20

Truly disgusting

3

u/DanTactical Aug 21 '20

Why is this so satisfying to seeq

3

u/ForeverAloniexdxdxd Aug 21 '20

wow this new yandere simulator code sure is lit

3

u/FloweyTheFlower420 sadistic Aug 21 '20

Who's getting YanDev vides?

5

u/Mrdeadlyenemy Aug 21 '20

Just use SwItCh cAsE!!

2

u/NullBrowbeat Aug 21 '20

I also sometimes submit code like this, even though I didn't go that far yet, just to fuck with people. :D

2

u/float7 Aug 21 '20

That's huge ( ͡° ͜ʖ ͡°)

2

u/FuzzYetDeadly Aug 22 '20

I remember doing this before learning about the miracle of the % operator and the use of DateTime formatting APIs

2

u/[deleted] Aug 22 '20

Did this person just shorten the code that much?

2

u/asaf92 Aug 28 '20

Wait so YandereDev switched to Python?

-1

u/[deleted] Aug 21 '20

What does this even do? Im not reading through all of it lol

1

u/MeDotPy Aug 22 '20

A program that tells the time with input in seconds as "days, hours, minutes and seconds" without those that are 0. Since it has commas and 'and' you have to put those somehow in the returned string.

Ex: 3727 -> '1 hour, 2 minutes and 7 seconds'