#77 Tortoise racing


Two tortoises named A and B must run a race. A starts with an average speed of 720 feet per hour. Young B knows she runs faster than A, and furthermore has not finished her cabbage.


When she starts, at last, she can see that A has a 70 feet lead but B's speed is 850 feet per hour. How long will it take B to catch A?


More generally: given two speeds v1 (A's speed, integer > 0) and v2 (B's speed, integer > 0) and a lead g (integer > 0) how long will it take B to catch A?


The result will be an array [hour, min, sec] which is the time needed in hours, minutes and seconds (round down to the nearest second) or a string in some languages.


If v1 >= v2 then return nil, nothing, null, None or {-1, -1, -1} for C++, C, Go, Nim, [] for Kotlin or "-1 -1 -1".


Examples:

(form of the result depends on the language)


race(720, 850, 70) => [0, 32, 18] or "0 32 18"

race(80, 91, 37)   => [3, 21, 49] or "3 21 49"




 #76 Ones and Zeros


Given an array of one's and zero's convert the equivalent binary value to an integer.


Eg: [0, 0, 0, 1] is treated as 0001 which is the binary representation of 1.


Examples:


Testing: [0, 0, 0, 1] ==> 1

Testing: [0, 0, 1, 0] ==> 2

Testing: [0, 1, 0, 1] ==> 5

Testing: [1, 0, 0, 1] ==> 9

Testing: [0, 0, 1, 0] ==> 2

Testing: [0, 1, 1, 0] ==> 6

Testing: [1, 1, 1, 1] ==> 15

Testing: [1, 0, 1, 1] ==> 11

However, the arrays can have varying lengths, not just limited to 4.




 #75 Numericals of a String


You are given an input string.


For each symbol in the string if it's the first character occurence, replace it with a '1', else replace it with the amount of times you've already seen it...


But will your code be performant enough?


Examples:

input   =  "Hello, World!"

result  =  "1112111121311"


input   =  "aaaaaaaaaaaa"

result  =  "123456789101112"

Note: there will be no int domain overflow (character occurences will be less than 2 billion).




 #74 CamelCase to underscore


You wrote all your unit test names in camelCase. But some of your colleagues have troubles reading these long test names. So you make a compromise to switch to underscore separation.


To make these changes fast you wrote a class to translate a camelCase name into an underscore separated name.


Implement the ToUnderscore() method.


Example:


"ThisIsAUnitTest" => "This_Is_A_Unit_Test"


But of course there are always special cases...


You also have some calculation tests. Make sure the results don't get splitted by underscores. So only add an underscore in front of the first number.


Also Some people already used underscore names in their tests. You don't want to change them. But if they are not splitted correct you should adjust them.


Some of your colleagues mark their tests with a leading and trailing underscore. Don't remove this.


And of course you should handle empty strings to avoid unnecessary errors. Just return an empty string then.


Example:


"Calculate15Plus5Equals20" => "Calculate_15_Plus_5_Equals_20"


"This_Is_Already_Splitted_Correct" => "This_Is_Already_Splitted_Correct"


"ThisIs_Not_SplittedCorrect" => "This_Is_Not_Splitted_Correct"


"_UnderscoreMarked_Test_Name_" => _Underscore_Marked_Test_Name_"




 #73 Counting Duplicates


Count the number of Duplicates

Write a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string. The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits.


Example

"abcde" -> 0 # no characters repeats more than once

"aabbcde" -> 2 # 'a' and 'b'

"aabBcde" -> 2 # 'a' occurs twice and 'b' twice (bandB)

"indivisibility" -> 1 # 'i' occurs six times

"Indivisibilities" -> 2 # 'i' occurs seven times and 's' occurs twice

"aA11" -> 2 # 'a' and '1'

"ABBA" -> 2 # 'A' and 'B' each occur twice




#72 Moving Zeros To The End


Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements.


moveZeros([false,1,0,1,2,0,1,3,"a"]) // returns[false,1,1,2,1,3,"a",0,0]


#71 Triple trouble


Write a function


tripledouble(num1,num2)

which takes in numbers num1 and num2 and returns 1 if there is a straight triple of a number at any place in num1 and also a straight double of the same number in num2.

For example:

tripledouble(451999277, 41177722899) == 1 // num1 has straight triple 999s and 

                                          // num2 has straight double 99s


tripledouble(1222345, 12345) == 0 // num1 has straight triple 2s but num2 has only a single 2


tripledouble(12345, 12345) == 0


tripledouble(666789, 12345667) == 1

If this isn't the case, return 0




Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given numbers finds one that is different in evenness, and return a position of this number.


! Keep in mind that your task is to help Bob solve a real IQ test, which means indexes of the elements start from 1 (not 0)


##Examples :


iqTest("2 4 7 8 10") => 3 // Third number is odd, while the rest of the numbers are even


iqTest("1 2 1 1") => 2 // Second number is even, while the rest of the numbers are odd



 #69  Weight for weight


My friend John and I are members of the "Fat to Fit Club (FFC)". John is worried because each month a list with the weights of members is published and each month he is the last on the list which means he is the heaviest.


I am the one who establishes the list so I told him: "Don't worry any more, I will modify the order of the list". It was decided to attribute a "weight" to numbers. The weight of a number will be from now on the sum of its digits.


For example 99 will have "weight" 18, 100 will have "weight" 1 so in the list 100 will come before 99. Given a string with the weights of FFC members in normal order can you give this string ordered by "weights" of these numbers?


Example:

"56 65 74 100 99 68 86 180 90" ordered by numbers weights becomes: "100 180 90 56 65 74 68 86 99"


When two numbers have the same "weight", let us class them as if they were strings and not numbers: 100 is before 180 because its "weight" (1) is less than the one of 180 (9) and 180 is before 90 since, having the same "weight" (9) it comes before as a string.


All numbers in the list are positive numbers and the list can be empty.




Task

You are working for NoVirus Security Solutions and they ask you to make a scanner that scans a file inputted by the user with the function scanFile(File,VirusDB) that takes a File and a VirusDB object and return whether a file is safe or not. Remember: the searches need to be non-Case-Sensitive


Your class also has the function setScanIntensity(int) which changes the scan intensity. This will only receive values 0, 1, 2 or 3. This has been done for you.


The scan intensity determines the arrays from the database that will be used. i.e.:


scanIntensity 0 means off(every file is considered safe)

scanIntensity 1 means that only the array intensity1Signatures will be used

scanIntensity 2 means that the arrays intensity1Signatures and intensity2Signatures will be used

scanIntensity 3 means that all 3 arrays will be used


Outputs

The outputs should be: "Filename is safe" or "Filename is not safe" (Filename is the name of the file that you can get with file.getName() )


File Class


class File{
  private String name;
  private String data;

  public File(String name,String data){
    this.name = name;
    this.data = data;
  }

  //used in output
  public String getName(){
    return this.name;
  }

  //the String that you need to scan.
  public String getData(){
    return this.data;
  }
}


VirusDB Class


class VirusDB{
   private String[] intensity1Signatures;
   private String[] intensity2Signatures;
   private String[] intensity3Signatures;

   public VirusDB(String[] intensity1Signatures,String[] intensity2Signatures,String[] intensity3Signatures){
     this.intensity1Signatures = intensity1Signatures;
     this.intensity2Signatures = intensity2Signatures;
     this.intensity3Signatures = intensity3Signatures;
   }

   public String[] getSignatures(int arrayNum){
     switch (arrayNum){
       case 1:return this.intensity1Signatures;
       case 2:return this.intensity2Signatures;
       case 3:return this.intensity3Signatures;
       default:return new String[0];
     }
   }
}

Examples



 String[] intensity1signatures = new String[]{
        "malware",
        "virus",
        "infect"
      };

      String[] intensity2signatures = new String[]{
        "ransomware",
        "trojan",
        "trojanHorse",
        "worm",
        "spyware",
        "keystrokelogger",
        "adware",
        "botnet",
        "rootkit",
      };

      String[] intensity3signatures = new String[]{
        "DeleteSys32",
        "OverideMBR",
        "EncryptAll",
        "openrandomwebsite",
        "openrandwebsite",
        "sendalldata",
        "recordKeyboard",
        "recordmouse",
        "destroy",
        "overheat",
        "getfullcontrol",
        "uploadharddrive",
        "uploadharddisk",
        "overload",
        "changeOS",
        "encrypt",
        "changeDesktop",
        "ddos",
        "dos",
        "hide",
        "inject",
        "ransom",
        "getcreditcardinfo",
        "getpasswords",
        "getpass",
      };

+ Recent posts