Skoči na vsebino

P1 - naloga Pretakanje

from time import time
sTime = time()
poteze = [("j", "a"), ("a", "b"), ("b", "j"), ("a", "b"), ("j", "a"), ("a", "b"), ("b", "j"), ("a", "b"), ("a", "j"), ("b", "a"), ("j", "a"), ("a", "j")]

vVal = { "a": 0, "b": 0, "j": pow(10, 2) }
vMax = { "a": 7, "b": 4, "j": pow(10, 4) }

for s, d in poteze:
    transfer = vVal[s] if vVal[s] + vVal[d] <= vMax[d] else vMax[d] - vVal[d]
    vVal[s] -= transfer
    vVal[d] += transfer

    print("%s => %s --- a: %s; b %s" % (s, d, vVal["a"], vVal["b"]))

print("Finished in: ", time() - sTime)

sTime = time()
stanja = [(7, 0), (3, 4), (3, 0), (0, 3), (7, 3), (6, 4), (6, 0), (2, 4), (0, 4), (4, 0), (7, 0), (0, 0)]
previous = (0, 0)

for a, b in stanja:
    diff = {
        "a": a - previous[0],
        "b": b - previous[1]
    }
    # print("A: %s - B: %s - pA: %s - pB: %s - dA: %2s - dB: %2s" % (a, b, previous[0], previous[1], diff["a"], diff["b"]), end="  --  ")
    previous = (a, b)
    source = ""
    destination = ""

    if diff["a"] > 0 and diff["b"] == 0:
        source = "j"
        destination = "a"
    elif diff["a"] == 0 and diff["b"] > 0:
        source = "j"
        destination = "b"
    elif diff["a"] < 0 and diff["b"] > 0:
        source = "a"
        destination = "b"
    elif diff["a"] > 0 and diff["b"] < 0:
        source = "b"
        destination = "a"
    elif diff["a"] == 0 and diff["b"] < 0:
        source = "b"
        destination = "j"
    elif diff["a"] < 0 and diff["b"] == 0:
        source = "a"
        destination = "j"
    else:
        source = "/"
        destination = "/"

    print("a: %s; b %s; --- %s => %s" % ( a, b, source, destination))

print("Finished in: ", time() - sTime)

Zadnja posodobitev: February 27, 2022