You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
906 B
Go
81 lines
906 B
Go
package cses
|
|
|
|
import "fmt"
|
|
|
|
func WeirdAlgo(n int) string {
|
|
seq := []int{}
|
|
|
|
for n != 1 {
|
|
seq = append(seq, n)
|
|
|
|
if n%2 == 0 {
|
|
n /= 2
|
|
} else {
|
|
n = n*3 + 1
|
|
}
|
|
}
|
|
|
|
seq = append(seq, 1)
|
|
|
|
return fmt.Sprint(seq)
|
|
}
|
|
|
|
func MissingNumber(n int, numbers []int) int {
|
|
|
|
if n != len(numbers)+1 {
|
|
return -1
|
|
}
|
|
|
|
present := make([]bool, n)
|
|
|
|
for _, i := range numbers {
|
|
|
|
if i > n {
|
|
return -2
|
|
}
|
|
|
|
present[i-1] = true
|
|
}
|
|
|
|
for i, b := range present {
|
|
if !b {
|
|
return i + 1
|
|
}
|
|
}
|
|
|
|
return -3
|
|
}
|
|
|
|
func Repetitions(dna string) int {
|
|
curC := ' '
|
|
maxL := 0
|
|
curL := 0
|
|
|
|
for _, c := range dna {
|
|
if c == curC {
|
|
curL += 1
|
|
} else {
|
|
curC = c
|
|
curL = 1
|
|
}
|
|
|
|
if curL > maxL {
|
|
maxL = curL
|
|
}
|
|
}
|
|
|
|
return maxL
|
|
}
|
|
|
|
func IncreasingArray(size int, arr []int) int {
|
|
moves := 0
|
|
|
|
for i := 0; i < len(arr)-1; i++ {
|
|
if arr[i] > arr[i+1] {
|
|
moves += arr[i] - arr[i+1]
|
|
}
|
|
}
|
|
|
|
return moves
|
|
}
|