14
\$\begingroup\$

In Australian Football, goals are worth 6 points and behinds are worth 1 point. Scores may include the number of goals and behinds, as well as the total score. Given the number of goals and behinds for two different teams, determine which team won the game.

Take four integers g1, b1, g2, b2 as input, and output two distinct values for whether the first team or the second team inputted won. Input format is flexible, but input order must allow it to be obvious which team is first. For example, g1, g2, b1, b2 would be allowed, but b1, g2, g1, b2 would not.

Test Cases

Test cases will use true for the first team winning and false for the second team winning. Input is in the format (g1,b1),(g2,b2).

(1,0),(0,1)        true
(2,0),(0,11)       true
(10,8),(11,1)      true
(0,0),(1,0)        false
(100,100),(117,0)  false
(7,7),(5,12)       true
(2,0),(0,13)       false

As an example, for input (10,8),(11,1), team 1 scored 10 goals and 8 behinds, for a total of \$10*6+8*1=68\$ points, while team 2 scored \$11*6+1*1=67\$ points, so team 1 wins.

No input will be a draw - your program's behavior on draw input does not matter.

\$\endgroup\$
7
  • \$\begingroup\$ Could we extend for Gaelic football and hurling? \$\endgroup\$
    – TRiG
    Sep 27, 2019 at 10:23
  • \$\begingroup\$ @TRiG make your own question! \$\endgroup\$
    – Stephen
    Sep 27, 2019 at 11:07
  • \$\begingroup\$ I'll try to think of something that isn't too close. \$\endgroup\$
    – TRiG
    Sep 27, 2019 at 11:23
  • 2
    \$\begingroup\$ @TRiG, GAA would be identical, just using base-3 instead of base-6. \$\endgroup\$
    – Shaggy
    Sep 27, 2019 at 11:35
  • \$\begingroup\$ Yeah @Shaggy, which is why I couldn't just copy this question to make an equivalent GAA one. Something similar. Maybe including International Rules Football. \$\endgroup\$
    – TRiG
    Sep 27, 2019 at 12:15

35 Answers 35

7
\$\begingroup\$

Jelly, 3 bytes

ḅ6M

A monadic Link accepting a list of lists of integers, [[g1,b1],[g2,b2]], which yields a list [1] or [2].
(Draws would yield [1,2])

...Or a full program printing 1 or 2.

Try it online! Or see the test-suite.

How?

ḅ6M - Link: list of lists of integers, X
 6  - literal six
ḅ   - convert (X) from base 6 (vectorises)
  M - maximal indices
\$\endgroup\$
5
\$\begingroup\$

CP-1610 assembly (Intellivision), 9 DECLEs1 ≈ 12 bytes

A routine taking input in R0 (\$g_1\$), R1 (\$b_1\$), R2 (\$g_2\$) and R3 (\$b_2\$) and setting the sign flag if the 2nd team wins, or clearing it otherwise.

275   PSHR  R5        ; push return address
110   SUBR  R2,   R0  ; R0 -= R2
082   MOVR  R0,   R2  ; R2 = R0
04C   SLL   R0,   2   ; R0 <<= 2
0D0   ADDR  R2,   R0  ; R0 += R2
0D0   ADDR  R2,   R0  ; R0 += R2
0C8   ADDR  R1,   R0  ; R0 += R1
118   SUBR  R3,   R0  ; R0 -= R3
2B7   PULR  R7        ; return

The CP-1610 has no multiplication instruction and may only shift by 1 or 2 positions at a time, so we compute the following expression instead:

((R0 - R2) << 2) + (R0 - R2) + (R0 - R2) + R1 - R3

Full test code

          ROMW    10              ; use 10-bit ROM width
          ORG     $4800           ; map this program at $4800

          ;; ------------------------------------------------------------- ;;
          ;;  test code                                                    ;;
          ;; ------------------------------------------------------------- ;;
main      PROC
          SDBD                    ; set up an interrupt service routine
          MVII    #isr,     R0    ; to do some minimal STIC initialization
          MVO     R0,       $100
          SWAP    R0
          MVO     R0,       $101

          EIS                     ; enable interrupts

          SDBD                    ; R4 = pointer to test cases
          MVII    #@@data,  R4
          MVII    #$200,    R5    ; R5 = backtab pointer

@@loop    PSHR    R5              ; save R5 on the stack
          MVI@    R4,       R0    ; load the next test case
          MVI@    R4,       R1    ; into R0 .. R3
          MVI@    R4,       R2
          MVI@    R4,       R3
          CALL    score           ; invoke our routine
          BMI     @@true

          MVII    #$80,     R0    ; set output to '0'
          B       @@output

@@true    MVII    #$88,     R0    ; set output to '1'

@@output  PULR    R5              ; restore R5
          MVO@    R0,       R5    ; draw the output

          SDBD                    ; was it the last test case?
          CMPI    #@@end,   R4
          BLT     @@loop          ; if not, jump to @@loop

          DECR    R7              ; loop forever

@@data    DECLE   1, 0, 0, 1      ; test cases
          DECLE   2, 0, 0, 11
          DECLE   10, 8, 11, 1
          DECLE   0, 0, 1, 0
          DECLE   100, 100, 117, 0
          DECLE   7, 7, 5, 12
          DECLE   2, 0, 0, 13
@@end     ENDP

          ;; ------------------------------------------------------------- ;;
          ;;  ISR                                                          ;;
          ;; ------------------------------------------------------------- ;;
isr       PROC
          MVO     R0,       $0020 ; enable display

          CLRR    R0
          MVO     R0,       $0030 ; no horizontal delay
          MVO     R0,       $0031 ; no vertical delay
          MVO     R0,       $0032 ; no border extension
          MVII    #$D,      R0
          MVO     R0,       $0028 ; light-blue background
          MVO     R0,       $002C ; light-blue border

          JR      R5              ; return from ISR
          ENDP

          ;; ------------------------------------------------------------- ;;
          ;;  routine                                                      ;;
          ;; ------------------------------------------------------------- ;;
score     PROC
          PSHR    R5              ; push the return address

          SUBR    R2,       R0    ; R0 -= R2
          MOVR    R0,       R2    ; R2 = R0
          SLL     R0,       2     ; R0 <<= 2
          ADDR    R2,       R0    ; R0 += R2
          ADDR    R2,       R0    ; R0 += R2
          ADDR    R1,       R0    ; R0 += R1
          SUBR    R3,       R0    ; R0 -= R3

          PULR    R7              ; return
          ENDP

Output

output

screenshot from jzIntv


1. A CP-1610 opcode is encoded with a 10-bit value, known as a 'DECLE'. This routine is 9 DECLEs long.

\$\endgroup\$
5
\$\begingroup\$

International Phonetic Esoteric Language, 12 bytes (WIP language) (OLD)

6ɪθɪt6ɪθɪtʈo

Outputs 1 for true and 0 for false.

No TIO interpreter yet, but is runnable by cloning the repository above, and calling python main.py "code here".

The TL;DR of the language is that it's a stack-based language where every instruction is a character from the International Phonetic Alphabet.

Takes in arguments as 4 inputs from STDIN, in the order g1, b1, g2, b2. Might be golfed down to less than 12 bytes once loops are fully implemented.

6ɪθɪt6ɪθɪtʈo
6            ; Push 6
 ɪ           ; Take number input, push
  θ          ; Pop 2, multiply, push
   ɪ         ; Take number input, push
    t        ; Pop 2, add, push
     6       ; Push 6
      ɪ      ; Take number input, push
       θ     ; Pop 2, multiply, push
        ɪ    ; Take number input, push
         t   ; Pop 2, add, push 
          ʈ  ; Pop 2, if a > b push 1, otherwise 0
           o ; Pop, print
\$\endgroup\$
2
  • 7
    \$\begingroup\$ kuːl ˈlæŋgwɪʤ, djuːd! \$\endgroup\$
    – roblogic
    Sep 27, 2019 at 4:25
  • \$\begingroup\$ aɪ əm nɑːt əˈmjuːzd baɪ ðə hʊd; bɪˈniːθ ɪt ɪz ˈsɪmpli dʒʌst əˈnʌðər stæk-beɪst ˈlæŋɡwɪdʒ. aɪ ˈstrɒŋli dɪsˈkɜːrɪdʒ ju tu ʌpvoʊt ðɪs ˈænsər. \$\endgroup\$
    – user85052
    Sep 30, 2019 at 11:03
4
\$\begingroup\$

Python 3, 26 bytes

lambda g,b,G,B:6*g+b>6*G+B

Try it online!

Not incredibly interesting answer.

\$\endgroup\$
4
\$\begingroup\$

Cascade, 16 bytes

#6&
>
 |/
 +
* &

Try it online!

Reuses the same 6*a+b logic for both teams then prints whether the first scores higher than the other

\$\endgroup\$
4
\$\begingroup\$

C# (Visual C# Interactive Compiler), 22 bytes

(a,b,c,d)=>a*6+b>c*6+d

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Also works in JS. \$\endgroup\$
    – Shaggy
    Sep 27, 2019 at 6:54
  • \$\begingroup\$ Or Java by changing the => to -> \$\endgroup\$ Sep 27, 2019 at 7:29
3
\$\begingroup\$

Clean, 34 bytes

import StdEnv
$a b c d=a*6+b>c*6+d

Try it online!

Defines $ :: Int Int Int Int -> Bool with arguments taken like $ g1 b1 g2 b2

\$\endgroup\$
3
\$\begingroup\$

Perl 6, 13 bytes

*×6+*>*×6+*

Try it online!

Takes input as 4 integers, and basically just does as the question asks

\$\endgroup\$
3
\$\begingroup\$

J, 12 bytes

>&(1#.6 1*])

Try it online!

\$\endgroup\$
3
\$\begingroup\$

33, 22 bytes

6OxcOasz6OxcOaclmzh1co

Try it online!

Takes the input as 4 delimited integers, and returns 0 for the first team winning, 1 for the second.

Explanation:

6Oxc                   | Multiplies the first number by 6
    Oa                 | Adds the second number
        6Oxc           | Multiplies the third number by 6
            Oa         | Adds the fourth number
      sz      clmz     | Subtract this from the first team's score
                  h1co | Print 0 if the first team's score is greater, 1 otherwise

-4 bytes if nondistinct results are allowed:

6OxcOasz6OxcOaclmo

Will output the score difference; positive results mean the first team win, negative means the second team win.

\$\endgroup\$
3
\$\begingroup\$

Scala, 11 bytes

_*6+_>_*6+_

Try it online!

Takes 4 Integers in the order of g1 b1 g2 b2.

\$\endgroup\$
3
\$\begingroup\$

brainfuck, 45 38 36 32 29 28 bytes

,[>,[<++++++>-],]-[[-<]>>]>.

Try it online!

Thanks to @Jo King for -8 bytes

Input is b1, g1, b2, g2 (goals and behinds are exchanged) Prints þ, if team 1 won. Prints null, if team 2 won.

code:

[tape: p1, p2, print marker]

[Get input and calculate scores]
,               input behinds of team 1
[               while input
  >,                go to next cell and input goals of team
  [<++++++>-]       add it 6 times to behinds
,]              repeat this with the second pair of values

[Determine, which one is better]
-               set print marker
[               while score of both teams is greater than zero
  [-<]              decrement and go to previous cell (team 1 or empty cell/in the first run, it will decrement the print marker a second time)
  >>                return to team 2 (or two cells to the right of the first team that became 0)
]
>               go one cell right. If team 1 won, we are at the print marker now
                If team 2 won, we are one cell right of the print marker
.           Print that
\$\endgroup\$
3
  • \$\begingroup\$ I dont think this works with inputs greater than 10, but a great solution anyway. (Would note it down still). Might give a try to outgolf that later :) \$\endgroup\$ Sep 27, 2019 at 10:01
  • 1
    \$\begingroup\$ Yes, inputs greater than 9 are at least a bit tricky, because the code only uses one character per input. You need to use the next ASCII characters (:;<=>? etc.) if you want to enter higher scores. \$\endgroup\$
    – Dorian
    Sep 27, 2019 at 10:08
  • \$\begingroup\$ Is "input as character code except null" an option? Plus, both scores must be equal, when being integer-divided by 256, at least when you use tio. \$\endgroup\$
    – Dorian
    Sep 27, 2019 at 15:46
3
\$\begingroup\$

Scratch 3.0 17 16 blocks, 160 143 bytes

Score comes from proposed scoring method here

1 block/17 bytes saved thanks to @A (or Uzer_A on scratch)_

Program in better blocks

Try it on Scratch

As Scratchblocks:

when gf clicked
repeat(2
ask[]and wait
set[m v]to((answer)*(6)
ask[]and wait
change[m v]by(answer
add(m)to[x v
end
say<(item(1) of [x v]) > (m)

Answer History

Program in blocks

Pretty much a port of my Keg answer.

Try it on Scratch

Input is in the form of g1, b1, g2, b2

In Scratchblocks syntax

when gf clicked
repeat(0
set[m v]to(0
ask[]and wait
change[m v]by((answer)*(6)
ask[]and wait
change[m v]by(answer
add(m)to[x v
end
say<(item(1) of [x v]) > (m)

Now I know what you're saying... why golf in scratch?!? Well, it's fun. That's why. Also, Scratch is unique in that it isn't very often featured here on CGCC.

\$\endgroup\$
1
  • \$\begingroup\$ 51 bytes? \$\endgroup\$
    – att
    Sep 27, 2019 at 7:53
2
\$\begingroup\$

Keg, 10 bytes (SBCS)

(2|¿¿6*+)>

Try it online!

As an Australian, I approve of this question.

Input taken as:

b1
g1
b2
g2

And 0 means team 2 and 1 means team 1

Explained

(2| #twice
¿¿  #get input in the form of bn, gn where n is the team number
*6+ #multiply the goals by 6 and add the values
)>  #compare the two values to determine the winner
\$\endgroup\$
2
\$\begingroup\$

05AB1E, 6 5 bytes

6δβZk

Input as a nested list [[g1,b1],[g2,b2]]. Output 0 if team 1 wins and 1 if team 2 wins.

-1 byte thanks to @Grimy for reminding me about δ.

Try it online or verify all test cases.

Explanation:

Apparently arbitrary base conversion on nested lists doesn't work without an explicit map outer product.

 δβ    # Apply arbitrary base-conversion double-vectorized,
6      # using the (implicit) input-list of lists and 6 as base
       # (i.e. [a,b] becomes 6a+b (or to be more precise: 6¹a + 6⁰b))
   Z   # Get the maximum of this mapped list (without popping the list itself)
    k  # And get the 0-based index of this maximum in the mapped list
       # (after which the top of the stack is output implicitly as result)
\$\endgroup\$
0
2
\$\begingroup\$

Zsh, 19 bytes

try it online!!

((6*$1+$2>6*$3+$4))

Input order is g1 b1 g2 b2. Exit codes 0==true and 1==false

\$\endgroup\$
2
\$\begingroup\$

C (gcc), 39 35 31 26 bytes

e(a,b,c,d){a=(a-c)*6>d-b;}

0 is false

1 is true

Input to function is (g1, b1, g2, b2)

Thanks to Doorknob for -5 bytes

Try it online!

\$\endgroup\$
1
  • 3
    \$\begingroup\$ You can remove the space after return, but you can also abuse an implementation detail for 26 bytes. \$\endgroup\$
    – Doorknob
    Sep 27, 2019 at 4:44
2
\$\begingroup\$

Brain-Flak, 62 bytes

([((({})({}){}){}{}[(({})({}){}){}{}]<(())>)(<>)]){({}())<>}{}

Outputs 1 if the first team lost, and 0 if they won (or tied).

Try it online!

# Input: G B g b

   (                                 <(())>)                   # Push 1 under...
    ({})({}){}){}{}                                            #   6G + B
                   [                ]                          #   Minus
                    (({})({}){}){}{}                           #   6g + b
                                             <>                # Switch stacks
([(                                         (  )])             # Push 0 under -(6G+B-6g+b)
                                                   ({}())<>    # Add 1 and switch stacks...
                                                  {        }   #   until one stack reaches 0
                                                            {} # Pop, leaving either 1 or 0
\$\endgroup\$
2
\$\begingroup\$

PowerShell, 35 bytes

param($g,$b,$h,$c)$g*6+$b-gt$h*6+$c

Try it online!

\$\endgroup\$
1
2
\$\begingroup\$

Poetic, 751 bytes

the game:a game o soccer
for a moment of my fun,i kicked my leg
o,i hurt a player
o.m.gee,o no
suddenly i then apologized a little
o.m.gee,o no
but really,i loved a good soccer battle
a game i am doing,i love it
there is a game,a twenty-to-one unwinnable match(as we called it,i mean)a match we won
a wonder of an event i saw
i played,i go in again
i am happy in a match-up of teams,i am pumped
then o,a coach i saw played soccer
i know i do admire a game o soccer
o,a match was not a bummer,and also i am making in an extra score
i think i saw a split net,a hole i ripped out a net
i am ready to win a match
o,my people and i love a sport,a bit o soccer
i am going in a game,i score,i win
o really,i am doing a game o soccer
play ball
i am gonna wi-n

Try it online!

Boy, this was a tough one to write.

Input is in the following format:

g1
b1
g2
b2

This gives the error code of "Mismatched IF/EIF" if the first team wins, and "Unexpected EOF" if the second team wins. (Incidentally, a tie is treated as the second team winning).

\$\endgroup\$
1
\$\begingroup\$

Retina 0.8.2, 34 bytes

\d+
$*
(1*),
$1$1$1$1$1$1
(1*);\1$

Try it online! Link includes test cases. Outputs 1 if the second team doesn't win and 0 if it does. Explanation:

\d+
$*

Convert the input to unary.

(1*),
$1$1$1$1$1$1

In each pair, multiply the first number by six and add the second.

(1*);\1$

Check whether the second number is greater than the first. Alternatively, you could use ^(1*);\1 which would output 0 if the first team wins and 1 if it doesn't.

\$\endgroup\$
1
\$\begingroup\$

PHP (7.4), 32 bytes

fn($g,$b,$G,$B)=>$g+$b/6>$G+$B/6

Try it online!

\$\endgroup\$
1
\$\begingroup\$

ABC-assembler, 111 74 bytes

.o 0 4 iiii
f
	subI
	pushI 6
	mulI
	addI
	subI
	pushI 0
	ltI
.d 0 1 b
	rtn

Try it online!

It doesn't use anything above the most basic stack operations:

subI    | B = [g1-g2,b1,b2]
pushI 6 | B = [6,g1-g2,b1,b2]
mulI    | B = [6*g1-6*g2,b1,b2]
addI    | B = [6*g1+b1-6*g2,b2]
subI    | B = [6*g1+b1-6*g2-b2]
pushI 0 | B = [0,6*g1+b1-6*g2-b2]
ltI     | B = [0<6*g1+b1-6*g2-b2]
\$\endgroup\$
1
\$\begingroup\$

Perl 5, 18 bytes

say<>*6+<>><>*6+<>

Try it online!

Input is line separated:

g1
b1
g2
b2
\$\endgroup\$
1
\$\begingroup\$

Wolfram Language (Mathematica), 13 bytes

6#+#2>6#3+#4&

Try it online!

straightforward and boring

\$\endgroup\$
1
\$\begingroup\$

Whitespace, 115 bytes

[S S S N
_Push_0][S N
S _Duplicate_0][T   N
T   T   _STDIN_as_integer][T    T   T   _Retrieve_integer][S S S T  T   S N
_Push_6][T  S S N
_Multiply][S N
S _Duplicate][S N
S _Duplicate][T N
T   T   _STDIN_as_integer][T    T   T   _Retrieve_integer][T    S S S _Add][S N
S _Duplicate][S N
S _Duplicate][T N
T   T   _STDIN_as_integer][T    T   T   _Retrieve_input][S S S T    T   S N
_Push_6][T  S S N
_Multiply][S N
S _Duplicate][S N
S _Duplicate][T N
T   T   _STDIN_as_integer][T    T   T   _Retrieve_input][T  S S S _Add][T   S S T   _Subtract][N
T   T   N
_If_negative_jump_to_Label_NEGATIVE][S S S N
_Push_0][T  N
S T _Print_as_integer][N
N
N
_Exit_Program][N
S S N
_Label_NEGATIVE][S S S T    N
_Push_1][T  N
S T _Print_as_integer]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Prints 0 if team 1 wins and 1 (could also be -1 for the same byte-count) if team 2 wins.

Try it online (with raw spaces, tabs and new-lines only).

Explanation in pseudo-code:

Integer g1 = STDIN as integer
Integer t1 = g1*6
Integer b1 = STDIN as integer
t1 = t1 + b1
Integer g2 = STDIN as integer
Integer t2 = g2*6
Integer b2 = STDIN as integer
t2 = t2 + b2
If(t1 - t2 < 0):
  Goto NEGATIVE
Print 0
Exit program

Label NEGATIVE:
  Print 1
  (implicitly exit with an error)

One minor note: since the inputs are guaranteed to be \$\geq0\$, I'm using that to my advantage to re-use the inputs as heap-addresses for the subsequent inputs. With challenges which can have negative inputs I'd have to re-push 0 as heap-address, since heap-addresses cannot be negative.

\$\endgroup\$
1
\$\begingroup\$

Ruby, 21 bytes

->a,b,x,y{b-y>6*x-=a}

Try it online!

Worked around the boring solution, saved a byte and called it a day.

\$\endgroup\$
1
\$\begingroup\$

SimpleTemplate, 84 bytes

Just the simple "multiply by 6, sum and compare" aproach, except the math support is extremelly lacking.

{@set*A argv.0,6}{@incbyargv.1 A}{@set*B argv.2,6}{@incbyargv.3 B}0{@ifB is lowerA}1

Outputs 0 for false and 01 for true.


Ungolfed:

{@// multiply the first argument by 6}
{@set* teamA argv.0, 6}

{@// add the 2nd argument to the previous result}
{@inc by argv.1 teamA}

{@// same as before, for argument 3 and 4}
{@set* teamB argv.2, 6}
{@inc by argv.3 teamB}

{@echo 0}
{@// alternative: teamA is greater than teamB}
{@if teamB is lower than teamA}
    {@echo 1}
{@/}

Everything should be clear with the comments ({@// ... }) added.

\$\endgroup\$
1
\$\begingroup\$

Japt, 6 bytes

Input as a 2D-array. Outputs 1 for team 1, 0 for a draw or -1 for team 2.

mì6 rg

Try it

mì6 rg     :Implicit input of array
m          :Map
 ì6        :  Convert from base-6 digit array
    r      :Reduce by
     g     :  Sign of difference
\$\endgroup\$
1
\$\begingroup\$

Go, 44 bytes

func f(a,b,x,y int)bool{return a*6+b>=x*6+y}

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.