Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created October 21, 2020 01:47
Show Gist options
  • Save ZechCodes/7600e00e41ea2b86fa80fe90956ce064 to your computer and use it in GitHub Desktop.
Save ZechCodes/7600e00e41ea2b86fa80fe90956ce064 to your computer and use it in GitHub Desktop.
Challenge 136 - Spin Around, Touch the Ground

Challenge 136 - Spin Around, Touch the Ground

Given a list of directions to spin, "left" or "right", return an integer of how many full 360° rotations were made. Note that each word in the list counts as a 90° rotation in that direction.

Worked Example

spin_around(['right', 'right', 'right', 'right', 'left', 'right', ]) ➞ 1
# You spun right 4 times (90 * 4 = 360)
# You spun left once (360 - 90 = 270)
# But you spun right once more to make a full rotation (270 + 90 = 360)

Examples

spin_around(['left', 'right', 'left', 'right']) ➞ 0

spin_around(['right', 'right', 'right', 'right', 'right', 'right', 'right', 'right']) ➞ 2

spin_around(['left', 'left', 'left', 'left']) ➞ 1

Notes

  • Return a positive number.
  • All tests will only include the words "right" and "left".
from __future__ import annotations
import unittest
def spin_around(turns: list[str]) -> int:
return 0 # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual(0, spin_around(["left", "right", "left", "right"]))
def test_2(self):
self.assertEqual(
2,
spin_around(
["right", "right", "right", "right", "right", "right", "right", "right"]
),
)
def test_3(self):
self.assertEqual(1, spin_around(["left", "left", "left", "left"]))
def test_4(self):
self.assertEqual(0, spin_around([]))
def test_5(self):
self.assertEqual(0, spin_around(["left"]))
def test_6(self):
self.assertEqual(0, spin_around(["right"]))
def test_7(self):
self.assertEqual(
1, spin_around(["right", "right", "right", "left", "right", "right"])
)
def test_8(self):
self.assertEqual(
1,
spin_around(
[
"left",
"left",
"right",
"left",
"left",
"left",
"left",
"left",
"left",
"right",
"left",
"left",
"right",
"right",
"right",
"right",
"left",
"left",
"right",
"right",
]
),
)
def test_9(self):
self.assertEqual(
0,
spin_around(
[
"right",
"left",
"left",
"right",
"left",
"left",
"right",
"left",
"right",
"right",
"left",
"left",
"right",
"right",
"right",
"left",
"left",
"right",
]
),
)
def test_10(self):
self.assertEqual(
10,
spin_around(
[
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
"right",
]
),
)
def test_11(self):
self.assertEqual(
10,
spin_around(
[
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
"left",
]
),
)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment