package main import "fmt" func bubble_sort(dataset []int, amout_of_integers int){ for i := 0; i <= amout_of_integers; i++ { for j := amout_of_integers; j >= i + 1; j-- { if dataset[j] < dataset[j-1] { dataset[j], dataset[j-1] = dataset[j-1], dataset[j] } } } } func main(){ dataset := []int{5, 2, 4, 6, 1, 3}; fmt.Println(dataset) bubble_sort(dataset, 5); fmt.Println(dataset) }
- package main
- import "fmt"
func swap(dataset []int, a, b int) {var x int = dataset[a]dataset[a] = dataset[b]dataset[b] = x}- func bubble_sort(dataset []int, amout_of_integers int){
- for i := 0; i <= amout_of_integers; i++ {
- for j := amout_of_integers; j >= i + 1; j-- {
- if dataset[j] < dataset[j-1] {
swap(dataset, j, j - 1)- dataset[j], dataset[j-1] = dataset[j-1], dataset[j]
- }
- }
- }
- }
- func main(){
- dataset := []int{5, 2, 4, 6, 1, 3};
- fmt.Println(dataset)
- bubble_sort(dataset, 5);
- fmt.Println(dataset)
- }
from math import sqrt def distance2D(pA, pB): if pA == pB: return 0 (xA, yA), (xB, yB) = pA, pB return sqrt((xA - xB)**2 + (yA - yB)**2) def distance3D(pA, pB): if pA == pB: return 0 (xA, yA, zA), (xB, yB, zB) = pA, pB return sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2)
- from math import sqrt
- def distance2D(pA, pB):
- if pA == pB: return 0
xA, yA = tuple(pA); xB, yB = tuple(pB)- (xA, yA), (xB, yB) = pA, pB
- return sqrt((xA - xB)**2 + (yA - yB)**2)
- def distance3D(pA, pB):
- if pA == pB: return 0
xA, yA, zA = tuple(pA); xB, yB, zB = tuple(pB)- (xA, yA, zA), (xB, yB, zB) = pA, pB
- return sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2)
from functools import lru_cache @lru_cache() def fib(n): if n < 2: return 1 return fib(n-1) + fib(n-2)
- from functools import lru_cache
- @lru_cache()
- def fib(n):
memo = {0:1, 1:1}def recursiveFib(n):if n not in memo:memo[n] = recursiveFib(n-1)+recursiveFib(n-2)return memo[n]return recursiveFib(n)- if n < 2: return 1
- return fib(n-1) + fib(n-2)