Skip to content

Commit 26a63b7

Browse files
Edit my solution
1 parent a893d61 commit 26a63b7

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Week30.ipynb

+11-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"\n",
2828
"Think about what the problem is asking, break it down\n",
2929
"\n",
30-
"The first step is determining which dice wins.\n",
30+
"First we must code up the `beats()` function.\n",
3131
"1. Count the number of ways dice A wins.\n",
3232
"2. Count the number of ways dice B wins.\n",
3333
"3. Whoever have a larger value is the winner. If both win the same number of times, that dice are tied."
@@ -39,7 +39,7 @@
3939
"metadata": {},
4040
"outputs": [],
4141
"source": [
42-
"\"\"\" Python solution to USACO January 2022 Bronze problem two\n",
42+
"\"\"\" Python solution to USACO January 2022 Bronze problem two.\n",
4343
"Translated into python from my c++ solution. Below is the link to my original code.\n",
4444
"https://github.com/asubramanian08/USACO/blob/master/Bronze/2021-2022/JAN2022/q2.cpp \"\"\"\n",
4545
"\n",
@@ -57,23 +57,28 @@
5757
" bWins += A[i] < B[j]\n",
5858
" return aWins - bWins\n",
5959
"\n",
60+
"# Get input\n",
6061
"C = [0, 0, 0, 0] # Using 0 as place holder\n",
6162
"for test in range(int(input())):\n",
6263
" diceFaces = list(map(int, input().split(' ')))\n",
6364
" A = diceFaces[:SIDES]\n",
6465
" B = diceFaces[SIDES:]\n",
65-
" foundAnswer = False\n",
66+
" \n",
67+
" # Unify cycle direction\n",
6668
" winner = beats(A, B)\n",
67-
" if winner == 0: # Tie\n",
68-
" foundAnswer = True\n",
69-
" elif winner < 0: # B won\n",
69+
" if winner < 0:\n",
7070
" A, B = B, A\n",
71+
" \n",
72+
" # Determine is there is a valid cycle\n",
73+
" foundAnswer = False\n",
7174
" for C[0] in range(MIN_FACE, MAX_FACE + 1, 1):\n",
7275
" for C[1] in range(MIN_FACE, MAX_FACE + 1, 1):\n",
7376
" for C[2] in range(MIN_FACE, MAX_FACE + 1, 1):\n",
7477
" for C[3] in range(MIN_FACE, MAX_FACE + 1, 1):\n",
7578
" if beats(C, A) > 0 and beats(B, C) > 0:\n",
7679
" foundAnswer = True # Cycle found\n",
80+
" \n",
81+
" # Print yes when there is no tie and a cycle has been found\n",
7782
" print(\"yes\" if (winner != 0 and foundAnswer) else \"no\")"
7883
]
7984
}

0 commit comments

Comments
 (0)