1. Python / Говнокод #23332

    −7

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    import re
    
    def matrix():
        square = [[0 for x in range(7)] for x in range(7)]
        directions = ((1,0), (0,1), (-1,0), (0,-1))
        x, y, d = -1, 0, 0
        
        for i in range(49):
            while True:
                x1, y1 = x + directions[d][0], y + directions[d][1]
                
                if x1 >= 0 and x1 < 7 and y1 >= 0 and y1 < 7 and square[y1][x1] == 0:
                    x, y = x1, y1
                    break
                
                d = (d + 1) % 4
            
            square[y][x] = re.sub(r'\d', lambda n: ' ' * int(n.group()), '9de9mb8nv5yo4aol1rm')[i]
        
        return square
    
    print('\n'.join([''.join(line) for line in matrix()]).strip())

    по мативам http://govnokod.ru/23329#comment389918

    HACTEHbKA, 06 Сентября 2017

    Комментарии (1)
  2. Python / Говнокод #23329

    −2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    n = int(input())
    matrix = [[0] * n for i in range(n)]
    num = 1
    end = n
    start = 0
    while num != num**2:
        for i in range(start, end):
            if num == num**2:
                break
            for j in range(start, end):
                if num == num**2:
                    break
                matrix[i][j] = num
                num += 1
                if j + 1 == end:
                    for k in range(start+1, end):
                        if num == num**2:
                            break
                        matrix[k][j] = num
                        num += 1
                        if k + 1 == end:
                            for l in range(-end+1, -start):
                                if num == num**2:
                                    break
                                matrix[k][l] = num
                                num += 1
                                if l + 1 == start:
                                    for m in range(-end+1, -start-1):
                                        if num == num**2:
                                            break
                                        matrix[m][l] = num
                                        num += 1
            end -= 1
            start += 1
    for i in range(n):
        for j in range(n):
            print(matrix[i][j], end='\t')
        print()

    у меня на выходе только нули, не понимаю где нагадил,вот условие:

    Выведите таблицу размером n×n, заполненную числами от 1 до n**2 по спирали, выходящей из левого верхнего угла и закрученной по часовой стрелке, как показано в примере (здесь n=5):
    Sample Input:
    5
    Sample Output:
    1 2 3 4 5
    16 17 18 19 6
    15 24 25 20 7
    14 23 22 21 8
    13 12 11 10 9

    reznik, 05 Сентября 2017

    Комментарии (15)
  3. Python / Говнокод #23328

    −9

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    class SimilarCardIsShown(ZenAndroidTest):
        def test_similar_show(self):
            cards = self.swipe_and_find_elements(By.ID, "com.yandex.zensample.app:id/card_title", 7)
            for card in cards:
                card.click()
                self.driver.back()
            assert self.driver.find_element_by_id("com.yandex.zensample.app:id/card_helper_sim_head"), "Нет похожих"

    хуй

    storvus, 05 Сентября 2017

    Комментарии (0)
  4. Python / Говнокод #23323

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    N = int(input())
    S = []
    for i in range(N):
        S.append(list(map(float, input().split())))
    for i in range(len(S)):
        S[i][0], S[i][1] = S[i][1], S[i][0]
    S.sort()
    for x in range(N):
        for i in range(N-1):
            if S[i][0] == S[i+1][0]:
                if S[i][1] < S[i+1][1]:
                    S[i][1], S[i+1][1] = S[i+1][1], S[i][1]
    for i in range(N):
    print((str(round(S[i][1], 2))[:str(round(S[i][1], 2)).index('.')]+(str(round(S[i][1], 2))+'00000000')[str(round(S[i][1], 2)).index('.'):str(round(S[i][1], 2)).index('.')+3]),(str(round(S[i][0], 3))[:str(round(S[i][0], 3)).index('.')]+(str(round(S[i][0], 3))+'00000000')[str(round(S[i][0], 3)).index('.'):str(round(S[i][0], 3)).index('.')+4]))

    Нужно было дописать эту прогу во что бы то ни стало...

    Caladrius, 03 Сентября 2017

    Комментарии (2)
  5. Python / Говнокод #23288

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    #!/usr/bin/env python
    
    import jinja2
    
    import contextlib
    import os.path
    import shutil
    import subprocess
    import sys
    import tempfile
    
    
    @contextlib.contextmanager
    def rm_dir(d):
        yield d
        shutil.rmtree(d)
    
    
    def main():
        if len(sys.argv) < 2:
            return
    
        if os.path.basename(sys.argv[1]) != "compile":
            subprocess.call(sys.argv[1:])
            return
    
        command = sys.argv[1:]
        preprocessed_files = []
    
        with rm_dir(tempfile.mkdtemp()) as tmpdir:
            print "Temp dir is", tmpdir
    
            while len(command) > 0 and not command[-1].startswith("-") and command[-1].endswith(".go"):
                tmpfile = os.path.join(tmpdir, str(len(command)) + ".go")
    
                with open(command[-1]) as input:
                    with open(tmpfile, "wb") as preprocessed:
                        print "Preprocess", command[-1], "into", tmpfile
                        preprocessed.write(jinja2.Template(input.read()).render())
    
                preprocessed_files.append(tmpfile)
                command.pop()
    
            subprocess.call(command + preprocessed_files)
    
    
    if __name__ == "__main__":
        main()

    Прикручиваем шаблонизатор jinja к го, чтобы копипастить с комфортом. Использовать так:

    go build -toolexec '/path/to/preprocess.py' package_na_go

    123123123, 22 Августа 2017

    Комментарии (4)
  6. Python / Говнокод #23226

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    bool retval = true;
    
    while (someting) {
        ...
        if (retval) retval = sendDataInternal(data);
        else sendDataInternal(data);
    }
    
    return retval;

    Ничто не остановит бульдозер.

    bormand, 30 Июля 2017

    Комментарии (24)
  7. Python / Говнокод #23212

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    a=int(input())
    b=int(input())
    c=int(input())
    d=int(input())
    x=a%2
    y=b%2
    z=c%2
    f=d%2
    if x==1 and y==1 and z==1 and f==1:
        print('YES')
    elif x==1 and y==1 and z==0 and f==0:
        print('YES')
    elif x==0 and y==0 and z==1 and f==1:
        print('YES')
    elif x==1 and y==0 and z==1 and f==0:
        print('YES')
    elif x==0 and y==1 and z==0 and f==1:
        print('YES')
    elif x==1 and y==1 and z==0 and f==1:
        print('NO')
    elif x==1 and y==1 and z==1 and f==0:
        print('NO')
    elif x==0 and y==0 and z==1 and f==0:
        print('NO')
    elif x==0 and y==0 and z==0 and f==1:
        print('NO')
    elif x==1 and y==0 and z==1 and f==1:
        print('NO')
    elif x==1 and y==0 and z==0 and f==1:
        print('YES')
    elif x==0 and y==1 and z==0 and f==0:
        print('NO')
    elif x==1 and y==0 and z==0 and f==1:
        print('YES')
    else: 
        print('YES')

    Откопал на Питонтьюторе.

    MaxLevs, 23 Июля 2017

    Комментарии (0)
  8. Python / Говнокод #23190

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    class Cell:
        def __init__(self, row_id, column_id):
            """Описание ячейки в матрице"""
            """Определение первой буквы в ячейке"""
            if row_id == 0:
                self.cell_letter_1 = 'A'
            elif row_id == 1:
                self.cell_letter_1 = 'K'
            elif row_id == 2:
                self.cell_letter_1 = 'Q'
            elif row_id == 3:
                self.cell_letter_1 = 'J'
            elif row_id == 4:
                self.cell_letter_1 = 'T'
            elif row_id == 5:
                self.cell_letter_1 = '9'
            elif row_id == 6:
                self.cell_letter_1 = '8'
            elif row_id == 7:
                self.cell_letter_1 = '7'
            elif row_id == 8:
                self.cell_letter_1 = '6'
            elif row_id == 9:
                self.cell_letter_1 = '5'
            elif row_id == 10:
                self.cell_letter_1 = '4'
            elif row_id == 11:
                self.cell_letter_1 = '3'
            elif row_id == 12:
                self.cell_letter_1 = '2'
            """Определение второй буквы в ячейке"""
            if column_id == 0:
                self.cell_letter_2 = 'A'
            elif column_id == 1:
                self.cell_letter_2 = 'K'
            elif column_id == 2:
                self.cell_letter_2 = 'Q'
            elif column_id == 3:
                self.cell_letter_2 = 'J'
            elif column_id == 4:
                self.cell_letter_2 = 'T'
            elif column_id == 5:
                self.cell_letter_2 = '9'
            elif column_id == 6:
                self.cell_letter_2 = '8'
            elif column_id == 7:
                self.cell_letter_2 = '7'
            elif column_id == 8:
                self.cell_letter_2 = '6'
            elif column_id == 9:
                self.cell_letter_2 = '5'
            elif column_id == 10:
                self.cell_letter_2 = '4'
            elif column_id == 11:
                self.cell_letter_2 = '3'
            elif column_id == 12:
                self.cell_letter_2 = '2'
            """Установка порядка отойбражения 1-й и 2-й буквы в ячейке"""
            if row_id == 0:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 1 and column_id >= 2:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 2 and column_id >= 3:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 3 and column_id >= 4:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 4 and column_id >= 5:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 5 and column_id >= 6:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 6 and column_id >= 7:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 7 and column_id >= 8:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 8 and column_id >= 9:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 9 and column_id >= 10:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 10 and column_id >= 11:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            elif row_id == 11 and column_id == 12:
                self.cell_text = self.cell_letter_1 + self.cell_letter_2
            else:
                self.cell_text = self.cell_letter_2 + self.cell_letter_1

    http://python.su/forum/topic/33195/?page=1#post-181430

    FishHook, 17 Июля 2017

    Комментарии (1)
  9. Python / Говнокод #23172

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    import csv
    import json
    
    import requests
    
    from io import StringIO
    
    from lxml import etree
    
    
    class DayPicParser(object):
        url = 'урл_до_сайта'
    
        def get_info(self):
            handler = open('daypic.csv', 'w+')
            page = 1
            rows = []
            tags = set()
            while page <= 1077:
                response = requests.get('{}/page/{}'.format(self.url, page))
                response.connection.close()
                parser = etree.HTMLParser()
                tree = etree.parse(StringIO(response.text), parser)
                posts = tree.xpath('//div[@class="posts"]/div[@class="post"]')
                for i, post in enumerate(posts):
                    title = post.find('./h2/a')
                    link_to_fulltext = title.attrib['href']
    
                    short_text = post.find('./div[@class="text"]//p[1]')
                    response = requests.get(link_to_fulltext)
                    full_parser = etree.HTMLParser()
                    full_tree = etree.parse(StringIO(response.text), full_parser)
                    full_post = full_tree.xpath('//div[@class="text"]//p')
    
                    main_image = None
                    full_text = []
                    for inner in full_post:
                        if inner.find('.//noindex') is not None:
                            continue
                        if inner.find('.//img') is not None:
                            src = inner.find('.//img').attrib['src']
                            if not main_image:
                                main_image = src
                            full_text.append({'image': src})
                        for paragraph in etree.tostring(inner, method="text", encoding='utf-8').decode('utf-8').strip().split("\n"):
                            if paragraph:
                                full_text.append({'text': paragraph})
                    rows.append({'title': title.text.strip(),
                                 'preview': main_image if main_image else '',
                                 'short_text': short_text.text.strip(),
                                 'full_text': full_text})
                    print('Post {} of {}'.format(i, len(posts)))
                page += 1
                print(page)
            handler.write(json.dumps(rows))
            handler.close()
            print(tags)
    
    
    DayPicParser().get_info()

    storvus, 10 Июля 2017

    Комментарии (4)
  10. Python / Говнокод #23168

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    class StreamRailBase:
        __metaclass__ = ABCMeta
    
        def __init__(self): pass
    
        # @abstractmethod
        # def create_connection(self): pass
        #
        # @abstractmethod
        # def send_to_sr(self, method, path, params=None): pass
    
        # @abstractmethod
        # def get_advertisers(self): pass
        #
        # @abstractmethod
        # def get_targeting_conditions(self, env, geos, os, size, white_list, black_list): pass
        #
        # @abstractmethod
        # def create_ad_source(self, name, price, partner, tag_url, env, geos, os, size, req_cap, imp_cap, white_list=None, black_list=None): pass
        #
        # @abstractmethod
        # def create_sr_tag(self, tag_instance): pass
        #
        # @abstractmethod
        # def create_domain_list(self, f, list_type, adsource_name): pass
        #
        # @abstractmethod
        # def activate_adsource(self, adsource_id): pass
        #
        # @abstractmethod
        # def deactivate_adsource(self, adsource_id): pass
        #
        # @abstractmethod
        # def set_caps(self, params, new_req_cap, new_imp_cap): pass
        #
        # @abstractmethod
        # def set_geos(self, params, new_geos): pass
        #
        # @abstractmethod
        # def edit_domain_list(self, f, list_id): pass
        #
        # @abstractmethod
        # def set_list(self, params, new_list, list_type): pass
        #
        # @abstractmethod
        # def set_size(self, params, size): pass
        #
        # @abstractmethod
        # def edit_adsource(self, tag_instance, form_data): pass
        #
        # @abstractmethod
        # def create_new_partner(self, name): pass
        #
        # @abstractmethod
        # def sync_tag(self, tag_instance): pass
        #
        # @abstractmethod
        # def add_new_tag_to_template(self, tag_name, price, tag_id, adv_id): pass

    В человеке умер рахитектор, и в отчаянии, он закомитил эту хуйню в мастер.

    wvxvw, 09 Июля 2017

    Комментарии (4)