From 0bfa95be7046b101a00f83f082260b5d0e007159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mo=C5=BEina?= Date: Tue, 25 Oct 2016 11:44:09 +0200 Subject: Added new exercises with recursion. Added description for functions. --- python/problems/recursion/where_to/sl.py | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 python/problems/recursion/where_to/sl.py (limited to 'python/problems/recursion/where_to/sl.py') diff --git a/python/problems/recursion/where_to/sl.py b/python/problems/recursion/where_to/sl.py new file mode 100644 index 0000000..365d7cd --- /dev/null +++ b/python/problems/recursion/where_to/sl.py @@ -0,0 +1,55 @@ +import server +mod = server.problems.load_language('python', 'sl') + +id = 20810 +name = 'Kam?' + +description = '''\ +

+od Meglenim gorovjem je, kot nekateri vedo že dolgo, +nekateri pa so morali čakati na film, cel labirint votlin. +Bilbu bi bilo veliko lažje, če bi imel zemljevid. Mi ga imamo. + +Zemljevid lahko shranimo tudi v obliki slovarja, +v katerem so ključi številke sob, vrednosti pa sobe, +v katere pridemo po levi in po desni poti. +Kadar kakšne poti ni, je ustrezni element enak None.

+ + + +
+map = {0: [6, 3], 6: [5, 81], 3: [8, 24], 5: [2, 18],
+81: [None, None], 8: [42, None], 24: [63, 13], 2: [7, 27],
+18: [None, 35], 42: [None, 66], 63: [61, None], 13: [4, 12],
+7: [None, None], 27: [None, None], 35: [None, None], 66: [None, None],
+61: [None, None], 4: [None, None], 12: [None, None]}
+ +

Napiši funkcijo where_to(map, room, path), +ki kot argument prejme zemljevid (npr. zgornji slovar), +začetno sobo (ta bo vedno 0, a to naj te ne moti) in pot (path), +podano kot zaporedje znakov L in R (levo in desno). +Kot rezultat mora vrniti sobo, v katero pelje podana pot.

+ +
+>>> where_to(map, 0, "LLR")
+18
+>>> where_to(map, 0, "RRRR")
+12
+>>> where_to(map, 0, "L")
+6
+>>> where_to(map, 0, "")
+0
+
+ +

Predpostaviti smeš, da je pot pravilna in se nikoli ne odpravi v hodnik, +ki ga ni.

+''' + +plan = [] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''] +} -- cgit v1.2.1