Змея / Говнокод #29222 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
import itertools
import time
n = int(input())
a = []
sm = 0
for i in range(n):
    a.append(list(map(int, input().split())))
    a[i].sort()
    sm += a[i][0] + a[i][1]
mx = 0
a.sort()
for i in itertools.product([0, 1], repeat=n - 1):
    if time.process_time() > 0.75:
        break
    s = 0
    for j in range(n):
        if j >= 1:
            s += a[j][i[j - 1]]
        else:
            s += a[j][0]
    s2 = sm - s
    if s % 3 == 0 and s > mx:
        mx = s
    if s2 > mx and s2 % 3 == 0:
        mx = s2
print(mx)

Задача с ЕГЭ: "Даны пары (A[i][0], A[i][1]), в каждой паре нужно выбрать одно число, при этом сумма выбранных чисел должна делится на 3, среди таких сумм найти максимальную"

Автор данного кода не справился нормально соптимизировать решение, поэтому написал какую-то х**ню, результат видите выше (особенно строчка 13)
Оно зашло на тестах, где n <= 20

letipetukh1 letipetukh1, (Updated )

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

Змея / Говнокод #29164 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
n = int(input())
d = n
i = 0
a = 0
c = 0
has1 = False
has2 = False
has3 = False 
has4 = False
has5 = False
has6 = False
has7 = False
has8 = False
last_dig = 0
while n > 0:
    last_dig = n % 10
    if last_dig > i :
        i = last_dig
        if last_dig == 1:
            c = 1
    elif last_dig == 1:
        has1 = True
    elif last_dig == 2:
        has2 = True
    elif last_dig == 3:
        has3 = True
    elif last_dig == 4:
        has4 = True
    elif last_dig == 5:
        has5 = True
    elif last_dig == 6:
        has6 = True
    elif last_dig == 7:
        has7 = True
    elif last_dig == 8:
        has8 = True
    n = n // 10
c = d % 10
if has1 == True and c >= 1:
    a = 1
elif has2 == True and c >= 2:
    a = 2
elif has3 == True and c >= 3:
    a = 3
elif has4 == True and c >= 4:
    a = 4
elif has5 == True and c >= 5:
    a = 5
elif has6 == True and c >= 6:
    a = 6
elif has7 == True and c >= 7:
    a = 7
elif has8 == True and c >= 8:
    a = 8
else:
    a = c
print('Максимальная цифра равна', i)
print('Минимальная цифра равна', a)

Дано натуральное число n. Напишите программу, которая определяет его максимальную и минимальную цифры

Permanent_Record Permanent_Record, (Updated )

Комментарии (1, +1)

Змея / Говнокод #29163 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
n = int(input())
a = n
i = 0
last_digit = 0
total = 0
while n != 0:
    i += 1
    n = n // 10
while a != 0:
    last_digit = (a % 10) * 10 ** i 
    total += last_digit
    i = i - 1
    a = a // 10
print(total // 10)

Дано натуральное число. Напишите программу, которая меняет порядок цифр числа на обратный. В той Вселенной, откуда пришел этот код, end просто не существует...

Permanent_Record Permanent_Record, (Updated )

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

Змея / Говнокод #29162 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
n = input().strip('#')
n = int(n)
for _ in range(n):
    s = input()
    if '#' not in s:
        s = s.rstrip()
        print(s)
    else:
        i = 0
        count = 0
        while s[i].isspace():
            count += 1
            i += 1
        s = s.strip()
        l = s.split(' ')
        while True:
            item = l.pop(-1)
            if '#' in item:
                break
        if count != 0:
            l.insert(0, ' '*(count - 1))
        count = 0
        m = ' '.join(l)
        print(m.rstrip())

На вход программе подаётся натуральное число в формате #n, а затем n строк с кодом, в котором нужно удалить все комментарии и сохранить всё остальное как есть. Зачем вся эта хрень со списками, когда можно решить в несколько строк методами строк, простите за каламбур!

Permanent_Record Permanent_Record, (Updated )

Комментарии (2, +2)

Змея / Говнокод #29153 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
from gremllm import Gremllm

# Be sure to tell your gremllm what sort of thing it is
counter = Gremllm('counter')
counter.value = 5
counter.increment()
print(counter.value)  # 6?
print(counter.to_roman_numerals()) # VI?

https://github.com/awwaiid/gremllm

Нет, вы не поняли. На каждый метод он запускает "ИИ", который додумывает что нужно сделать.

OCETuHCKuu_nemyx OCETuHCKuu_nemyx, (Updated )

Комментарии (9, +9)

Змея / Говнокод #29149 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
def animate_fight (self, игрок):
       if self.gamedata.animate_fight == True: 
          
          if self.gamedata.fight_animation_progress < 3:
           self.gamedata.screen.blit(self.fight1, (self.x - (self.width // 2), self.y - (self.width //2) ))
           
          elif 3 <= self.gamedata.fight_animation_progress < 6:
           self.gamedata.screen.blit(self.fight2, (self.x - (self.width // 2), self.y - (self.width //2) ))

          elif  6 <= self.gamedata.fight_animation_progress < 9:
           self.gamedata.screen.blit(self.fight3, (self.x - (self.width // 2), self.y - (self.width //2) ))
           self.gamedata.screen.blit(self.fight1, (игрок.x - (self.width // 2), игрок.y - (self.width // 2) ))
          elif  9 <= self.gamedata.fight_animation_progress < 12:
           self.gamedata.screen.blit(self.fight4, (self.x - (self.width // 2), self.y - (self.width //2) ))
           self.gamedata.screen.blit(self.fight2, (игрок.x - (self.width // 2), игрок.y - (self.width // 2) ))
          elif  12 <= self.gamedata.fight_animation_progress < 15:
           self.gamedata.screen.blit(self.fight5, (self.x - (self.width // 2), self.y - (self.width //2) ))
           self.gamedata.screen.blit(self.fight3, (игрок.x - (self.width // 2), игрок.y - (self.width // 2) ))
          elif  15 <= self.gamedata.fight_animation_progress < 18:
           self.gamedata.screen.blit(self.fight6, (self.x - (self.width // 2), self.y - (self.width //2) ))
           self.gamedata.screen.blit(self.fight4, (игрок.x - (self.width // 2), игрок.y - (self.width // 2) ))
          elif  18 <= self.gamedata.fight_animation_progress < 21:
             self.gamedata.screen.blit(self.fight5, (игрок.x - (self.width // 2), игрок.y - (self.width // 2) ))

          elif  21 <= self.gamedata.fight_animation_progress < 24:
             self.gamedata.screen.blit(self.fight6, (игрок.x - (self.width // 2), игрок.y - (self.width // 2) ))
           
          elif  24 <=self.gamedata.fight_animation_progress:
             self.gamedata.animating = False
             self.gamedata.fight_animation_progress = 0
             self.gamedata.animate_fight = False
          if 24 > self.gamedata.fight_animation_progress:
           self.gamedata.fight_animation_progress += 1

Зачем делить на 3, если можно написать кучу говна?

1004w 1004w, (Updated )

Комментарии (2, +2)

Змея / Говнокод #29134 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
def pause(c):                                             #replace, assist
    if c > 100: waitLong(c)
    elif c== 1: wait1s()
    elif c== 2: wait2s()
    elif c== 3: wait3s()
    elif c== 5: wait5s()
    elif c== 8: wait8s()
    elif c== 10: wait10s()
    else:
        logger.debug(f"custom timeout, need recheck({c})")
        p(c)   #ping raspberry instead of direct sleep

def p(c):
    time.sleep(c)

def wait1s():
    p(1)

def wait2s():
    wait1s()
    wait1s()

def wait3s():
    logger.debug("one, two, three")
    p(3)   

def wait5s():
    logger.debug("5, 4, 3, 2, 1..")
    p(5)

def wait8s():
    wait5s()
    wait3s()

def wait10s():
    wait5s()
    wait5s()

def waitLong(c):
    logger.debug(f"Attention, wait time is too long({c}), need to replace with waiting for some event or ping")
    p(c)

def cc():
    global client
    client.connect()
    return(client)

NikitaTsyb NikitaTsyb, (Updated )

Комментарии (7, +7)