8 Комити 6bd54cdf74 ... 07346aaa45

Аутор SHA1 Порука Датум
  Vinicius Teshima 07346aaa45 Adding solution for 27 пре 10 месеци
  Vinicius Teshima a80c850333 Adding an even faster solution for 1299 пре 10 месеци
  Vinicius Teshima 8c32c8c699 Adding solution to 1299 пре 10 месеци
  Vinicius Teshima a7f184529d Adding solution for 2423 пре 10 месеци
  Vinicius Teshima be39114d92 Adding Solution for 3663 пре 10 месеци
  Vinicius Teshima 8268fee63b Adding solution for 2635 пре 10 месеци
  Vinicius Teshima 67623bba84 Making language_chooser.sh create source code пре 10 месеци
  Vinicius Teshima 760cb45cc4 Adding solution for 3452 пре 10 месеци
7 измењених фајлова са 235 додато и 1 уклоњено
  1. 35 0
      Go/1299.go
  2. 44 0
      Python/2423.py
  3. 44 0
      Ruby/27.rb
  4. 40 0
      Ruby/3663.rb
  5. 24 0
      TypeScript/2635.ts
  6. 31 0
      TypeScript/3452.ts
  7. 17 1
      language_chooser.sh

+ 35 - 0
Go/1299.go

@@ -0,0 +1,35 @@
+package main;
+
+import (
+	"os"
+	"fmt"
+)
+
+func replaceElements(arr []int) []int {
+	if len(arr) == 1 { return []int{-1} }
+
+	var arr_size int = len(arr)
+	var ret []int = make([]int, arr_size)
+
+	var max int = 0
+
+	var i int = arr_size - 1
+	for ; i > 0; i -= 1 {
+		ret[i] = max
+		if arr[i] > max { max = arr[i] }
+	}
+	ret[0] = max
+
+	ret[arr_size-1] = -1
+	return ret
+}
+
+func main() {
+	r := func (arr []int, exp []int) {
+		fmt.Printf("replaceElements(%v) = %v | exp: %v\n", arr, replaceElements(arr), exp)
+	}
+	r([]int{17,18,5,4,6,1}, []int{18,6,6,6,1,-1})
+	r([]int{400}, []int{-1})
+
+	os.Exit(0)
+}

+ 44 - 0
Python/2423.py

@@ -0,0 +1,44 @@
+# 2423. Remove Letter To Equalize Frequency
+
+import sys
+
+class Solution:
+    def equalFrequency(self, word: str) -> bool:
+        def check_freq(word) -> bool:
+            l = [0 for _ in range(ord('z')+10)]
+            for c in word:
+                l[ord(c)] += 1
+                pass
+            n = 0
+            for x in l:
+                if x == 0:
+                    continue
+                if n == 0:
+                    n = x
+                    continue
+                if n != x:
+                    return False
+                pass
+            return True
+
+        for i in range(len(word)):
+            if check_freq(word[:i] + word[i+1:]):
+                return True
+            pass
+        return False
+    pass
+
+def main() -> int:
+    def r(word: str, exp: bool) -> None:
+        print(
+            f"Solution().equalFrequency({word}) = {Solution().equalFrequency(word)} | exp: {exp}"
+        )
+        pass
+
+    r('abcc', True)
+    r('aazz', False)
+    r('cccaa', True)
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main())

+ 44 - 0
Ruby/27.rb

@@ -0,0 +1,44 @@
+# 268. Missing Number
+
+# @param {Integer[]} nums
+# @param {Integer} val
+# @return {Integer}
+def remove_element(nums, val)
+  num_diff = 0
+  i = 0
+  nums_size = nums.size()
+  while i < nums_size do
+    if nums[i] != val then
+      num_diff += 1
+    else
+      nums[i] = -1
+    end
+    i += 1
+  end
+  i = 0
+  while i < nums_size do
+    if nums[i] == -1 then
+      j = i+1
+      while nums[j] == -1 do j += 1 end
+      break if j >= nums_size
+      nums[i] = nums[j]
+      nums[j] = -1
+    end
+    i += 1
+  end
+  return num_diff
+end
+
+def main()
+  def r(nums, val, exp, exp_nums)
+    puts "remove_element(#{nums}, #{val}) = #{remove_element(nums, val)} -> #{nums} | exp_nums: #{exp_nums} exp: #{exp}"
+  end
+  r([3,2,2,3], 3, 2, [2,2,-1,-1])
+  r([0,1,2,2,3,0,4,2], 2, 5, [0,1,4,0,3,-1,-1,-1])
+
+end
+
+
+if __FILE__ == $0
+  main()
+end

+ 40 - 0
Ruby/3663.rb

@@ -0,0 +1,40 @@
+# 268. Missing Number
+
+# @param {Integer} n
+# @return {Integer}
+def get_least_frequent_digit(n)
+  l = Array.new(10, 0)
+  while n != 0 do
+    n, d = n.divmod(10)
+    l[d] += 1
+  end
+
+  min_value = 9999999
+  min_index = 0
+  i = 0
+  while i < 10 do
+    if l[i] > 0 and l[i] < min_value then
+      min_value = l[i]
+      min_index = i
+    end
+    i += 1
+  end
+
+  return min_index
+end
+
+def main()
+  def r(n, exp)
+    puts "get_least_frequent_digit(#{n}) = #{get_least_frequent_digit(n)} | exp: #{exp}"
+  end
+
+  r(1553322, 1)
+  r(723344511, 2)
+  r(10, 0)
+
+end
+
+
+if __FILE__ == $0
+  main()
+end

+ 24 - 0
TypeScript/2635.ts

@@ -0,0 +1,24 @@
+// 2635. Apply Transform Over Each Element in Array
+
+
+function map(arr: number[], fn: (n: number, i: number) => number): number[] {
+    let ret: number[] = [];
+    const limit: number = arr.length;
+    for ( let i = 0; i < limit; ++i ) {
+        ret[i] = fn(arr[i], i);
+    }
+    return ret;
+};
+
+function main() {
+    function r(arr: number[], fn: (n: number, i: number) => number, exp: number) {
+        console.log(`map([${arr}], ${fn}) = ${map(arr, fn)} | exp: ${exp}`)
+    }
+
+    r([1,2,3], function plusone(n) { return n + 1; }, [2,3,4])
+    r([1,2,3], function plusI(n, i) { return n + i; }, [1,3,5])
+    r([10,20,30], function constant() { return 42; }, [42,42,42])
+
+}
+
+main()

+ 31 - 0
TypeScript/3452.ts

@@ -0,0 +1,31 @@
+// 3452. Sum of Good Numbers
+
+function sumOfGoodNumbers(nums: number[], k: number): number {
+    let sum = 0;
+    let i: number = 0;
+    const limit: number = nums.length;
+    while ( i < limit ) {
+        let v: number = nums[i];
+        let lg: boolean = true;
+        if ( i-k >= 0 ) { lg = v > nums[i-k]; }
+        let rg: boolean = true;
+        if ( i+k < limit ) { rg = v > nums[i+k]; }
+
+        if ( lg == true && rg == true ) { sum += v; }
+
+        ++i;
+    }
+    return sum;
+};
+
+function main() {
+    function r(nums: number[], k: number, exp: number) {
+        console.log(`sumOfGoodNumbers([${nums}], ${k}) = ${sumOfGoodNumbers(nums, k)} | exp: ${exp}`)
+    }
+
+    r([1,3,2,1,5,4], 2, 12)
+    r([2,1], 1, 2)
+    r([45,38,20], 1, 45)
+}
+
+main()

+ 17 - 1
language_chooser.sh

@@ -12,6 +12,9 @@
 #
 #echo "$languages" | shuf | head -n5
 
+prob="$1"
+test -n "$prob" || { echo "Pass the problem number"; exit 1;}
+
 lang_frek="$(find . -maxdepth 1 -mindepth 1 -not -path './.git' -type d \
     | parallel -j1 'find {} -maxdepth 1 -mindepth 1 -type f | wc -l | xargs echo {}' \
     | sort -k2)"
@@ -20,4 +23,17 @@ lest_amount="$(echo "$lang_frek" | head -n1 | cut -d' ' -f2)"
 
 possibles="$(echo "$lang_frek" | grep "$lest_amount" | sed "s/ ${lest_amount}//g")"
 
-echo "$possibles" | shuf | head -n5
+chosen="$(echo "$possibles" | shuf | head -n1)"
+
+newest_file="$(find "${chosen}" -type f -printf "%T@ %p\n" \
+                 | sort -n \
+                 | cut -d' ' -f 2- \
+                 | tail -n 1)"
+
+bn="$(basename "$newest_file")"
+ext="$(echo "$bn" | cut -d'.' -f2)"
+
+cp "$newest_file" "${chosen}/${prob}.${ext}"
+
+echo "Language ${chosen}"
+echo "File: '${chosen}/${prob}.${ext}'"