Skip to content

Commit

Permalink
another probelm fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierian-Data committed Feb 18, 2018
1 parent 1efa0fa commit 0f112f7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### LAUGHTER: Write a function that counts the number of times a given pattern appears in a string, *including overlap*\n",
"### Find 33: \n",
"\n",
" laughter('hah','hahahah') --> 3\n",
"Given a list of ints, return True if the array contains a 3 next to a 3 somewhere.\n",
"\n",
"Note that `'hahahah'.count('hah')` only returns 2."
" has_33([1, 3, 3]) → True\n",
" has_33([1, 3, 1, 3]) → False\n",
" has_33([3, 1, 3]) → False"
]
},
{
Expand All @@ -343,7 +345,7 @@
},
"outputs": [],
"source": [
"def laughter(pattern,text):\n",
"def has_33(pattern,text):\n",
" pass"
]
},
Expand All @@ -356,7 +358,7 @@
"outputs": [],
"source": [
"# Check\n",
"laughter('hah','hahahah')"
"has_33([1, 3, 3])"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### LAUGHTER: Write a function that counts the number of times a given pattern appears in a string, *including overlap*\n",
"### Find 33: \n",
"\n",
" laughter('hah','hahahah') --> 3\n",
"Given a list of ints, return True if the array contains a 3 next to a 3 somewhere.\n",
"\n",
"Note that `'hahahah'.count('hah')` only returns 2."
" has_33([1, 3, 3]) → True\n",
" has_33([1, 3, 1, 3]) → False\n",
" has_33([3, 1, 3]) → False"
]
},
{
Expand All @@ -469,12 +471,16 @@
},
"outputs": [],
"source": [
"def laughter(pattern,text):\n",
" out = 0\n",
" for x in range(len(text)-2):\n",
" if text[x:x+len(pattern)] == pattern:\n",
" out += 1\n",
" return out"
"def has_33(nums):\n",
" for i in range(0, len(nums)-1):\n",
" \n",
" # nicer looking alternative in commented code\n",
" #if nums[i] == 2 and nums[i+1] == 2:\n",
" \n",
" if nums[i:i+2] == [2,2]:\n",
" return True \n",
" \n",
" return False"
]
},
{
Expand All @@ -495,7 +501,7 @@
],
"source": [
"# Check\n",
"laughter('hah','hahahah')"
"has_33([1, 3, 3])"
]
},
{
Expand Down Expand Up @@ -983,7 +989,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Just for fun:\n",
"-----\n",
"### Just for fun, not a real problem :)\n",
"\n",
"#### PRINT BIG: Write a function that takes in a single letter, and returns a 5x5 representation of that letter\n",
" print_big('a')\n",
" \n",
Expand Down
12 changes: 7 additions & 5 deletions 03-Methods and Functions/03-Function Practice Exercises.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### LAUGHTER: Write a function that counts the number of times a given pattern appears in a string, *including overlap*\n",
"### Find 33: \n",
"\n",
" laughter('hah','hahahah') --> 3\n",
"Given a list of ints, return True if the array contains a 3 next to a 3 somewhere.\n",
"\n",
"Note that `'hahahah'.count('hah')` only returns 2."
" has_33([1, 3, 3]) → True\n",
" has_33([1, 3, 1, 3]) → False\n",
" has_33([3, 1, 3]) → False"
]
},
{
Expand All @@ -343,7 +345,7 @@
},
"outputs": [],
"source": [
"def laughter(pattern,text):\n",
"def has_33(pattern,text):\n",
" pass"
]
},
Expand All @@ -356,7 +358,7 @@
"outputs": [],
"source": [
"# Check\n",
"laughter('hah','hahahah')"
"has_33([1, 3, 3])"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### LAUGHTER: Write a function that counts the number of times a given pattern appears in a string, *including overlap*\n",
"### Find 33: \n",
"\n",
" laughter('hah','hahahah') --> 3\n",
"Given a list of ints, return True if the array contains a 3 next to a 3 somewhere.\n",
"\n",
"Note that `'hahahah'.count('hah')` only returns 2."
" has_33([1, 3, 3]) → True\n",
" has_33([1, 3, 1, 3]) → False\n",
" has_33([3, 1, 3]) → False"
]
},
{
Expand All @@ -469,12 +471,16 @@
},
"outputs": [],
"source": [
"def laughter(pattern,text):\n",
" out = 0\n",
" for x in range(len(text)-2):\n",
" if text[x:x+len(pattern)] == pattern:\n",
" out += 1\n",
" return out"
"def has_33(nums):\n",
" for i in range(0, len(nums)-1):\n",
" \n",
" # nicer looking alternative in commented code\n",
" #if nums[i] == 2 and nums[i+1] == 2:\n",
" \n",
" if nums[i:i+2] == [2,2]:\n",
" return True \n",
" \n",
" return False"
]
},
{
Expand All @@ -495,7 +501,7 @@
],
"source": [
"# Check\n",
"laughter('hah','hahahah')"
"has_33([1, 3, 3])"
]
},
{
Expand Down Expand Up @@ -983,7 +989,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Just for fun:\n",
"-----\n",
"### Just for fun, not a real problem :)\n",
"\n",
"#### PRINT BIG: Write a function that takes in a single letter, and returns a 5x5 representation of that letter\n",
" print_big('a')\n",
" \n",
Expand Down

0 comments on commit 0f112f7

Please sign in to comment.