<file_sep>import UIKit

func dontGiveMeFive(_ start: Int, _ end: Int) -> Int {
    var arr = (start...end).map {$0}
    let newArray = arr.filter {String($0).contains(String(5))}
    for i in newArray {
        arr.removeAll() {$0 == i}
    }
    return arr.count
}

dontGiveMeFive(4, 17)


//MARK:- Easier method



var arr = [1,2,3,4,5,6,7,8,9,15]

//
//
let newArr = (0...16).filter {!String($0).contains(String(5))}
print(newArr)

<file_sep>package day_5;

import java.util.Arrays;
import java.util.List;

import static java.util.stream.IntStream.range;

/*
The input is a string str of digits. Cut the string into chunks
(a chunk here is a substring of the initial string) of size sz
(ignore the last chunk if its size is less than sz).

If a chunk represents an integer such as the sum of the cubes
of its digits is divisible by 2, reverse that chunk;
otherwise rotate it to the left by one position.
Put together these modified chunks and return the result as a string.

If

sz is <= 0 or if str is empty return ""
sz is greater (>) than the length of str it is impossible to take a chunk of size sz hence return "".

Examples:
revrot("123456987654", 6) --> "234561876549"
revrot("123456987653", 6) --> "234561356789"
revrot("66443875", 4) --> "44668753"
revrot("66443875", 8) --> "64438756"
revrot("664438769", 8) --> "67834466"
revrot("123456779", 8) --> "23456771"
revrot("", 8) --> ""
revrot("123456779", 0) --> ""
revrot("563000655734469485", 4) --> "0365065073456944"


public static String revRot(String strng, int sz) {
        if ((sz==0) || (strng == "") || (sz > strng.length())) return "";  // INVALID CASES -> Return empty string

        String result = "";                                                // this string will contain the result to be returned

        for (int i = 0; i < (strng.length()/sz); i++){                     // for each chunk of sz elements
            String chunk = strng.substring(i*sz, i*sz + sz);
            int digitSum = 0;
                                                                           // Because our final goal is to determine if the digtSum is odd or even
            for (int j = 0; j < sz; j++){                                  // There is no need of summing the cubes of the numbers
                digitSum += Character.getNumericValue(chunk.charAt(j));    // odd^n remains odd, even^n remains even
            }                                                              // so the proportion of even and odd numbers remains the same

            if ((digitSum % 2) == 0){                                      // REVERSE CHUNK
                for (int k = sz-1; k >= 0; k--){                           //   by adding every character of the chunk to the result from right to left
                    result += chunk.charAt(k);
                }
            }else{                                                         // ROTATE CHUNK TO THE LEFT BY ONE POSITION
                result += chunk.substring(1) + chunk.charAt(0);            //   by adding the chunk to the result with its first character in the end
            }
        }

        return result;



  public static String revRot(String str, int sz) {
        Function<String, String> prd = s -> s.chars().map(c -> c - '0').sum() % 2 == 0 ?
                new StringBuilder(s).reverse().toString() : s.substring(1) + s.substring(0, 1);

        return Arrays.stream(str.split("(?<=\\G.{" + sz + "})"))
                .filter(s -> s.length() == sz)
                .map(s -> prd.apply(s))
                .collect(Collectors.joining());
    }
 */
public class ReverseOrRotate {
    public static void main(String[] args) {
        String str = "123456987654";
        var seperated = List.of(str.split(""));

        System.out.println(seperated);

        String x = Arrays.toString(new String[]{str.substring(6)});
        System.out.println(x);





    }
    public static String revRot(String strng, int sz) {
        if (strng.isEmpty() || sz <= 0 || sz > strng.length()) return "";
        var ans = new StringBuilder();
        for (int i = 0; i <= strng.length() - sz; i += sz) {
            var chunk = new StringBuilder(strng.substring(i, sz + i));
            if (range(0, sz).mapToDouble(j -> Math.pow(chunk.charAt(j) - 48., 3)).sum() % 2 > 0) {
                ans.append(chunk.substring(1, sz)).append(chunk.charAt(0));
            } else {
                ans.append(chunk.reverse());
            }
        }
        return ans.toString();
    }
}
<file_sep>import UIKit

let num = 1928
let convNum = String(num).reversed()



for (key, value) in convNum.enumerated() {
    let intValue = Int(String(value))!
    let doubleKey = Double(key)
    let placeValue = pow(10.0, doubleKey)
    let result = Int(placeValue) * intValue
    print(result)
}


//MARK:- USING JAVASCRIPT TO SOLVE IT
/*var num = 100
 var lookup = {M:1000,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1};
 var roman = '';
 var i;

 for ( i in lookup ) {
   console.log(i)
   while ( num >= lookup[i] ) {

     roman += i;
     num -= lookup[i];
   }
 }
 console.log(roman)*/
<file_sep>import UIKit

public func solution(_ N : Int) -> Int {
    let binary = String(N, radix: 2)
    
    var arr: [Int] = []

    for (index, value) in binary.enumerated() {
        if value == "1" {
            arr.append(index)
        }
    }
    var final = Array<Int>()
    for i in 0..<arr.count - 1 {
        let res = (arr[i+1] - arr[i]) - 1
        if res == 0 {
            continue
        }
        print(res)
        final.append(res)
    }
    return (Int(final.max() ?? 0))
}

solution(529)


<file_sep>import UIKit

/*Usually when you buy something, you're asked whether your credit card number, phone number or answer to your most secret question is still correct. However, since someone could look over your shoulder, you don't want that shown on your screen. Instead, we mask it.
 
 Your task is to write a function maskify, which changes all but the last four characters into '#'.

 Examples
 Input Output Comments
 "4556364607935616" "############5616"
 "64607935616" "#######5616"
 "1" "1" No #s if less than 4 characters
 "" "" Make sure to handle empty strings
 "Skippy" "##ippy"
 Documentation
 maskify(cc)
 Parameters:
 cc: String
 A string of any characters.

 Guaranteed Cons*/




func maskify(_ letter: String) -> String {
    var newStr: String = ""
    if letter.isEmpty {
        return letter
    } else if letter.count <= 4 {
        return letter
    } else {
        let lenOfHash = letter.count - 4
        let numHash = String(repeating: "#", count: lenOfHash)
        newStr += numHash + letter.suffix(4)
        return newStr
    }
}

maskify("4556364607935616")




<file_sep>package day_1;

import java.util.Arrays;


/*
Find the sum of the odd numbers within an array, after cubing the initial integers.
The function should return undefined/None/nil/NULL if any of the values aren't numbers.

Note: There are ONLY integers in the JAVA and C# versions of this Kata.
 */
public class FindOddCubes {
    public static void main(String[] args) {
        System.out.println(cubeOdd(new int[] {1, 2, 3, 4}));
    }
    public static int cubeOdd(int[] arr) {
        return Arrays.stream(arr)
                .map(n -> n*n*n)
                .filter(n -> n % 2 != 0)
                .sum();
    }
}
<file_sep>import UIKit

//Mark:- BMI Calculator
/*Write function bmi that calculates body mass index (bmi = weight / height2).
 
 if bmi <= 18.5 return "Underweight"

 if bmi <= 25.0 return "Normal"

 if bmi <= 30.0 return "Overweight"

 if bmi > 30 return "Obese"

*/

func bmi(_ weight: Int, _ height: Double) -> String {
    let result = Double(weight) / (pow(height, 2))

    switch true {
    case result <= 18.5:
        return("Underweight")
    case result <= 25.0:
        return("Normal")
    case result <= 30.0:
        return("Overweight")
    default:
        return("Obese")
    }
}

bmi(50, 1.8)

<file_sep>import UIKit

/*You have to search all numbers from inclusive 1 to inclusive a given number x, that have the given digit d in it.
 The value of d will always be 0 - 9.
 The value of x will always be greater than 0.

 You have to return as an array

 the count of these numbers,
 their sum
 and their product.

 For example:
 x = 11
 d = 1
 ->
 Numbers: 1, 10, 11
 Return: [3, 22, 110]

 If there are no numbers, which include the digit, return [0,0,0].*/


//
//typealias Long = Int64
//
//func numbersWithDigitInside(_ x:Long, _ d: Long) -> [Long] {
//
//    // the parameters to what I can understand
//
//     let check = x
//
//    let secondNum = String(d)
//    var result = [String]()
//
//    // check is x
//
//    for i in (0...check) {
//        result.append(String(i))
//
//    }
//
//   if secondNum == "0" {
//        result.removeFirst()
//    }
//
//    //count is d
//    var newArr = [Long]()
//    var count: Long = 0
//    for i in result {
//        if i.contains(secondNum) {
//            newArr.append(Long(i)!)
//            count += 1
//        }
//    }
//
//    var newestArr = [Long]()
//    for i in newArr {
//        if i == 0 {
//            continue
//        } else {
//            newestArr.append(i)
//        }
//    }
//    print(newestArr)
//    let multiplyResult: Long;
//    if newestArr == [] {
//        multiplyResult = newestArr.reduce(0, *)
//    } else {
//        multiplyResult = newestArr.reduce(1, *)
//    }
//
//
//
//    let addResult = newestArr.reduce(0, +)
//
//    let finalResult = [count, addResult, multiplyResult]
//
////    print("The count of 1 is \(count)")
////    print("The added result of 1 is \(addResult)")
////    print("The multiplied result of 1 is \(multiplyResult)")
////
////
////
////    print(finalResult)
//    return finalResult
//
//}



// MARK:- Easier Method
func numbersWithDigitInside1(_ x: Int64, _ d: Int64) -> [Int64] {
   let numbers = (1...x).filter {String($0).contains(String(d))}
    print(numbers)
    return [Int64(numbers.count),
            numbers.reduce(Int64(0), +),
            numbers.count > 0 ? numbers.reduce(Int64(1), *) : Int64(0)]
}

numbersWithDigitInside1(11,1)


/*numbersWithDigitInside(5,6), [0, 0, 0])
 numbersWithDigitInside(7,6), [1, 6, 6]
 numbersWithDigitInside(11,1), [3, 22, 110]
 numbersWithDigitInside(20,0), [2, 30, 200]
 numbersWithDigitInside(44,4), [9, 286, 5955146588160]*/
<file_sep>import UIKit

/* Braking distance d1 is the distance a vehicle will go from the point when it brakes to when it comes to a complete stop. It depends on the original speed v and on the coefficient of friction mu between the tires and the road surface.
 
 The braking distance is one of two principal components of the total stopping distance. The other component is the reaction distance, which is the product of the speed and the perception-reaction time of the driver.

 The kinetic energy E is 0.5*m*v**2, the work W given by braking is mu*m*g*d1. Equalling E and W gives the braking distance: d1 = v*v / 2*mu*g where g is the gravity of Earth and m the vehicle's mass.

 We have v in km per hour, g as 9.81 m/s/s and in the following we suppose that the reaction time is constant and equal to 1 s. The coefficient mu is dimensionless.

 Tasks.
 The first one is to calculate the total stopping distance in meters given v, mu (and the reaction time t = 1).

 dist(v, mu) -> d = total stopping distance

 The second task is to calculate v in km per hour knowing d in meters and mu with the supposition that the reaction time is still t = 1.

 speed(d, mu) -> v such that dist(v, mu) = d.

 Examples:
 dist(100, 0.7) -> 83.9598760937531

 speed(83.9598760937531, 0.7) -> 100.0

 Notes:
 Remember to convert the velocity from km/h to m/s or from m/s in km/h when necessary.
 Don't forget the reaction time t: t = 1
 Don't truncate or round your results. See in "RUN SAMPLE TESTS" the function assertFuzzyEquals or dotest or ....
 Shell: only dist is tested.
*/

//MARK:- SOLUTION


func dist(_ v: Double, _ mu: Double) -> Double {
    let newV = (v * 1000) / 3600
    let result = pow(newV, 2.0) / (2 * mu * 9.81)
    let total = newV + result
    return total
}
let d1 = dist(100, 0.7)

func speed(_ d: Double, _ mu: Double) -> Double {
    let speed = (-9.81 * mu) - sqrt((pow(9.81, 2) * pow(mu, 2)) + (2 * 9.81 * mu * d ))
    return speed
}
speed(83.9598760937531, 0.7)


<file_sep>package day_4;
/*

Take an integer n (n >= 0) and a digit d (0 <= d <= 9) as an integer.

Square all numbers k (0 <= k <= n) between 0 and n.

Count the numbers of digits d used in the writing of all the k**2.

Call nb_dig (or nbDig or ...) the function taking n and d as parameters and returning this count.

Examples:
n = 10, d = 1
the k*k are 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100
We are using the digit 1 in: 1, 16, 81, 100. The total count is then 4.

nb_dig(25, 1) returns 11 since
the k*k that contain the digit 1 are:
1, 16, 81, 100, 121, 144, 169, 196, 361, 441.
So there are 11 digits 1 for the squares of numbers between 0 and 25.
Note that 121 has twice the digit 1.


 */

import java.util.stream.IntStream;

public class CountTheDigit {
    public static void main(String[] args) {
        System.out.println(IntStream.rangeClosed(0, 10).flatMap(a -> (""+ a * a).chars()).filter(a -> a == 1 + '0').count());

    }
    public static int nbDig(int n, int d) {
        return Math.toIntExact(IntStream.rangeClosed(0, n)
                .flatMap(a -> ("" + a * a).chars())
                .filter(a -> a == (d + '0'))
                .count());
    }
}
<file_sep>package day_5;
/*
Find the total sum of internal angles (in degrees)
in an n-sided simple polygon. N will be greater than 2.
 */

public class SumOfAngles {
    public static int sumOfAngles(int n) {
        return (n - 2) * 180;
    }
}
<file_sep>import UIKit

func amort(_ rate: Double, _ balance: Double, _ term: Int, _ numPayments: Int) -> String {
    var newBalance = balance
    var c: Double
    var n: Double
    var r: Double
    var princ: Double
    var d: Double
    var interest: Double
    
    r = rate / 1200

    d  = 1 - (pow((1 + r), -Double(term)))
    print(d)

    n =  r * balance
    print(n)

    c = n/d
    print(c)

    interest = balance * r
    print(interest)

    princ =  c - interest
    print(princ)

    for _ in 1...numPayments {
        interest = newBalance * r
        princ = c - interest
        newBalance -= (princ)
    }
    
    print("num_payment \(numPayments) c \(Int(round(c))) princ \(Int(round(princ))) int \(Int(round(interest))) balance \(Int(round(newBalance)))")
    
    return "num_payment \(numPayments) c \(Int(round(c))) princ \(Int(round(princ))) int \(Int(round(interest))) balance \(Int(round(newBalance)))"
}

//   testing(7.4, 10215, 24, 20, "num_payment 20 c 459 princ 445 int 14 balance 1809")
//testing(7.9, 107090, 48, 41, "num_payment 41 c 2609 princ 2476 int 133 balance 17794")
amort(7.4, 10215, 24, 20)

<file_sep>import UIKit
let a1 = ["live", "arp", "strong"]
let a2 = ["lively", "alive", "harp", "sharp", "armstrong"]

func inArray(_ a1: [String], _ a2: [String]) -> [String] {
    var newArr: [String] = []
    for i in a1 {
        for j in a2 {
            if j.contains(i){
                newArr.append(i)
            }
            else {
                continue
            }
        }
    }
    let result = Set(newArr)
    
    return Array(result).sorted()
    
}


inArray(a1, a2)
<file_sep>package day_6;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/*
The prime numbers are not regularly spaced. For example from 2 to 3 the step is 1.
 From 3 to 5 the step is 2. From 7 to 11 it is 4.
 Between 2 and 50 we have the following pairs of 2-steps primes:

3, 5 - 5, 7, - 11, 13, - 17, 19, - 29, 31, - 41, 43

We will write a function step with parameters:

g (integer >= 2) which indicates the step we are looking for,

m (integer >= 2) which gives the start of the search (m inclusive),

n (integer >= m) which gives the end of the search (n inclusive)

In the example above step(2, 2, 50) will return [3, 5] which is
the first pair between 2 and 50 with a 2-steps.

So this function should return the first pair of the two prime numbers
spaced with a step of g between the limits m, n if these g-steps
prime numbers exist otherwise nil or null or None or Nothing or [] or "0, 0" or {0, 0}
 or 0 0(depending on the language).

Examples:
step(2, 5, 7) --> [5, 7] or (5, 7) or {5, 7} or "5 7"
step(2, 5, 5) --> nil or ... or [] in Ocaml or {0, 0} in C++
step(4, 130, 200) --> [163, 167] or (163, 167) or {163, 167}
See more examples for your language in "TESTS"

Remarks:
([193, 197] is also such a 4-steps primes between 130 and 200
but it's not the first pair).

step(6, 100, 110) --> [101, 107] though there is a prime
between 101 and 107 which is 103; the pair 101-103 is a 2-step.

Notes:
The idea of "step" is close to that of "gap" but it is not exactly the same.
 For those interested they can have a look at http://mathworld.wolfram.com/PrimeGaps.html.

A "gap" is more restrictive: there must be no primes in
between (101-107 is a "step" but not a "gap". Next kata will be about "gaps":-).

For Go: nil slice is expected when there are no step between m and n.
Example: step(2,4900,4919) --> nil


 */
public class StepsInPrimes {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(step(2, 5, 7)));
    }
    public static long[] step(int g, long m, long n) {
        var ans = new long[g];
        for (long i=m;i<=n;i++){
            if(i%2==1){
                ans[g-1] = i;
                --g;
            }
            return ans;
        }
        return ans;

    }
}
