---
# System prepended metadata

title: WDI 4.3

---

---
title: WDI 4.3
---
```python=
def nwd_list (list):
    list = sorted(list)
    current_nwd = nwd(list[0], list[1])
    for i in range(0, len(list)):
        if list[i]%current_nwd != 0:
            current_nwd = nwd(current_nwd, list[i])
    print(current_nwd)

def  nwd (a, b):
    if a < b:
        a, b = b, a
    while b > 0:
        reszta = a%b
        a = b
        b = reszta
    return a

nwd_list([60, 78, 36, 18, 6])

#v2
from wdi.lib.wdi import Array, printw
import random


def get_min(source):
    min_item = source[0]

    for i in range(1, len(source)):
        item = source[i]
        if min_item > item:
            min_item = item

    return min_item


def nwd_list(list):
    min_item = get_min(list)
    current_nwd = nwd(min_item, list[0])

    for i in range(0, len(list)):
        item = list[i]
        if item % current_nwd != 0:
            current_nwd = nwd(current_nwd, item)

    printw("NWD = ", current_nwd)


def nwd(a, b):
    if a < b:
        k = a
        a = b
        b = k
    while b > 0:
        reszta = a % b
        a = b
        b = reszta
    return a

source = Array(4)

source[0] = 16
source[1] = 32
source[2] = 96
source[3] = 144

nwd_list(source)


```
