mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-08 18:38:03 +00:00
Move xor challenge solution to a class (#143)
This commit is contained in:
@@ -72,9 +72,11 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def max_xor(lower, upper):\n",
|
"class Solution(object):\n",
|
||||||
" # TODO: Implement me\n",
|
"\n",
|
||||||
" pass"
|
" def max_xor(self, lower, upper):\n",
|
||||||
|
" # TODO: Implement me\n",
|
||||||
|
" pass"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -101,7 +103,8 @@
|
|||||||
"class TestMaximingXor(object):\n",
|
"class TestMaximingXor(object):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_maximizing_xor(self):\n",
|
" def test_maximizing_xor(self):\n",
|
||||||
" assert_equal(max_xor(10, 15), 7)\n",
|
" solution = Solution()\n",
|
||||||
|
" assert_equal(solution.max_xor(10, 15), 7)\n",
|
||||||
" print('Success: test_maximizing_xor')\n",
|
" print('Success: test_maximizing_xor')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -126,21 +129,21 @@
|
|||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"display_name": "Python 2",
|
"display_name": "Python 3",
|
||||||
"language": "python",
|
"language": "python",
|
||||||
"name": "python2"
|
"name": "python3"
|
||||||
},
|
},
|
||||||
"language_info": {
|
"language_info": {
|
||||||
"codemirror_mode": {
|
"codemirror_mode": {
|
||||||
"name": "ipython",
|
"name": "ipython",
|
||||||
"version": 2
|
"version": 3
|
||||||
},
|
},
|
||||||
"file_extension": ".py",
|
"file_extension": ".py",
|
||||||
"mimetype": "text/x-python",
|
"mimetype": "text/x-python",
|
||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython2",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "2.7.10"
|
"version": "3.5.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|||||||
@@ -82,14 +82,16 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"def max_xor(lower, upper):\n",
|
"class Solution(object):\n",
|
||||||
" result = 0\n",
|
"\n",
|
||||||
" for l in range(lower, upper + 1):\n",
|
" def max_xor(self, lower, upper):\n",
|
||||||
" for u in range(lower, upper + 1):\n",
|
" result = 0\n",
|
||||||
" curr = l ^ u\n",
|
" for l in range(lower, upper + 1):\n",
|
||||||
" if result < curr:\n",
|
" for u in range(lower, upper + 1):\n",
|
||||||
" result = curr\n",
|
" curr = l ^ u\n",
|
||||||
" return result"
|
" if result < curr:\n",
|
||||||
|
" result = curr\n",
|
||||||
|
" return result"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -123,7 +125,8 @@
|
|||||||
"class TestMaximingXor(object):\n",
|
"class TestMaximingXor(object):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def test_maximizing_xor(self):\n",
|
" def test_maximizing_xor(self):\n",
|
||||||
" assert_equal(max_xor(10, 15), 7)\n",
|
" solution = Solution()\n",
|
||||||
|
" assert_equal(solution.max_xor(10, 15), 7)\n",
|
||||||
" print('Success: test_maximizing_xor')\n",
|
" print('Success: test_maximizing_xor')\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -158,21 +161,21 @@
|
|||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"display_name": "Python 2",
|
"display_name": "Python 3",
|
||||||
"language": "python",
|
"language": "python",
|
||||||
"name": "python2"
|
"name": "python3"
|
||||||
},
|
},
|
||||||
"language_info": {
|
"language_info": {
|
||||||
"codemirror_mode": {
|
"codemirror_mode": {
|
||||||
"name": "ipython",
|
"name": "ipython",
|
||||||
"version": 2
|
"version": 3
|
||||||
},
|
},
|
||||||
"file_extension": ".py",
|
"file_extension": ".py",
|
||||||
"mimetype": "text/x-python",
|
"mimetype": "text/x-python",
|
||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython2",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "2.7.10"
|
"version": "3.5.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ from nose.tools import assert_equal
|
|||||||
class TestMaximingXor(object):
|
class TestMaximingXor(object):
|
||||||
|
|
||||||
def test_maximizing_xor(self):
|
def test_maximizing_xor(self):
|
||||||
assert_equal(max_xor(10, 15), 7)
|
solution = Solution()
|
||||||
|
assert_equal(solution.max_xor(10, 15), 7)
|
||||||
print('Success: test_maximizing_xor')
|
print('Success: test_maximizing_xor')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user