inputs
stringlengths 50
14k
| targets
stringlengths 4
655k
|
|---|---|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
new_string = ''
for c in s:
new_string = new_string + c + c
return new_string
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return ''.join(''.join(i) for i in zip(s, s))
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
final_str = ""
for char in s:
final_str += (char + char)
return final_str
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
new_str = ''
for i in s:
new_str = new_str + i + i
return new_str
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
solution = ''
for char in s:
solution += char * 2
return solution
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
res = map(lambda x: x *2, s)
res = ''.join(res)
return res
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return "".join(map(lambda i: i+i, s))
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
from itertools import repeat
def double_char(s):
return ''.join([x for item in s for x in repeat(item, 2)])
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
a=""
for i in s:
i=i*2
a+=i
return a
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
x = ''
return x.join(i * 2 for i in s)
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
aç = ""
for a in s:
aç += a*2
return aç
|
Given a string, you have to return a string in which each character (case-sensitive) is repeated once.
```python
double_char("String") ==> "SSttrriinngg"
double_char("Hello World") ==> "HHeelllloo WWoorrlldd"
double_char("1234!_ ") ==> "11223344!!__ "
```
Good Luck!
|
def double_char(s):
return ''.join(x * 2 for x in list(s[:]))
|
A circle is defined by three coplanar points that are not aligned.
You will be given a list of circles and a point [xP, yP]. You have to create a function, ```count_circles()``` (Javascript ```countCircles()```), that will count the amount of circles that contains the point P inside (the circle border line is included).
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point1 = [1, 4] # P1
count_circles(list_of_circles, point1) == 4 #(The four circles have P1 inside)
```
It may happen that the point may be external to all the circles.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[-3,2],[2,6], [6,4]]]
point2 = [10, 6] # P2
count_circles(list_of_circles, point2) == 0 #(P2 is exterior to the four circles)
```
The point may be in the circle line and that will be consider as an internal point of it, too.
For practical purposes a given point ```P``` will be in the circle line if:
|r - d|/r < 10^(-10)
```r```: radius of the circle that should be calculated from the coordinates of the three given points.
```d```: distance from the point ```P``` to the center of the circle. Again we have to do a calculation, the coordinates of the center should be calculated using the coordinates of the three given points.
Let's see a case when the pints is in the circle line.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point3 = point2 = [2, 6] # P3
count_circles(list_of_circles, point3) == 4 #(P3 is an internal point of the four circles)
```
All these three cases are shown in the image below:
Your code should be able to skip these cases:
- inexistent circle when we have three points aligned
- undefined circles when two or three of given points coincides.
First ten people to solve it will receive extra points.
Hints: This kata will give you important formulas: ```Give The Center And The Radius of Circumscribed Circle. (A warm up challenge)```
```http://www.codewars.com/kata/give-the-center-and-the-radius-of-circumscribed-circle-a-warm-up-challenge```
Features of the tests:
```N: amount of Tests```
```n: amount of given circles```
```x, y: coordinates of the points that define the circle```
```xP, yP: coordinates of the point P```
```N = 500```
```10 < n < 500```
```-500 < x < 500, -500 < y < 500```
```-750 < xP < -750, -750 < yP < -750```
|
def circum_curvat(points):
A, B, C = [complex(*p) for p in points]
BC, CA, AB = B - C, C - A, A - B
D = 2. * (A.real * BC + B.real * CA + C.real * AB).imag
if not D: return D, D
U = (abs(A)**2 * BC + abs(B)**2 * CA + abs(C)**2 * AB) / D
radius = (abs(BC) * abs(CA) * abs(AB)) / abs(D)
return -1j * U, radius
def count_circles(circles, point):
return sum(abs(complex(*point) - center) < radius
for center, radius in map(circum_curvat, circles))
|
A circle is defined by three coplanar points that are not aligned.
You will be given a list of circles and a point [xP, yP]. You have to create a function, ```count_circles()``` (Javascript ```countCircles()```), that will count the amount of circles that contains the point P inside (the circle border line is included).
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point1 = [1, 4] # P1
count_circles(list_of_circles, point1) == 4 #(The four circles have P1 inside)
```
It may happen that the point may be external to all the circles.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[-3,2],[2,6], [6,4]]]
point2 = [10, 6] # P2
count_circles(list_of_circles, point2) == 0 #(P2 is exterior to the four circles)
```
The point may be in the circle line and that will be consider as an internal point of it, too.
For practical purposes a given point ```P``` will be in the circle line if:
|r - d|/r < 10^(-10)
```r```: radius of the circle that should be calculated from the coordinates of the three given points.
```d```: distance from the point ```P``` to the center of the circle. Again we have to do a calculation, the coordinates of the center should be calculated using the coordinates of the three given points.
Let's see a case when the pints is in the circle line.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point3 = point2 = [2, 6] # P3
count_circles(list_of_circles, point3) == 4 #(P3 is an internal point of the four circles)
```
All these three cases are shown in the image below:
Your code should be able to skip these cases:
- inexistent circle when we have three points aligned
- undefined circles when two or three of given points coincides.
First ten people to solve it will receive extra points.
Hints: This kata will give you important formulas: ```Give The Center And The Radius of Circumscribed Circle. (A warm up challenge)```
```http://www.codewars.com/kata/give-the-center-and-the-radius-of-circumscribed-circle-a-warm-up-challenge```
Features of the tests:
```N: amount of Tests```
```n: amount of given circles```
```x, y: coordinates of the points that define the circle```
```xP, yP: coordinates of the point P```
```N = 500```
```10 < n < 500```
```-500 < x < 500, -500 < y < 500```
```-750 < xP < -750, -750 < yP < -750```
|
def count_circles(circles, point):
return sum(inside(circle_xyr(circle), point) for circle in circles)
def inside(xyr, pt):
if xyr is None: return False
x, y, r = xyr
return dist(pt, (x, y)) <= r
def circle_xyr(pts):
if len(pts) != 3: return None
m1, c1 = perpbisector(pts[0], pts[1])
m2, c2 = perpbisector(pts[0], pts[2])
if m1 == m2: return None
x, y = (c1, m2*c1 + c2) if m1 is None else (c2, m1*c2 + c1) if m2 is None else ((c2 - c1)/(m1 - m2), m1*(c2 - c1)/(m1 - m2) + c1)
return x, y, dist(pts[0], (x, y))
def perpbisector(a, b):
ax, ay = a
bx, by = b
mpx, mpy = (ax + bx) / 2.0, (ay + by) / 2.0
if ax == bx: return 0, mpy
if ay == by: return None, mpx
m = (ax - bx) / float(by - ay)
c = mpy - m * mpx
return m, c
def dist(a, b):
return round(((a[0] - b[0])**2 + (a[1] - b[1])**2)**0.5, 8)
|
A circle is defined by three coplanar points that are not aligned.
You will be given a list of circles and a point [xP, yP]. You have to create a function, ```count_circles()``` (Javascript ```countCircles()```), that will count the amount of circles that contains the point P inside (the circle border line is included).
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point1 = [1, 4] # P1
count_circles(list_of_circles, point1) == 4 #(The four circles have P1 inside)
```
It may happen that the point may be external to all the circles.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[-3,2],[2,6], [6,4]]]
point2 = [10, 6] # P2
count_circles(list_of_circles, point2) == 0 #(P2 is exterior to the four circles)
```
The point may be in the circle line and that will be consider as an internal point of it, too.
For practical purposes a given point ```P``` will be in the circle line if:
|r - d|/r < 10^(-10)
```r```: radius of the circle that should be calculated from the coordinates of the three given points.
```d```: distance from the point ```P``` to the center of the circle. Again we have to do a calculation, the coordinates of the center should be calculated using the coordinates of the three given points.
Let's see a case when the pints is in the circle line.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point3 = point2 = [2, 6] # P3
count_circles(list_of_circles, point3) == 4 #(P3 is an internal point of the four circles)
```
All these three cases are shown in the image below:
Your code should be able to skip these cases:
- inexistent circle when we have three points aligned
- undefined circles when two or three of given points coincides.
First ten people to solve it will receive extra points.
Hints: This kata will give you important formulas: ```Give The Center And The Radius of Circumscribed Circle. (A warm up challenge)```
```http://www.codewars.com/kata/give-the-center-and-the-radius-of-circumscribed-circle-a-warm-up-challenge```
Features of the tests:
```N: amount of Tests```
```n: amount of given circles```
```x, y: coordinates of the points that define the circle```
```xP, yP: coordinates of the point P```
```N = 500```
```10 < n < 500```
```-500 < x < 500, -500 < y < 500```
```-750 < xP < -750, -750 < yP < -750```
|
def count_circles(list_of_circles, point, count = 0):
return sum(1 for circle in list_of_circles if point_in(circle, point))
def point_in(points, point):
helper = lambda x,y: (-1)**y*(points[(x+1)%3][(y+1)%2] - points[(x+2)%3][(y+1)%2])
D = 2*sum(points[i][0]*helper(i,0) for i in range(3))
U = [1.0 * sum(sum(points[i][j]**2 for j in range(2))*helper(i,k) for i in range(3))/D for k in range(2)]
return compare(point, U, radius(points,D)) if (not invalid(points, D)) else False
compare = lambda p, U, r: ((distance(U,p) < r) or (abs(r-distance(U,p))/r < 10**-10))
distance = lambda p1, p2: ((p2[0] - p1[0])**2 + (p2[1] - p1[1])**2)**0.5
invalid = lambda p, D: ((D == 0) or (p[0] == p[1]) or (p[0] == p[2]) or (p[1] == p[2]))
radius = lambda p, D: distance(p[0],p[1])*distance(p[0],p[2])*distance(p[1],p[2])/abs(D)
|
A circle is defined by three coplanar points that are not aligned.
You will be given a list of circles and a point [xP, yP]. You have to create a function, ```count_circles()``` (Javascript ```countCircles()```), that will count the amount of circles that contains the point P inside (the circle border line is included).
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point1 = [1, 4] # P1
count_circles(list_of_circles, point1) == 4 #(The four circles have P1 inside)
```
It may happen that the point may be external to all the circles.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[-3,2],[2,6], [6,4]]]
point2 = [10, 6] # P2
count_circles(list_of_circles, point2) == 0 #(P2 is exterior to the four circles)
```
The point may be in the circle line and that will be consider as an internal point of it, too.
For practical purposes a given point ```P``` will be in the circle line if:
|r - d|/r < 10^(-10)
```r```: radius of the circle that should be calculated from the coordinates of the three given points.
```d```: distance from the point ```P``` to the center of the circle. Again we have to do a calculation, the coordinates of the center should be calculated using the coordinates of the three given points.
Let's see a case when the pints is in the circle line.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point3 = point2 = [2, 6] # P3
count_circles(list_of_circles, point3) == 4 #(P3 is an internal point of the four circles)
```
All these three cases are shown in the image below:
Your code should be able to skip these cases:
- inexistent circle when we have three points aligned
- undefined circles when two or three of given points coincides.
First ten people to solve it will receive extra points.
Hints: This kata will give you important formulas: ```Give The Center And The Radius of Circumscribed Circle. (A warm up challenge)```
```http://www.codewars.com/kata/give-the-center-and-the-radius-of-circumscribed-circle-a-warm-up-challenge```
Features of the tests:
```N: amount of Tests```
```n: amount of given circles```
```x, y: coordinates of the points that define the circle```
```xP, yP: coordinates of the point P```
```N = 500```
```10 < n < 500```
```-500 < x < 500, -500 < y < 500```
```-750 < xP < -750, -750 < yP < -750```
|
import math
def count_circles(loc, point):
c=0; px,py=point
for i in range (0,len(loc)):
circle=circum_curvat(loc[i][0],loc[i][1],loc[i][2])
if circle!=False:
x,y,r=circle
d=((x-px)**2+(y-py)**2)**.5
if d<=r+1e-10: c+=1
return c
def circum_curvat(pointA, pointB, pointC):
xA,yA=pointA; xB,yB=pointB; xC,yC=pointC
if pointA==pointB or pointA==pointC or pointC==pointB: return False
x=(xA**2+yA**2)*(yB-yC)+(xB**2+yB**2)*(yC-yA)+(xC**2+yC**2)*(yA-yB)
y=(xA**2+yA**2)*(xC-xB)+(xB**2+yB**2)*(xA-xC)+(xC**2+yC**2)*(xB-xA)
AB=((xB-xA)**2+(yB-yA)**2)**.5; BC=((xC-xB)**2+(yC-yB)**2)**.5; AC=((xC-xA)**2+(yC-yA)**2)**.5
D=2.0*(xA*(yB-yC)+xB*(yC-yA)+xC*(yA-yB))
if D==0: return False
Ux=x/D; Uy=y/D
if D<0: D=-D
diam=AB*BC*AC/D
return [Ux,Uy,diam]
|
A circle is defined by three coplanar points that are not aligned.
You will be given a list of circles and a point [xP, yP]. You have to create a function, ```count_circles()``` (Javascript ```countCircles()```), that will count the amount of circles that contains the point P inside (the circle border line is included).
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point1 = [1, 4] # P1
count_circles(list_of_circles, point1) == 4 #(The four circles have P1 inside)
```
It may happen that the point may be external to all the circles.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[-3,2],[2,6], [6,4]]]
point2 = [10, 6] # P2
count_circles(list_of_circles, point2) == 0 #(P2 is exterior to the four circles)
```
The point may be in the circle line and that will be consider as an internal point of it, too.
For practical purposes a given point ```P``` will be in the circle line if:
|r - d|/r < 10^(-10)
```r```: radius of the circle that should be calculated from the coordinates of the three given points.
```d```: distance from the point ```P``` to the center of the circle. Again we have to do a calculation, the coordinates of the center should be calculated using the coordinates of the three given points.
Let's see a case when the pints is in the circle line.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point3 = point2 = [2, 6] # P3
count_circles(list_of_circles, point3) == 4 #(P3 is an internal point of the four circles)
```
All these three cases are shown in the image below:
Your code should be able to skip these cases:
- inexistent circle when we have three points aligned
- undefined circles when two or three of given points coincides.
First ten people to solve it will receive extra points.
Hints: This kata will give you important formulas: ```Give The Center And The Radius of Circumscribed Circle. (A warm up challenge)```
```http://www.codewars.com/kata/give-the-center-and-the-radius-of-circumscribed-circle-a-warm-up-challenge```
Features of the tests:
```N: amount of Tests```
```n: amount of given circles```
```x, y: coordinates of the points that define the circle```
```xP, yP: coordinates of the point P```
```N = 500```
```10 < n < 500```
```-500 < x < 500, -500 < y < 500```
```-750 < xP < -750, -750 < yP < -750```
|
def dist(pointA, pointB):
return ((pointB[0] - pointA[0])**2 + (pointB[1] - pointA[1])**2)**.5
def contains(circle, point):
return circle and 0 <= circle['r'] - dist(point, circle['c']) <= circle['r'] or abs(circle['r'] - dist(point, circle['c'])) / circle['r'] < 1e-10
def circum_curvat(points):
if len(set(map(tuple, points))) != 3: return None
xa, ya, xb, yb, xc, yc = points[0][0], points[0][1], points[1][0], points[1][1], points[2][0], points[2][1]
D = 2. * (xa * (yb - yc) + xb * (yc - ya) + xc * (ya - yb))
if not D: return None
Ux = ((xa**2 + ya**2)*(yb - yc) + (xb**2 + yb**2)*(yc - ya) + (xc**2 + yc**2)*(ya - yb)) / D
Uy = ((xa**2 + ya**2)*(xc - xb) + (xb**2 + yb**2)*(xa - xc) + (xc**2 + yc**2)*(xb - xa)) / D
rad = dist(points[0], points[1]) * dist(points[1], points[2]) * dist(points[0], points[2]) / abs(D)
return {'c': (Ux, Uy), 'r': rad}
def count_circles(list_of_circles, point):
return len(filter(None, (contains(circum_curvat(p), point) for p in list_of_circles)))
|
A circle is defined by three coplanar points that are not aligned.
You will be given a list of circles and a point [xP, yP]. You have to create a function, ```count_circles()``` (Javascript ```countCircles()```), that will count the amount of circles that contains the point P inside (the circle border line is included).
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point1 = [1, 4] # P1
count_circles(list_of_circles, point1) == 4 #(The four circles have P1 inside)
```
It may happen that the point may be external to all the circles.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[-3,2],[2,6], [6,4]]]
point2 = [10, 6] # P2
count_circles(list_of_circles, point2) == 0 #(P2 is exterior to the four circles)
```
The point may be in the circle line and that will be consider as an internal point of it, too.
For practical purposes a given point ```P``` will be in the circle line if:
|r - d|/r < 10^(-10)
```r```: radius of the circle that should be calculated from the coordinates of the three given points.
```d```: distance from the point ```P``` to the center of the circle. Again we have to do a calculation, the coordinates of the center should be calculated using the coordinates of the three given points.
Let's see a case when the pints is in the circle line.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point3 = point2 = [2, 6] # P3
count_circles(list_of_circles, point3) == 4 #(P3 is an internal point of the four circles)
```
All these three cases are shown in the image below:
Your code should be able to skip these cases:
- inexistent circle when we have three points aligned
- undefined circles when two or three of given points coincides.
First ten people to solve it will receive extra points.
Hints: This kata will give you important formulas: ```Give The Center And The Radius of Circumscribed Circle. (A warm up challenge)```
```http://www.codewars.com/kata/give-the-center-and-the-radius-of-circumscribed-circle-a-warm-up-challenge```
Features of the tests:
```N: amount of Tests```
```n: amount of given circles```
```x, y: coordinates of the points that define the circle```
```xP, yP: coordinates of the point P```
```N = 500```
```10 < n < 500```
```-500 < x < 500, -500 < y < 500```
```-750 < xP < -750, -750 < yP < -750```
|
import math
def get_center_radius(points):
x = [pt[0] for pt in points]
y = [pt[1] for pt in points]
A = x[0]*(y[1]-y[2]) - y[0]*(x[1]-x[2]) + x[1]*y[2] - x[2]*y[1]
B = (x[0]**2 + y[0]**2)*(y[2]-y[1]) + (x[1]**2 + y[1]**2)*(y[0]-y[2]) + (x[2]**2 + y[2]**2)*(y[1]-y[0])
C = (x[0]**2 + y[0]**2)*(x[1]-x[2]) + (x[1]**2 + y[1]**2)*(x[2]-x[0]) + (x[2]**2 + y[2]**2)*(x[0]-x[1])
D = (x[0]**2 + y[0]**2)*(x[2]*y[1]-x[1]*y[2]) + (x[1]**2 + y[1]**2)*(x[0]*y[2]-x[2]*y[0]) + (x[2]**2 + y[2]**2)*(x[1]*y[0]-x[0]*y[1])
return -B/(2*A), -C/(2*A), ((B**2+C**2-4*A*D)/(4*A**2))**.5
def count_circles(list_of_circles, point):
counter = 0
for circle in list_of_circles:
xc, yc, r = get_center_radius(circle)
d = math.hypot(xc - point[0], yc - point[1])
counter += 1 if d < r or abs(d-r)/r < 10**-10 else 0
return counter
|
A circle is defined by three coplanar points that are not aligned.
You will be given a list of circles and a point [xP, yP]. You have to create a function, ```count_circles()``` (Javascript ```countCircles()```), that will count the amount of circles that contains the point P inside (the circle border line is included).
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point1 = [1, 4] # P1
count_circles(list_of_circles, point1) == 4 #(The four circles have P1 inside)
```
It may happen that the point may be external to all the circles.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[-3,2],[2,6], [6,4]]]
point2 = [10, 6] # P2
count_circles(list_of_circles, point2) == 0 #(P2 is exterior to the four circles)
```
The point may be in the circle line and that will be consider as an internal point of it, too.
For practical purposes a given point ```P``` will be in the circle line if:
|r - d|/r < 10^(-10)
```r```: radius of the circle that should be calculated from the coordinates of the three given points.
```d```: distance from the point ```P``` to the center of the circle. Again we have to do a calculation, the coordinates of the center should be calculated using the coordinates of the three given points.
Let's see a case when the pints is in the circle line.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point3 = point2 = [2, 6] # P3
count_circles(list_of_circles, point3) == 4 #(P3 is an internal point of the four circles)
```
All these three cases are shown in the image below:
Your code should be able to skip these cases:
- inexistent circle when we have three points aligned
- undefined circles when two or three of given points coincides.
First ten people to solve it will receive extra points.
Hints: This kata will give you important formulas: ```Give The Center And The Radius of Circumscribed Circle. (A warm up challenge)```
```http://www.codewars.com/kata/give-the-center-and-the-radius-of-circumscribed-circle-a-warm-up-challenge```
Features of the tests:
```N: amount of Tests```
```n: amount of given circles```
```x, y: coordinates of the points that define the circle```
```xP, yP: coordinates of the point P```
```N = 500```
```10 < n < 500```
```-500 < x < 500, -500 < y < 500```
```-750 < xP < -750, -750 < yP < -750```
|
import math
def circum_curvat(pointA, pointB, pointC):
#if len({pointA, pointB, pointC})<3:
# return (0,0,0)
D = 2*(pointA[0]*(pointB[1]-pointC[1])+pointB[0]*(pointC[1]-pointA[1])+pointC[0]*(pointA[1]-pointB[1]))
if abs(D)<1e-10:
return (0,0,0)
x = ((pointA[0]**2+pointA[1]**2)*(pointB[1]-pointC[1])+
(pointB[0]**2+pointB[1]**2)*(pointC[1]-pointA[1])+
(pointC[0]**2+pointC[1]**2)*(pointA[1]-pointB[1])
)/D
y = ((pointA[0]**2+pointA[1]**2)*(pointC[0]-pointB[0])+
(pointB[0]**2+pointB[1]**2)*(pointA[0]-pointC[0])+
(pointC[0]**2+pointC[1]**2)*(pointB[0]-pointA[0])
)/D
ab = math.hypot(pointB[0]-pointA[0],pointB[1]-pointA[1])
bc = math.hypot(pointB[0]-pointC[0],pointB[1]-pointC[1])
ac = math.hypot(pointC[0]-pointA[0],pointC[1]-pointA[1])
radius = ab*bc*ac/abs(D)
return (x, y, radius)
def count_circles(list_of_circles, point):
result = 0
for circles in list_of_circles:
x,y,r = circum_curvat(*circles)
if r-math.hypot(point[0]-x,point[1]-y)>-1e-10:
result += 1
return result
|
A circle is defined by three coplanar points that are not aligned.
You will be given a list of circles and a point [xP, yP]. You have to create a function, ```count_circles()``` (Javascript ```countCircles()```), that will count the amount of circles that contains the point P inside (the circle border line is included).
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point1 = [1, 4] # P1
count_circles(list_of_circles, point1) == 4 #(The four circles have P1 inside)
```
It may happen that the point may be external to all the circles.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[-3,2],[2,6], [6,4]]]
point2 = [10, 6] # P2
count_circles(list_of_circles, point2) == 0 #(P2 is exterior to the four circles)
```
The point may be in the circle line and that will be consider as an internal point of it, too.
For practical purposes a given point ```P``` will be in the circle line if:
|r - d|/r < 10^(-10)
```r```: radius of the circle that should be calculated from the coordinates of the three given points.
```d```: distance from the point ```P``` to the center of the circle. Again we have to do a calculation, the coordinates of the center should be calculated using the coordinates of the three given points.
Let's see a case when the pints is in the circle line.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point3 = point2 = [2, 6] # P3
count_circles(list_of_circles, point3) == 4 #(P3 is an internal point of the four circles)
```
All these three cases are shown in the image below:
Your code should be able to skip these cases:
- inexistent circle when we have three points aligned
- undefined circles when two or three of given points coincides.
First ten people to solve it will receive extra points.
Hints: This kata will give you important formulas: ```Give The Center And The Radius of Circumscribed Circle. (A warm up challenge)```
```http://www.codewars.com/kata/give-the-center-and-the-radius-of-circumscribed-circle-a-warm-up-challenge```
Features of the tests:
```N: amount of Tests```
```n: amount of given circles```
```x, y: coordinates of the points that define the circle```
```xP, yP: coordinates of the point P```
```N = 500```
```10 < n < 500```
```-500 < x < 500, -500 < y < 500```
```-750 < xP < -750, -750 < yP < -750```
|
from __future__ import division
from numpy import *
def find_circle(a, b, c):
if any(map(array_equal, (a, b, c), (b, c, a))): return
(ax, ay), (bx, by), (cx, cy) = a, b, c
d = ax * (by - cy) + bx * (cy - ay) + cx * (ay - by) << 1
if not d: return
t1, t2, t3 = (ax**2 + ay**2), (bx**2 + by**2), (cx**2 + cy**2)
x = (t1*(by - cy) + t2*(cy - ay) + t3*(ay - by)) / d
y = (t1*(cx - bx) + t2*(ax - cx) + t3*(bx - ax)) / d
ab, bc, ca = linalg.norm(a - b), linalg.norm(b - c), linalg.norm(c - a)
return x, y, ab*bc*ca / abs(d)
def count_circles(list_of_circles, point):
(px, py), result = point, 0
for circle in list_of_circles:
if point in circle:
result += 1
else:
res = find_circle(*map(array, circle))
result += res and (px - res[0])**2 + (py - res[1])**2 <= res[2]**2
return result
|
A circle is defined by three coplanar points that are not aligned.
You will be given a list of circles and a point [xP, yP]. You have to create a function, ```count_circles()``` (Javascript ```countCircles()```), that will count the amount of circles that contains the point P inside (the circle border line is included).
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point1 = [1, 4] # P1
count_circles(list_of_circles, point1) == 4 #(The four circles have P1 inside)
```
It may happen that the point may be external to all the circles.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[-3,2],[2,6], [6,4]]]
point2 = [10, 6] # P2
count_circles(list_of_circles, point2) == 0 #(P2 is exterior to the four circles)
```
The point may be in the circle line and that will be consider as an internal point of it, too.
For practical purposes a given point ```P``` will be in the circle line if:
|r - d|/r < 10^(-10)
```r```: radius of the circle that should be calculated from the coordinates of the three given points.
```d```: distance from the point ```P``` to the center of the circle. Again we have to do a calculation, the coordinates of the center should be calculated using the coordinates of the three given points.
Let's see a case when the pints is in the circle line.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point3 = point2 = [2, 6] # P3
count_circles(list_of_circles, point3) == 4 #(P3 is an internal point of the four circles)
```
All these three cases are shown in the image below:
Your code should be able to skip these cases:
- inexistent circle when we have three points aligned
- undefined circles when two or three of given points coincides.
First ten people to solve it will receive extra points.
Hints: This kata will give you important formulas: ```Give The Center And The Radius of Circumscribed Circle. (A warm up challenge)```
```http://www.codewars.com/kata/give-the-center-and-the-radius-of-circumscribed-circle-a-warm-up-challenge```
Features of the tests:
```N: amount of Tests```
```n: amount of given circles```
```x, y: coordinates of the points that define the circle```
```xP, yP: coordinates of the point P```
```N = 500```
```10 < n < 500```
```-500 < x < 500, -500 < y < 500```
```-750 < xP < -750, -750 < yP < -750```
|
def count_circles(list_of_circles, point):
c=0
for circle in list_of_circles:
(x1,y1),(x2,y2),(x3,y3)=circle[0],circle[1],circle[2]
x=(x2**2+y2**2-x1**2-y1**2)*(y3-y1)-(x3**2+y3**2-x1**2-y1**2)*(y2-y1)
x/=2.0*((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))
y=(x2**2+y2**2-x1**2-y1**2)*(y3-y1)-2*(x2-x1)*(y3-y1)*x
y/=2.0*(y2-y1)*(y3-y1)
r=((x1-x)**2+(y1-y)**2)**0.5
d=((x-point[0])**2+(y-point[1])**2)**0.5
if d<=r or abs(r-d)<=10e-10:
c+=1
return c
|
A circle is defined by three coplanar points that are not aligned.
You will be given a list of circles and a point [xP, yP]. You have to create a function, ```count_circles()``` (Javascript ```countCircles()```), that will count the amount of circles that contains the point P inside (the circle border line is included).
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point1 = [1, 4] # P1
count_circles(list_of_circles, point1) == 4 #(The four circles have P1 inside)
```
It may happen that the point may be external to all the circles.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[-3,2],[2,6], [6,4]]]
point2 = [10, 6] # P2
count_circles(list_of_circles, point2) == 0 #(P2 is exterior to the four circles)
```
The point may be in the circle line and that will be consider as an internal point of it, too.
For practical purposes a given point ```P``` will be in the circle line if:
|r - d|/r < 10^(-10)
```r```: radius of the circle that should be calculated from the coordinates of the three given points.
```d```: distance from the point ```P``` to the center of the circle. Again we have to do a calculation, the coordinates of the center should be calculated using the coordinates of the three given points.
Let's see a case when the pints is in the circle line.
```python
list_of_circles = ([[[-3,2], [1,1], [6,4]], [[-3,2], [1,1], [2,6]], [[1,1], [2,6], [6,4]], [[[-3,2],[2,6], [6,4]]]
point3 = point2 = [2, 6] # P3
count_circles(list_of_circles, point3) == 4 #(P3 is an internal point of the four circles)
```
All these three cases are shown in the image below:
Your code should be able to skip these cases:
- inexistent circle when we have three points aligned
- undefined circles when two or three of given points coincides.
First ten people to solve it will receive extra points.
Hints: This kata will give you important formulas: ```Give The Center And The Radius of Circumscribed Circle. (A warm up challenge)```
```http://www.codewars.com/kata/give-the-center-and-the-radius-of-circumscribed-circle-a-warm-up-challenge```
Features of the tests:
```N: amount of Tests```
```n: amount of given circles```
```x, y: coordinates of the points that define the circle```
```xP, yP: coordinates of the point P```
```N = 500```
```10 < n < 500```
```-500 < x < 500, -500 < y < 500```
```-750 < xP < -750, -750 < yP < -750```
|
from math import sqrt, hypot
def count_circles(list_of_circles, point):
count = int(any(point in c for c in list_of_circles))
for [[x1, y1], [x2, y2], [x3, y3]] in list_of_circles:
A = x1 * (y2 - y3) - y1 * (x2 - x3) + x2 * y3 - x3 * y2
B = (x1 * x1 + y1 * y1) * (y3 - y2) + (x2 * x2 + y2 * y2) * (y1 - y3) + (x3 * x3 + y3 * y3) * (y2 - y1)
C = (x1 * x1 + y1 * y1) * (x2 - x3) + (x2 * x2 + y2 * y2) * (x3 - x1) + (x3 * x3 + y3 * y3) * (x1 - x2)
D = (x1 * x1 + y1 * y1) * (x3 * y2 - x2 * y3) + (x2 * x2 + y2 * y2) * (x1 * y3 - x3 * y1) + (x3 * x3 + y3 * y3) * (x2 * y1 - x1 * y2)
[A, B, C, D] = map(float, [A, B, C, D])
xc, yc = -B / (2 * A), -C / (2 * A)
r = sqrt((B * B + C * C - 4 * A * D) / (4 * A * A))
d = hypot(point[0] - xc, point[1] - yc)
if d <= r: count += 1
return count
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(s):
return "\n".join(line[::-1] for line in s.split("\n"))
def hor_mirror(s):
return "\n".join(s.split("\n")[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return map(reversed, strng)
def hor_mirror(strng):
return reversed(strng)
def oper(fct, s):
return '\n'.join(map(''.join, fct(s.split('\n'))))
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def hor_mirror(s):
return '\n'.join(reversed(s.split('\n')))
def vert_mirror(s):
return '\n'.join(a[::-1] for a in s.split('\n'))
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
vert_mirror,hor_mirror,oper=lambda s:[e[::-1]for e in s],lambda s:s[::-1],lambda f,s:'\n'.join(f(s.split()))
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return "\n".join(w[::-1] for w in strng.split("\n"))
def hor_mirror(strng):
return "\n".join(strng.split("\n")[::-1])
def oper(fct, strng):
return fct(strng)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
lst_string = strng.split('\n')
i = 0
while i < len(lst_string):
lst_string[i] = lst_string[i][::-1]
i += 1
return '\n'.join(lst_string)
def hor_mirror(strng):
lst_string = strng.split('\n')
i = 0
l = len(lst_string)
while i < l//2:
fst_s = lst_string[i]
lst_string[i] = lst_string[l-1-i]
lst_string[l-1-i] = fst_s
i += 1
return '\n'.join(lst_string)
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return '\n'.join(s[::-1] for s in strng.split('\n'))
def hor_mirror(strng):
return'\n'.join(strng.split('\n')[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
hor_mirror = reversed
vert_mirror = lambda st: (i[::-1] for i in st)
def oper(fct, s):
return '\n'.join(fct(s.split('\n')))
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(st):
return (i[::-1] for i in st)
def hor_mirror(st):
return st[::-1]
def oper(fct, s):
return '\n'.join(fct(s.split('\n')))
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return [x[::-1] for x in strng.split("\n")]
def hor_mirror(strng):
return strng.split("\n")[::-1]
def oper(fct, s):
return '\n'.join(list(map(fct, [s]))[0])
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return (s[::-1] for s in strng.split('\n'))
def hor_mirror(strng):
return strng.split('\n')[::-1]
def oper(fct, s):
return '\n'.join(fct(s))
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def format_to_list(string):
return string.split('\n')
def stitch(array):
return '\n'.join(array)
def vert_mirror(string):
matrix = format_to_list(string)
mirrored_matrix = []
for row in matrix:
mirrored_row = row[::-1]
mirrored_matrix.append(mirrored_row)
return stitch(mirrored_matrix)
def hor_mirror(string):
matrix = format_to_list(string)
matrix.reverse()
return stitch(matrix)
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(str_):
return "\n".join(word[::-1] for word in str_.split("\n"))
def hor_mirror(str_):
return "\n".join(str_.split("\n")[::-1])
def oper(fct, str_):
return fct(str_)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return '\n'.join(s[::-1] for s in strng.split('\n'))
def hor_mirror(strng):
return '\n'.join(reversed(strng.split('\n')))
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return '\n'.join([s[::-1] for s in strng.split('\n')])
def hor_mirror(strng):
return '\n'.join(strng.split('\n')[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(lines):
return '\n'.join(line[::-1] for line in lines.split('\n'))
def hor_mirror(lines):
return '\n'.join(lines.split('\n')[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return "\n".join([x[::-1] for x in strng.split("\n")])
def hor_mirror(strng):
return "\n".join(strng.split("\n")[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
hor_mirror, vert_mirror, oper = reversed, lambda m: map(reversed, m), lambda f, s: "\n".join(map("".join, f(s.split("\n"))))
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
s = strng.split("\n")
rs = ["".join(reversed(x)) for x in s]
return "\n".join(rs)
def hor_mirror(strng):
s = strng.split("\n")
rs = [x for x in reversed(s)]
return "\n".join(rs)
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(l):
return [x[::-1] for x in l]
def hor_mirror(l):
return l[::-1]
def oper(fct, s):
return '\n'.join(fct(s.split()))
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
# your code
x = [i[::-1] for i in strng.split('\n')]
return '\n'.join(x)
def hor_mirror(strng):
# your code
a = strng[::-1]
x = [i[::-1] for i in a.split('\n')]
return '\n'.join(x)
def oper(fct, s):
# your code
if fct == hor_mirror:
return hor_mirror(s)
else:
return vert_mirror(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
k=[i[::-1] for i in strng.split('\n')]
return '\n'.join(k)
def hor_mirror(strng):
l=strng.split('\n')[::-1]
return '\n'.join(l)
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return "\n".join(word[::-1] for word in strng.split('\n'))
def hor_mirror(strng):
return "\n".join(reversed(strng.split('\n')))
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return "\n".join("".join(word[i] for i in range(len(word)-1, -1, -1)) for word in strng.split('\n'))
def hor_mirror(strng):
return "\n".join(word for word in reversed(strng.split('\n')))
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return '\n'.join(i[::-1] for i in strng)
def hor_mirror(strng):
return '\n'.join(i for i in strng[::-1])
def oper(fct, s):
return fct(s.split('\n'))
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return '\n'.join(i[::-1] for i in strng.split('\n'))
def hor_mirror(strng):
return '\n'.join(''.join(i) for i in [(c for c in word) for word in strng.split('\n')][::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
import unittest
def vert_mirror(strng):
return '\n'.join(word[::-1] for word in strng.split('\n'))
def hor_mirror(strng):
return '\n'.join(strng.split('\n')[::-1])
def oper(fct, s):
return fct(s)
class TestVertAndHorMirror(unittest.TestCase):
def test_vert_mirror(self):
fct, s = vert_mirror, "hSgdHQ\nHnDMao\nClNNxX\niRvxxH\nbqTVvA\nwvSyRu"
actual = oper(fct, s)
self.assertEqual(actual, "QHdgSh\noaMDnH\nXxNNlC\nHxxvRi\nAvVTqb\nuRySvw")
def test_hor_mirror(self):
fct, s = hor_mirror, "lVHt\nJVhv\nCSbg\nyeCt"
actual = oper(fct, s)
self.assertEqual(actual, "yeCt\nCSbg\nJVhv\nlVHt")
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def reverse_str(str):
return str[::-1]
def vert_mirror(strng):
string_list = strng.split("\n")
result = ""
for i, element in enumerate(string_list):
result = result + reverse_str(element)
if i != len(string_list) - 1:
result += "\n"
return result
def hor_mirror(strng):
string_list = strng.split("\n")
result = ""
for i, element in enumerate(string_list):
result = element + result
if i != len(string_list) - 1:
result = "\n" + result
return result
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
strng = strng.split("\n")
res = []
for substr in strng:
res.append(substr[::-1])
res = '\n'.join(res)
return res
def hor_mirror(strng):
strng = strng.split("\n")
res = []
for index in range(len(strng)):
res.append(strng[len(strng) - index - 1])
res = '\n'.join(res)
return res
def oper(fct, s):
if (fct == vert_mirror):
return vert_mirror(s)
elif (fct == hor_mirror):
return hor_mirror(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
vert_mirror = lambda strng: '\n'.join(i[::-1] for i in strng.split())
hor_mirror = lambda strng: '\n'.join(strng.split()[::-1])
oper = lambda fct, s: fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return '\n'.join(chunk[::-1] for chunk in strng.split('\n'))
def hor_mirror(strng):
return '\n'.join(strng.split('\n')[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
from string import ascii_letters
def vert_mirror(strng):
return "\n".join(w[::-1] for w in strng.split('\n'))
def hor_mirror(strng):
return "\n".join(w for w in strng.split('\n')[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return (line[::-1] for line in strng.split('\n'))
def hor_mirror(strng):
return strng.split('\n')[::-1]
# your code
def oper(fct, s):
return '\n'.join(fct(s))
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
segments = strng.split('\n')
for i in range(len(segments)):
segments[i] = segments[i][::-1]
return segments
# your code
def hor_mirror(strng):
segments = strng.split('\n')
s = segments[::-1]
return s
# your code
def oper(fct, s):
return '\n'.join(fct(s))
# your code
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(s):
return '\n'.join(list(map(lambda x: x[::-1],s.split('\n'))))
def hor_mirror(s):
return '\n'.join(s.split('\n')[::-1])
def oper(f, s):
if str(f).split()[1] == 'vert_mirror': return vert_mirror(s)
return hor_mirror(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return "\n".join([strng.split('\n')[i][::-1] for i in range(len(strng.split('\n')))])
def hor_mirror(strng):
return "\n".join(strng.split('\n')[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
v_mirror = []
for row in strng.split("\n"):
v_mirror.append(row[::-1])
return "\n".join(v_mirror)
def hor_mirror(strng):
return "\n".join(list(reversed(strng.split("\n"))))
def oper(fct, s):
if fct == vert_mirror:
return vert_mirror(s)
else:
return hor_mirror(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
s = strng.split('\n')
return '\n'.join([x[::-1] for x in s])
def hor_mirror(strng):
s = strng.split('\n')
return '\n'.join(s[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
L=[]
str = strng.split("\n")
for s in str:
L.append(s[::-1])
return "\n".join(L)
def hor_mirror(strng):
str = strng.split("\n")
return "\n".join(str[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng: str):
return "\n".join(el[::-1] for el in strng.split())
def hor_mirror(strng: str):
return "\n".join(reversed(strng.split()))
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
vert_mirror = lambda S : '\n'.join(s[::-1] for s in S.split('\n'))
hor_mirror = lambda S : '\n'.join(S.split('\n')[::-1])
oper = lambda f, S: f(S)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
strng = strng.split('\n')
strng = [i[::-1] for i in strng]
return '\n'.join(strng)
def hor_mirror(strng):
strng = strng.split('\n')
strng = strng[::-1]
return '\n'.join(strng)
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def oper(fct, s):
return fct(s)
def vert_mirror(strng):
vert = strng.split()
vert1 = []
vert2 = '\n'
for i in range(len(vert)):
vert1.append(vert[i][::-1])
return (vert2.join(vert1))
def hor_mirror(strng):
hor = strng.split()
hor1 = hor[::-1]
hor2 = '\n'
return hor2.join(hor1)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(st):
a = st.split("\n")
for i in range(len(a)):
a[i] = list(a[i])
a[i].reverse()
a[i] = ''.join(a[i])
return "\n".join(a)
def hor_mirror(st):
a = st.split('\n')
a.reverse()
return "\n".join(a)
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
lst = strng.split()[::-1]
return "\n".join(lst)[::-1]
def hor_mirror(strng):
lst = strng.split()[::-1]
return "\n".join(lst)
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
from typing import Callable
def oper(callback: Callable[[str], str], string: str) -> str:
return callback(string)
def vert_mirror(string: str) -> str:
return '\n'.join([
line[::-1] for line in string.split('\n')
])
def hor_mirror(string: str) -> str:
return '\n'.join(
string.split('\n')[::-1]
)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
strs=strng.split('\n')
for s in range(len(strs)):
strs[s] = strs[s][::-1]
return '\n'.join(strs)
def hor_mirror(strng):
stsrs=strng.split('\n')
return '\n'.join(stsrs[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return '\n'.join(w[::-1] for w in strng.split())
def hor_mirror(strng):
return '\n'.join(strng.split()[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
ans = ""
sq = strng.split("\n")
dim = len(sq)
for i in range (0,dim,1):
print(i)
ans += str(sq[i][::-1]) + "\n"
return ans.rstrip("\n")
def hor_mirror(strng):
ans = ""
sq = strng.split("\n")
dim = len(sq)
for i in range (dim,0,-1):
ans += str(sq[i-1]) + "\n"
return ans.rstrip("\n")
def oper(fct, s):
return vert_mirror(s) if fct == vert_mirror else hor_mirror(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(string):
mylist = string.split('\n') #splits into list of the parts
for x in range(len(mylist)):
mylist[x] = mylist[x][::-1]
mystring = '\n'.join(mylist)
return mystring
def hor_mirror(string):
mylist = string.split('\n')
mylist = mylist[::-1]
mystring = '\n'.join(mylist)
return mystring
def oper(fct, s):
if fct == vert_mirror:
return vert_mirror(s)
elif fct==hor_mirror:
return hor_mirror(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return [x[::-1] for x in strng]
def hor_mirror(strng):
return strng[::-1]
def oper(fct, s):
strng=s.split("\n")
return "\n".join(fct(strng))
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return "\n".join(["".join(list(word)[::-1]) for word in strng.split()])
def hor_mirror(strng):
return "\n".join(strng.split()[::-1])
def oper(fct, s):
return eval('fct(s)')
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return "\n".join(cs[::-1] for cs in strng.split("\n"))
def hor_mirror(strng):
return "\n".join(strng.split("\n")[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return "\n".join(cs[::-1] for cs in strng.split("\n"))
def hor_mirror(strng):
return "\n".join(strng.split("\n")[::-1])
def oper(fct, s):
return vert_mirror(s) if fct == vert_mirror else hor_mirror(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
strng = strng.split('\n')
return '\n'.join(i[::-1] for i in strng)
def hor_mirror(strng):
strng = strng.split('\n')
return '\n'.join(i for i in reversed(strng))
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
l = strng.split('\n')
p = []
for i in l:
p.append(i[::-1])
return '\n'.join(p)
def hor_mirror(strng):
l = list(reversed(strng.split('\n')))
return '\n'.join(l)
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(str):
return '\n'.join([i[::-1] for i in str.split('\n')])
def hor_mirror(str):
return '\n'.join(str.split('\n')[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
lines = strng.split("\n")
transformed_lines = ["".join(reversed(line)) for line in lines]
return "\n".join(transformed_lines)
def hor_mirror(strng):
lines = strng.split("\n")
return "\n".join(reversed(lines))
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(s):
return '\n'.join(m[::-1] for m in s.split('\n'))
def hor_mirror(s):
return '\n'.join(s.split('\n')[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(s):
return '\n'.join([s.split('\n')[0][::-1]] + [m[1:][::-1]+m[0] for m in s.split('\n')[1:]])
def hor_mirror(s):
return '\n'.join(s.split('\n')[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
strng = strng.split("\n")
output = []
for word in strng:
output.append(word[::-1])
return '\n'.join(output)
def hor_mirror(strng):
strng = strng.split("\n")
output = []
return '\n'.join(strng[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(string):
return [s[::-1] for s in string]
def hor_mirror(string):
return string[::-1]
def oper(fct, s):
return '\n'.join(fct(s.split('\n')))
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
sub_list = strng.split("\n")
for index, substr in enumerate(sub_list):
sub_list[index] = substr[::-1]
return "\n".join(sub_list)
def hor_mirror(strng):
sub_list = strng.split("\n")
sub_list.reverse()
return "\n".join(sub_list)
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return '\n'.join([text[::-1] for text in strng.split('\n')])
def hor_mirror(strng):
return '\n'.join(strng.split('\n')[::-1])
def oper(fct, s):
return vert_mirror(s) if fct is vert_mirror else hor_mirror(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(value: str):
return '\n'.join([s[::-1] for s in value.split('\n')])
def hor_mirror(value):
return '\n'.join(value.split('\n')[::-1])
def oper(func, value):
return func(value)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
lst = strng.split("\n")
return "\n".join("".join(i[::-1]) for i in lst)
def hor_mirror(strng):
lst = strng.split("\n")
return "\n".join(lst[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(s):
lst = s.split('\n')
return '\n'.join([x[::-1] for x in lst])
def hor_mirror(s):
lst = s.split('\n')
return '\n'.join(lst[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
s = strng.split("\n")
l = list()
for i in s:
l.append(i[::-1])
return "\n".join(str(i) for i in l)
def hor_mirror(strng):
s = strng.split("\n")
return "\n".join(str(i) for i in s[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return "\n".join([x[::-1] for x in strng.split("\n")])
def hor_mirror(strng):
return "\n".join(x for x in strng.split("\n")[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
strng = strng.split("\n")
return "\n".join(s[::-1] for s in strng)
def hor_mirror(strng):
strng = strng.split("\n")
return "\n".join(strng[::-1])
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
from typing import Callable
def vert_mirror(strng: str) -> str:
return '\n'.join(s[::-1] for s in strng.splitlines())
def hor_mirror(strng: str) -> str:
return '\n'.join(strng.splitlines()[::-1])
def oper(fct: Callable[[str], str], s) -> str:
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
import re
def vert_mirror(strng):
x=re.split("\s",strng)
y=[i[::-1] for i in x]
return '\n'.join(y)
def hor_mirror(strng):
x=re.split('\s',strng)
a=x[::-1]
return '\n'.join(a)
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return '\n'.join([a[::-1] for a in strng.split('\n')])
def hor_mirror(strng):
return '\n'.join(reversed(strng.split('\n')))
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
vert_mirror = lambda s: '\n'.join(r[::-1] for r in s.split('\n'))
hor_mirror = lambda s: '\n'.join(s.split('\n')[::-1])
oper = lambda f, s: f(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return '\n'.join(''.join(reversed(line)) for line in strng.split('\n'))
def hor_mirror(strng):
return '\n'.join(reversed(strng.split('\n')))
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
# your code
p=[]
s=strng.split("\n")
for i in s:
p.append(i[::-1])
return "\n".join(p)
def hor_mirror(strng):
# your code
s=strng.split("\n")
p=s[::-1]
return "\n".join(p)
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
return '\n'.join(list(map(lambda x: x[::-1], strng.split('\n'))))
def hor_mirror(strng):
return '\n'.join(list(map(lambda x: x[::-1], strng[::-1].split('\n'))))
def oper(fct, s):
return fct(s)
|
This kata is the first of a sequence of four about "Squared Strings".
You are given a string of `n` lines, each substring being `n` characters long: For example:
`s = "abcd\nefgh\nijkl\nmnop"`
We will study some transformations of this square of strings.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
```
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
```
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
```
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
```
or printed:
```
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
```
# Task:
- Write these two functions
and
- high-order function `oper(fct, s)` where
- fct is the function of one variable f to apply to the string `s`
(fct will be one of `vertMirror, horMirror`)
# Examples:
```
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
```
# Note:
The form of the parameter `fct` in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
# Bash Note:
The input strings are separated by `,` instead of `\n`. The output strings should be separated by `\r` instead of `\n`. See "Sample Tests".
Forthcoming katas will study other transformations.
|
def vert_mirror(strng):
arr = [s[::-1] for s in strng.split('\n')]
return('\n'.join(arr))
def hor_mirror(strng):
print('there')
return('\n'.join([s for s in strng.split('\n')][::-1]))
def oper(fct, s):
return(fct(s))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.