Kaynağa Gözat

Adding Initial solution for 1560

Vinicius Teshima 1 hafta önce
ebeveyn
işleme
2eacd9eaad
4 değiştirilmiş dosya ile 66 ekleme ve 0 silme
  1. 4 0
      Makefile
  2. 46 0
      Ruby/1560.rb
  3. 4 0
      Ruby/build.sh
  4. 12 0
      build.sh

+ 4 - 0
Makefile

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

+ 46 - 0
Ruby/1560.rb

@@ -0,0 +1,46 @@
+# 1560. Most Visited Sector in a Circular Track
+
+
+# @param {Integer} n
+# @param {Integer[]} rounds
+# @return {Integer[]}
+def most_visited(n, rounds)
+  expanded = []
+
+  expanded.push(rounds.shift())
+  loop do
+    nxt = rounds.shift()
+    break if nxt.nil?()
+
+    i = expanded.last()
+    loop do
+      i = i+1 > n ? 1 : i+1
+      expanded.push(i)
+      break if i == nxt
+    end
+
+    break if rounds.last().nil?()
+  end
+
+  uses = Hash.new(0)
+  expanded.each {|x| uses[x] += 1}
+
+  max_amount = 0
+  uses.each_pair {|k, v| max_amount = v > max_amount ? v : max_amount}
+
+  res = []
+  uses.each_pair {|k, v| if v == max_amount then res.push(k) end}
+  res.sort()
+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

+ 12 - 0
build.sh

@@ -0,0 +1,12 @@
+#!/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
+