mirror of https://github.com/01-edu/public.git
Xavier Petit
4 years ago
committed by
xpetit
15 changed files with 39 additions and 133 deletions
@ -1,10 +0,0 @@
|
||||
package main |
||||
|
||||
import "strings" |
||||
|
||||
func DoppelGanger(s, substr string) int { |
||||
return strings.LastIndex(s, substr) |
||||
} |
||||
|
||||
func main() { |
||||
} |
@ -1,27 +0,0 @@
|
||||
package main |
||||
|
||||
func main() { |
||||
} |
||||
|
||||
func FindPrevPrime(nbr int) int { |
||||
if nbr < 2 { |
||||
return 0 |
||||
} |
||||
if IsPrime(nbr) { |
||||
return nbr |
||||
} |
||||
return FindPrevPrime(nbr - 1) |
||||
} |
||||
|
||||
func IsPrime(nb int) bool { |
||||
if nb <= 0 || nb == 1 { |
||||
return false |
||||
} |
||||
|
||||
for i := 2; i <= nb/2; i++ { |
||||
if nb%i == 0 { |
||||
return false |
||||
} |
||||
} |
||||
return true |
||||
} |
@ -1,13 +0,0 @@
|
||||
package main |
||||
|
||||
func Halfcontest(h1, m1, h2, m2 int) int { |
||||
t1 := h1*60 + m1 |
||||
t2 := h2*60 + m2 |
||||
t2 = (t2 + t1) / 2 |
||||
h2 = t2 / 60 |
||||
m2 = t2 % 60 |
||||
return h2*100 + m2 |
||||
} |
||||
|
||||
func main() { |
||||
} |
@ -1,21 +0,0 @@
|
||||
package main |
||||
|
||||
func ReachableNumber(n int) int { |
||||
cnt := 0 |
||||
for n > 0 { |
||||
cnt++ |
||||
if n < 10 { |
||||
cnt += 8 |
||||
break |
||||
} else { |
||||
n++ |
||||
} |
||||
for n%10 == 0 { |
||||
n /= 10 |
||||
} |
||||
} |
||||
return cnt |
||||
} |
||||
|
||||
func main() { |
||||
} |
@ -1,45 +0,0 @@
|
||||
package main |
||||
|
||||
func ifNegative(a []string, n int) int { |
||||
if n < 0 { |
||||
n = len(a) + n |
||||
} |
||||
|
||||
if n < 0 { |
||||
n = 0 |
||||
} else if n > len(a) { |
||||
n = len(a) |
||||
} |
||||
|
||||
return n |
||||
} |
||||
|
||||
func Slice(a []string, nbr ...int) []string { |
||||
if len(nbr) == 0 { |
||||
return a |
||||
} |
||||
|
||||
first := nbr[0] |
||||
if len(nbr) == 1 { |
||||
if first < 0 { |
||||
first = len(a) + first |
||||
if first < 0 { |
||||
return a |
||||
} |
||||
} |
||||
return a[first:] |
||||
} |
||||
second := nbr[1] |
||||
|
||||
first = ifNegative(a, first) |
||||
second = ifNegative(a, second) |
||||
|
||||
if first > second { |
||||
return nil |
||||
} |
||||
|
||||
return a[first:second] |
||||
} |
||||
|
||||
func main() { |
||||
} |
Loading…
Reference in new issue