1. Список говнокодов пользователя imrnccc

    Всего: 2

  2. Java / Говнокод #27664

    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
    import java.util.Arrays;
    import java.util.Optional;
    
    public class AntiVirus{
      
      private int scanIntensity = 0;
      
      //this method is ready for you.
      public void setScanIntensity(int level){
        scanIntensity = level;
      }
      
      //write this method.
      public String scanFile(File file,VirusDB database){
        String[] signature = database.getSignatures(scanIntensity);
        String fileData = file.getData().toLowerCase();
        
         Optional<String> res = Arrays.stream(signature)
             .map(s -> s.toLowerCase())
             .filter(fileData::contains).findAny();
        
         String scan = " is safe";
        
         if(res.isPresent()) {
            System.out.println(res.get());
            System.out.println("scan: " + scan);
            scan = " is not safe";
            System.out.println("scan after: " + scan);
         }
        
        return file.getName() + scan;
      }
    }

    Не понимаю, почему не работает.

    Задача
    https://www.codewars.com/kata/5b13027eedd62c5216000001

    Test Results:
    AVTest
    checkRandomFiles
    Log
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    dos
    scan: is safe
    scan after: is not safe
    expected:<f4wpzFoQD is [not ]safe> but was:<f4wpzFoQD is []safe>
    Stack Trace
    Completed in 476ms
    checkSameFilesWithDifferentIntensitySett ings
    Log
    virus
    scan: is safe
    scan after: is not safe
    expected:<file1 is [not ]safe> but was:<file1 is []safe>
    Stack Trace
    Completed in 1ms
    Completed in 496ms

    imrnccc, 14 Сентября 2021

    Комментарии (23)
  3. Java / Говнокод #27325

    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
    85. 85
    86. 86
    public static boolean isMagicSquare(int[][] a) {
        boolean isMagic = true;
        boolean isSquare = true;
        
        //square? checking here.
        for(int i = 0; i < a.length; i++) {
                if(a.length != a[i].length) {
                        isSquare = false;
                }
        }
        
        if(isSquare) {
            int sum = 0;
            int nextSum = 0;
            
            //first row
            for(int i = 0; i < a.length; i++) {
                    sum += a[0][i]; 
            }
            
            
            //rows
            for(int i = 1; i < a.length; i++) {
                    for(int j = 0; j < a.length; j++) {
                            nextSum += a[i][j];
                    }
                
                    if(nextSum != sum) {
                            isMagic = false;
                            break;
                    } else {
                            nextSum = 0;
                    }
            }
            
            //columns
            if(isMagic) {
                    for(int i = 0; i < a.length; i++) {
                            for(int j = 0; j < a.length; j++) {
                                    nextSum += a[j][i];
                            }
                        
                            if(nextSum != sum) {
                                    isMagic = false;
                                    break;
                            } else {
                                    nextSum = 0;
                            }
                    }
                
                    //diagonals
                    if(isMagic) {
                            for(int i = 0; i < a.length; i++) {
                                    nextSum += a[i][i];
                            }
                            
                            if(nextSum != sum) {
                                    isMagic = false;
                            } else {
                                    nextSum = 0;
                            }
                        
                            if(isMagic) {
                                    int j = a.length - 1;
                                
                                    for(int i = 0; i < a.length; i++) {
                                            nextSum += a[i][j];
                                            
                                            if(j > 0) {
                                                    j--;
                                            }
                                    }
                                
                                    if(nextSum != sum) {
                                            isMagic = false;
                                    }
                            }
                    }
            }
            
        } else {
                isMagic = false;
        }
    
        return isMagic;
    }

    Write a method called isMagicSquare that accepts a two-dimensional array of integers as a parameter and returns true if it is a magic square. A square matrix is a magic square if it is square in shape (same number of rows as columns, and every row the same length), and all of its row, column, and diagonal sums are equal. For example, [[2, 7, 6], [9, 5, 1], [4, 3, 8]] is a magic square because all eight of the sums are exactly 15.

    (https://practiceit.cs.washington.edu/problem/view/bjp3/chapter7/e20%2DisMagicSquare)

    Работает, но код нечитаемый. Как сократить? Понятия не имею.

    imrnccc, 28 Марта 2021

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