6 Commits b4888f28df ... 710191e357

Autore SHA1 Messaggio Data
  Vinicius Teshima 710191e357 Adding solution for 1108 10 mesi fa
  Vinicius Teshima be6d0b8f09 Adding even faster solution for 3637 10 mesi fa
  Vinicius Teshima f9607ecaf8 Adding Solution for 3637 10 mesi fa
  Vinicius Teshima 836b2ab82b Adding even faster solution for 1560 10 mesi fa
  Vinicius Teshima 9756c35338 Adding faster solution of 1560 10 mesi fa
  Vinicius Teshima 2eacd9eaad Adding Initial solution for 1560 10 mesi fa
8 ha cambiato i file con 165 aggiunte e 0 eliminazioni
  1. 36 0
      Go/1108.go
  2. 7 0
      Go/build.sh
  3. 4 0
      Makefile
  4. 53 0
      Ruby/1560.rb
  5. 4 0
      Ruby/build.sh
  6. 45 0
      TypeScript/3637.ts
  7. 6 0
      TypeScript/build.sh
  8. 10 0
      build.sh

+ 36 - 0
Go/1108.go

@@ -0,0 +1,36 @@
+package main;
+// 1108. Defanging an IP Address
+
+import (
+	"os"
+	"fmt"
+)
+
+func defangIPaddr(address string) string {
+	var res [3+3+3+3+9]rune
+	var i int = 0
+
+	for _, c := range address {
+		if c == '.' {
+			res[i] = '['; i += 1
+			res[i] = '.'; i += 1
+			res[i] = ']'; i += 1
+			continue
+		}
+		res[i] = c
+		i += 1
+	}
+
+	return string(res[:i])
+}
+
+func main() {
+	r := func (addr string) {
+		fmt.Printf("defangIPaddr(\"%s\") -> \"%s\"\n", addr, defangIPaddr(addr))
+	}
+
+	r("1.1.1.1")
+	r("255.100.50.0")
+
+	os.Exit(0)
+}

+ 7 - 0
Go/build.sh

@@ -0,0 +1,7 @@
+#!/bin/sh
+
+newest_file="$(find ./ -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2- | tail -n 1)"
+
+set -x
+go run $newest_file
+

+ 4 - 0
Makefile

@@ -0,0 +1,4 @@
+
+.PHONY: all
+all:
+	sh ./build.sh

+ 53 - 0
Ruby/1560.rb

@@ -0,0 +1,53 @@
+# 1560. Most Visited Sector in a Circular Track
+
+
+# @param {Integer} n
+# @param {Integer[]} rounds
+# @return {Integer[]}
+def most_visited(n, rounds)
+  uses = Array.new(n+1, 0)
+  i = 0
+  while i < (rounds.size()-1)
+    x = rounds[i]
+    tgt = rounds[i+1]
+    while x != tgt
+      uses[x] += 1
+      x = x+1 > n ? 1 : x+1
+    end
+    i += 1
+  end
+  uses[rounds[-1]] += 1
+
+  max_amount = 0
+
+  i = 1
+  while i < uses.size()
+    if uses[i] > max_amount
+      max_amount = uses[i]
+    end
+    i += 1
+  end
+
+  res = []
+
+  i = 1
+  while i < uses.size()
+    if uses[i] == max_amount
+      res.push(i)
+    end
+    i += 1
+  end
+  res
+end
+
+
+def main()
+  puts String(most_visited(4, [1, 3, 1, 2]) == [1,2])
+  puts String(most_visited(2, [2,1,2,1,2,1,2,1,2]) == [2])
+  puts String(most_visited(7, [1,3,5,7]) == [1,2,3,4,5,6,7])
+end
+
+
+if __FILE__ == $0
+  main()
+end

+ 4 - 0
Ruby/build.sh

@@ -0,0 +1,4 @@
+newest_file="$(find ./ -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2- | tail -n 1)"
+
+set -x
+ruby $newest_file

+ 45 - 0
TypeScript/3637.ts

@@ -0,0 +1,45 @@
+// 3637. Trionic Array I
+
+
+function isTrionic(nums: number[]): boolean {
+    if ( nums.length < 4 ) { return false }
+
+    function isIncreasing(s, e: number): boolean {
+        let i: number = s
+        while ( i < e ) { if ( nums[i] >= nums[i+1] ) { return false } i++ }
+        return true
+    }
+
+    function isDecreasing(s, e: number): boolean {
+        let i: number = s
+        while ( i < e ) { if ( nums[i] <= nums[i+1] ) { return false } i++ }
+        return true
+    }
+
+    let p: number = 1
+    let q: number = 2
+    let nlen: number = nums.length - 1
+
+    while ( true ) {
+        if ( isIncreasing(0, p)
+             && isDecreasing(p, q)
+             && isIncreasing(q, nlen) ) { return true }
+        q++
+        if ( q >= nlen ) {
+            p++
+            q = p+1
+            if ( q >= nlen ) { return false }
+        }
+    }
+
+    return false
+};
+
+function main() {
+    function r(n: number[]) { console.log(`[${n}] = ${isTrionic(n)}`) }
+    r([1,3,5,4,2,6])
+    r([2,1,3])
+    r([1,2,1,2])
+}
+
+main()

+ 6 - 0
TypeScript/build.sh

@@ -0,0 +1,6 @@
+#!/bin/sh
+
+newest_file="$(find ./ -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2- | tail -n 1)"
+
+set -x
+bun $newest_file

+ 10 - 0
build.sh

@@ -0,0 +1,10 @@
+#!/bin/sh
+
+newest_dir="$(find ./ -type f -printf "%T@ %p\n" \
+                | sort -n \
+                | cut -d' ' -f 2- \
+                | tail -n 1 \
+                | xargs dirname)"
+
+sh $newest_dir/build.sh
+