Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

How do you do this? (Python)

Name: Anonymous 2013-02-23 3:51

Consider a dice battle game called What-Are-the-Odds? It is a team battle game where team_ab plays against
team_cd and two players are on a team. Each player rolls a die and adds their roll value to their teammate’s
value. The first team_ab, will roll values represented by a and b. The second team_cd, will roll values
represented by c and d. Let the sum of the dice values for team_ab be represented by AB, and the sum of the dice
values for team_cd be represented by CD.
Rules of battle are as follows and apply to either team.
 Die values will be integers from 1 to 6, inclusive
 If only one of AB and CD are odd: The team with the odd number wins.
 If AB and CD are both odd: The largest odd number wins. If there is a tie, the individual rolls of a, b, c,
and d must be examined. The team with the largest odd number roll wins.
 If exactly one of AB or CD is an even number <= 6: The team with the even number loses.
 If AB and CD are both even and <=6: The team with AB or CD that is divisible by the largest odd
number wins.
 If AB and CD are both even and >6: The team with AB or CD that is divisible by the largest odd number
wins.
 A tie will occur in all situations in which a winner is not determined.
Write a python function, win_odds, that consumes 4 dice values, a, b, c, or d (integers 1-6), and produces
the winning team represented by a string (“AB”, “CD”, or “ABCD” when there is a tie). Some examples follow:


win_odds(2, 3, 6, 6) => “AB”
win_odds(2, 3, 5, 6) => “CD”
win_odds(2, 2, 1, 3) => “ABCD”
win_odds(1, 1, 1, 2) => “CD”
win_odds(3, 5, 5, 5) => “CD”
win_odds(2, 4, 2, 2) => “AB”
win_odds(1, 5, 1, 3) => “AB”
win_odds(6, 6, 4, 4) => “AB”

Name: Anonymous 2013-02-23 4:08

Bump.

Name: Anonymous 2013-02-23 4:27

what's the bfd? start with a variable set to the tie result ABCD. write a bunch of conditionals testing all those stupid rules that will change the result variable if need be. return the result variable

Name: Anonymous 2013-02-23 4:49

hurrrr

Name: Anonymous 2013-02-23 5:27


when will u python fags learn that javascript is superior?



function win_odds(a,b,c,d){var ab=a+b,cd=c+d,result='ABCD'; if(ab%2==1&&cd%2==0)result='AB'; if(ab%2==0&&cd%2==1)result='CD'; if(ab%2==1&&cd%2==1){if(ab==cd){var ab_odd=a%2==0?b:a, cd_odd=c%2==0?d:c; if(ab_odd!=cd_odd){result=ab_odd>cd_odd?'AB':'CD';}}else{result=ab>cd?'AB':'CD';}}else if(ab%2==0&&cd%2==0){if(ab<=6&&cd<=6){if(ab==6&&cd!=6)result='AB';else if(ab!=6&&cd==6)result='CD';}else if(ab>6&&cd>6){if(ab!=cd){if(ab==10||cd==10){result=ab==10?'AB':'CD';}else if(ab==12||cd==12){result=ab==12?'AB':'CD';}}}} return result;}

Name: Anonymous 2013-02-23 5:31

>>5
When will you learn how to properly indent your code?

Name: Anonymous 2013-02-23 5:32

>>5
should it return as soon as it gets a result?

Name: Anonymous 2013-02-23 5:47

>>6
indenting code... ever
python, forced indentation... no

Name: Anonymous 2013-02-23 5:47

>>7
what do you think faget? Ctrl-shift-J in chrome and copy and paste it and find out

Name: Anonymous 2013-02-23 5:48

>>8
>sacrificing readability for some bytes

Name: Anonymous 2013-02-23 5:51

>>7

it could if you gave that much of a shit. probably more of a style preference than anything. just assign the result and return it after all the spaghetti logic

Name: Anonymous 2013-02-23 5:52

>>10
implying i wrote it for you to read it
if you care that much do a jewgle search for "javascript beautifier"

Name: Anonymous 2013-02-23 6:06

def win_odds(a, b, c, d):
    ab = a + b
    cd = c + d
    result = 'ABCD'
    if (ab%2==1 & cd%2==0):
        result = 'AB'
    if (ab%2==0 & cd%2==1):
        result = 'CD'
    if (ab%2==1 & cd%2==1):
        if (ab==cd):
            ab_odd = a%2==0
            cd_odd = c%2==0
            if (ab_odd!=cd_odd):
                result = ab_odd > cd_odd
        else:
            result = ab>cd
    elif (ab%2==0 & cd%2==0):
        if(ab<=6 & cd<=6):
            if (ab==6 & cd!=6):
                result = 'AB'
            elif (ab!=6 & cd==6):
                result = 'CD'
        elif (ab>6 & cd>6):
            if(ab!=cd):
                if(ab==10|cd==10):
                    result = ab==10
                elif (ab==12|cd==12):
                    result = ab==12
    return result

Name: Anonymous 2013-02-23 6:11

>>13
lolno

Name: Anonymous 2013-02-23 6:17

>>14
Enlighten me

Name: Anonymous 2013-02-23 6:27

>>15
code tags

Name: Anonymous 2013-02-23 6:37

>>15
first of all, you turned some solid, thick, tight javascript into some ugly forced-indentation python. fuck that gay language

second, look at your return values for the lower spaghetti logic. when you assign "ab_odd > cd_odd" to the variable 'return', what the fuck are you getting back from your function? i don't know how python represents true/false values when you assign them to variables, but regardless of what it sends back it's not going to be 'AB' or 'CD' is it?

since python blows and doesn't have the ?: operator, you need to convert that too: http://stackoverflow.com/questions/2191890/conditional-operator-in-python

welp, i'm done doing your homework. you're welcome

Name: Anonymous 2013-02-23 6:49

win_odds(2, 4, 2, 2) => “AB”

undefined behaviour ^^

Name: Anonymous 2013-02-23 6:51

>>17

def win_odds(a, b, c, d):
    ab = a + b
    cd = c + d
    result = 'ABCD'
    if (ab%2==1 & cd%2==0):
        result = 'AB'
    if (ab%2==0 & cd%2==1):
        result = 'CD'
    if (ab%2==1 & cd%2==1):
        if (ab==cd):
            ab_odd = b if a%2==0 else a
            cd_odd = d if c%2==0 else c
            if (ab_odd!=cd_odd):
                result = 'AB' if ab_odd > cd_odd else 'CD'
        else:
            result = 'AB' if ab > cd else 'CD'
    elif (ab%2==0 & cd%2==0):
        if(ab<=6 & cd<=6):
            if (ab==6 & cd!=6):
                result = 'AB'
            elif (ab!=6 & cd==6):
                result = 'CD'
        elif (ab>6 & cd>6):
            if(ab!=cd):
                if(ab==10|cd==10):
                    result = 'AB' if ab==10 else 'CD'
                elif (ab==12|cd==12):
                    result = 'AB' if ab==12 else 'CD'
    return result


I know this language is ass, but give me a break.

Name: Anonymous 2013-02-23 6:54

>>18
refer to the rule "If AB and CD are both even and <=6: The team with AB or CD that is divisible by the largest odd
number wins."

it's AB = 6 and CD = 4.
 6 is divisible by 3 but 4 is only divisible by 1, so it's 'AB' and the result is correct.

Name: !agc.6D4SKQ 2013-02-23 6:55

>>1
good ol' pen and paper

Name: !t11zgaSFtY 2013-02-23 6:57

>>20
*facepalm

Name: Anonymous 2013-02-23 7:03


def win_odds(a, b, c, d):
    ab = a + b
    cd = c + d
    result = 'ABCD'
    if (ab%2==1 and cd%2==0):
        result = 'AB'
    if (ab%2==0 and cd%2==1):
        result = 'CD'
    if (ab%2==1 and cd%2==1):
        if (ab==cd):
            ab_odd = b if a%2==0 else a
            cd_odd = d if c%2==0 else c
            if (ab_odd != cd_odd):
                result = 'AB' if ab_odd > cd_odd else 'CD'
        else:
            result = 'AB' if ab > cd else 'CD'
    elif (ab%2==0 and cd%2==0):
        if(ab<=6 and cd<=6):
            if (ab==6 & cd!=6):
                result = 'AB'
            elif (ab!=6 & cd==6):
                result = 'CD'
        elif (ab>6 and cd>6):
            if(ab!=cd):
                if(ab==10 or cd==10):
                    result = 'AB' if ab==10 else 'CD'
                elif (ab==12 or cd==12):
                    result = 'AB' if ab==12 else 'CD'
    return result


This is getting rather close...

Results
[code]
AB
CD
AB
CD
CD
ABCD
ABCD
AB
[code]

Name: Anonymous 2013-02-23 7:06

eh 4,4 - 3,3 is a draw though =)

Name: Anonymous 2013-02-23 7:09

I got it.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List