Skip to main content
deleted 2 characters in body
Source Link
Peilonrayz
  • 43.5k
  • 7
  • 76
  • 155

I'd recommend you start over. I always start patterns that are mirrored in the x axis by figuring out how to do a quarter of the pattern. I also use a view, so that if you want to change the icons you can.

And so I start with:

def palindrome(n):
    view = ''.join(map(str, range(n + 1)))
    for size in reversed(range(n + 1)):
        half = view[size:]
        print(half)

palindrome(3)
3
23
123
0123

After this we know to use view[size] as the center, and we repeat it size amount of times.

def palindrome(n):
    view = ''.join(map(str, range(n + 1)))
    for size in reversed(range(n + 1)):
        half = view[size] * size + view[size:]
        print(half)

palindrome(3)
3333
2223
1123
0123

From this you will then just have to mirror the output:

def palindrome(n):
    view = ''.join(map(str, range(n + 1)))
    for sizes in (reversed(range(n + 1)), range(1, n + 1)):
        for size in sizes:
            half = view[size] * size + view[size:]
            print(yield half[:0:-1] + half)

Going forward, you could enter view into it and make it output whatever you want.

import itertools

def palindrome(view):
    n = len(view)
    for sizessize in itertools.chain(reversed(range(n)), range(1, n)):
        for size in sizes:
            half = view[size] * size + view[size:]
           yield print(half[:0:-1]) + half

print('\n'.join(palindrome('.|.|')))
|||||||
|.....|
|.|||.|
|.|.|.|
|.|||.|
|.....|
|||||||

I'd recommend you start over. I always start patterns that are mirrored in the x axis by figuring out how to do a quarter of the pattern. I also use a view, so that if you want to change the icons you can.

And so I start with:

def palindrome(n):
    view = ''.join(map(str, range(n + 1)))
    for size in reversed(range(n + 1)):
        half = view[size:]
        print(half)

palindrome(3)
3
23
123
0123

After this we know to use view[size] as the center, and we repeat it size amount of times.

def palindrome(n):
    view = ''.join(map(str, range(n + 1)))
    for size in reversed(range(n + 1)):
        half = view[size] * size + view[size:]
        print(half)

palindrome(3)
3333
2223
1123
0123

From this you will then just have to mirror the output:

def palindrome(n):
    view = ''.join(map(str, range(n + 1)))
    for sizes in (reversed(range(n + 1)), range(1, n + 1)):
        for size in sizes:
            half = view[size] * size + view[size:]
            print(half[:0:-1] + half)

Going forward, you could enter view into it and make it output whatever you want.

def palindrome(view):
    n = len(view)
    for sizes in (reversed(range(n)), range(1, n)):
        for size in sizes:
            half = view[size] * size + view[size:]
            print(half[:0:-1])

palindrome('.|.|')
|||||||
|.....|
|.|||.|
|.|.|.|
|.|||.|
|.....|
|||||||

I'd recommend you start over. I always start patterns that are mirrored in the x axis by figuring out how to do a quarter of the pattern. I also use a view, so that if you want to change the icons you can.

And so I start with:

def palindrome(n):
    view = ''.join(map(str, range(n + 1)))
    for size in reversed(range(n + 1)):
        half = view[size:]
        print(half)

palindrome(3)
3
23
123
0123

After this we know to use view[size] as the center, and we repeat it size amount of times.

def palindrome(n):
    view = ''.join(map(str, range(n + 1)))
    for size in reversed(range(n + 1)):
        half = view[size] * size + view[size:]
        print(half)

palindrome(3)
3333
2223
1123
0123

From this you will then just have to mirror the output:

def palindrome(n):
    view = ''.join(map(str, range(n + 1)))
    for sizes in (reversed(range(n + 1)), range(1, n + 1)):
        for size in sizes:
            half = view[size] * size + view[size:]
            yield half[:0:-1] + half

Going forward, you could enter view into it and make it output whatever you want.

import itertools

def palindrome(view):
    n = len(view)
    for size in itertools.chain(reversed(range(n)), range(1, n)):
        half = view[size] * size + view[size:]
        yield half[:0:-1] + half

print('\n'.join(palindrome('.|.|')))
|||||||
|.....|
|.|||.|
|.|.|.|
|.|||.|
|.....|
|||||||
clean code
Source Link
Peilonrayz
  • 43.5k
  • 7
  • 76
  • 155

I'd recommend you start over. I always start patterns that are mirrored in the x axis by figuring out how to do a quarter of the pattern. I also use a view, so that if you want to change the icons you can.

And so I start with:

def palindrome(n):
    view = list''.join(map(str, range(n + 1)))
    for size in reversed(range(n + 1)):
        half = view[size:]
        print(''.join(half))

palindrome(3)
3
23
123
0123

After this we know to use view[size] as the center, and we repeat it size amount of times.

def palindrome(n):
    view = list''.join(map(str, range(n + 1)))
    for size in reversed(range(n + 1)):
        half = [view[size]]view[size] * size + view[size:]
        print(''.join(half))

palindrome(3)
3333
2223
1123
0123

From this you will then just have to mirror the output:

def palindrome(n):
    view = list''.join(map(str, range(n + 1)))
    for sizes in (reversed(range(n + 1)), range(1, n + 1)):
        for size in sizes:
            half = [view[size]]view[size] * size + view[size:]
            print(''.join(half[:0:-1] + half))

Going forward, you could enter view into it and make it output whatever you want.

def palindrome(view):
    n = len(view)
    for sizes in (reversed(range(n)), range(1, n)):
        for size in sizes:
            half = view[size] * size + view[size:]
            print(half[:0:-1])

palindrome('.|.|')
|||||||
|.....|
|.|||.|
|.|.|.|
|.|||.|
|.....|
|||||||

I'd recommend you start over. I always start patterns that are mirrored in the x axis by figuring out how to do a quarter of the pattern. I also use a view, so that if you want to change the icons you can.

And so I start with:

def palindrome(n):
    view = list(map(str, range(n + 1)))
    for size in reversed(range(n + 1)):
        half = view[size:]
        print(''.join(half))

palindrome(3)
3
23
123
0123

After this we know to use view[size] as the center, and we repeat it size amount of times.

def palindrome(n):
    view = list(map(str, range(n + 1)))
    for size in reversed(range(n + 1)):
        half = [view[size]] * size + view[size:]
        print(''.join(half))

palindrome(3)
3333
2223
1123
0123

From this you will then just have to mirror the output:

def palindrome(n):
    view = list(map(str, range(n + 1)))
    for sizes in (reversed(range(n + 1)), range(1, n + 1)):
        for size in sizes:
            half = [view[size]] * size + view[size:]
            print(''.join(half[:0:-1] + half))

Going forward, you could enter view into it and make it output whatever you want.

def palindrome(view):
    n = len(view)
    for sizes in (reversed(range(n)), range(1, n)):
        for size in sizes:
            half = view[size] * size + view[size:]
            print(half[:0:-1])

palindrome('.|.|')
|||||||
|.....|
|.|||.|
|.|.|.|
|.|||.|
|.....|
|||||||

I'd recommend you start over. I always start patterns that are mirrored in the x axis by figuring out how to do a quarter of the pattern. I also use a view, so that if you want to change the icons you can.

And so I start with:

def palindrome(n):
    view = ''.join(map(str, range(n + 1)))
    for size in reversed(range(n + 1)):
        half = view[size:]
        print(half)

palindrome(3)
3
23
123
0123

After this we know to use view[size] as the center, and we repeat it size amount of times.

def palindrome(n):
    view = ''.join(map(str, range(n + 1)))
    for size in reversed(range(n + 1)):
        half = view[size] * size + view[size:]
        print(half)

palindrome(3)
3333
2223
1123
0123

From this you will then just have to mirror the output:

def palindrome(n):
    view = ''.join(map(str, range(n + 1)))
    for sizes in (reversed(range(n + 1)), range(1, n + 1)):
        for size in sizes:
            half = view[size] * size + view[size:]
            print(half[:0:-1] + half)

Going forward, you could enter view into it and make it output whatever you want.

def palindrome(view):
    n = len(view)
    for sizes in (reversed(range(n)), range(1, n)):
        for size in sizes:
            half = view[size] * size + view[size:]
            print(half[:0:-1])

palindrome('.|.|')
|||||||
|.....|
|.|||.|
|.|.|.|
|.|||.|
|.....|
|||||||
Source Link
Peilonrayz
  • 43.5k
  • 7
  • 76
  • 155

I'd recommend you start over. I always start patterns that are mirrored in the x axis by figuring out how to do a quarter of the pattern. I also use a view, so that if you want to change the icons you can.

And so I start with:

def palindrome(n):
    view = list(map(str, range(n + 1)))
    for size in reversed(range(n + 1)):
        half = view[size:]
        print(''.join(half))

palindrome(3)
3
23
123
0123

After this we know to use view[size] as the center, and we repeat it size amount of times.

def palindrome(n):
    view = list(map(str, range(n + 1)))
    for size in reversed(range(n + 1)):
        half = [view[size]] * size + view[size:]
        print(''.join(half))

palindrome(3)
3333
2223
1123
0123

From this you will then just have to mirror the output:

def palindrome(n):
    view = list(map(str, range(n + 1)))
    for sizes in (reversed(range(n + 1)), range(1, n + 1)):
        for size in sizes:
            half = [view[size]] * size + view[size:]
            print(''.join(half[:0:-1] + half))

Going forward, you could enter view into it and make it output whatever you want.

def palindrome(view):
    n = len(view)
    for sizes in (reversed(range(n)), range(1, n)):
        for size in sizes:
            half = view[size] * size + view[size:]
            print(half[:0:-1])

palindrome('.|.|')
|||||||
|.....|
|.|||.|
|.|.|.|
|.|||.|
|.....|
|||||||