From c2e782122d52acea0e69f8a5a92b40bbbb7072e5 Mon Sep 17 00:00:00 2001
From: Aleksander Sadikov To je ena najlepših in najbolj poučnih nalog. Klasična rekurzija! Problem poskusi zmanjšati. Seveda, prevedi na
-krajši seznam. This is one of the most rewarding exercises. Classic recursion! Try to reduce the problem into a smaller one.
+That, of course, means reducing it to a shorter list. Seznamu odvzamem glavo, rekurzija mi obrne rep in vse, kar moram na koncu narediti jaz je, da glavo vstavim nazaj
-v obrnjen rep na pravo mesto. I divide the list into its head and tail, the recursion reverses the tail, and all I have to do
+is to insert the head into its proper location in the reversed tail. Če je podani seznam If the given list Operator Seveda pa lahko nalogo rešiš brez obeh omenjenih operatorjev, spomni se, da lahko unifikacijo narediš
-implicitno že kar v argumentih predikata (glavi stavka). The operator Of course, you can also solve the exercise without explicit use of either of these two operators, just
+remember that unification is implicitly performed with the predicate's arguments (head of clause). Morda bi bil bolj primeren operator za unifikacijo (=)? Perhaps the operator for unification (=) would be better? Si pomislil na robni pogoj? Kateri seznam je trivialno obrniti? Did you think of a base case? Which list is the most trivial to reverse? Robni primer deluje. Kaj pa rekurzivni, splošni, primer? The base case is ok. However, what about the general recursive case? Vse kaže, da tvoj predikat vedno vrne "false". Si mu dal pravilno ime, si se morda pri imenu zatipkal? Če je ime pravilno, se morda splača preveriti tudi, če se nisi zatipkal kje drugje,
-je morda kakšna pika namesto vejice ali obratno, morda kakšna spremenljivka z malo začetnico? Možno je seveda tudi, da so tvoji pogoji prestrogi ali celo nemogoči (kot bi bila npr. zahteva,
-da je It seems your predicate is If the name is correct, check whether something else is misspelled, perhaps there is a full stop instead of
+a comma or vice versa, or maybe you typed a variable name in lowercase? It is, of course, also possible that your conditions are too restrictive, or even impossible to satisfy
+(as would be, for example, the condition that Je morda na delu potencialno neskončna rekurzija? Kako se bo ustavila? Morda pa je kriv tudi manjkajoč, neustrezen ali preprosto nekompatibilen (s splošnim primerom) robni pogoj? Is there an infinite recursion at work here? How will it ever stop? Or perhaps is there a missing, faulty, or simply incompatible (with the general recursive case) base case? Ta robni pogoj je seveda povsem smiseln, a ga vseeno popravi tako, da bo deloval tudi za prazen seznam.
-Vendar ne imej dveh robnih pogojev, ker bo to podvajalo rešitve./p>
+ Your base case is perfectly reasonable, but it doesn't work for an empty list.
+However, don't use two base cases here, because this will duplicate the solutions./p>
''',
'arbitrary_base_case': '''\
- Kaj je rezultat obračanja praznega seznama? Gotovo ne karkoli (spremenljivka brez določene vrednosti)! What is the result of reversing an empty list? Surely not an arbitrary list (a variable without
+an assigned value)! Ne vsiljuj rekurziji kaj naj vrne, prepusti se ji. To je tisti del, ko narediš predpostavko,
-če je ta izpolnjena, potem bo tvoje pravilo delovalo za večji primer. Je tvoj rekurzivni klic oblike Don't force the result onto recursion, don't tell it what it should return. Just assume it will do its job.
+If this assumption is correct, then the rule will work for a larger case. Is your recursive call of the form Od predikatov Predicates Vstavljaš morda glavo nazaj na začetek obrnjenega repa? To ni pravo mesto, ker s tem samo sestaviš nazaj
-enak seznam kot na začetku. Did you insert the head at the start of the reversed tail? That's not its proper place; in this way
+you just reassemble the original list. Spomni se, rep seznama je vedno seznam! Kako vstaviš element na zadnje mesto? Remember, a list's tail is always another list, not an element.
+How do you insert an element at the end of the list? Vsi trije argumenti predikata All three arguments of predicate Operator L
sestavljen iz glave H
in repa T
-in če predpostavim, da rekurzija obrne T
v obrnjen rep RT
in če RT
na konec
-dodam H
, potem je rezultat obrnjen seznam L
.L
is composed of head H
and tail T
+and if I assume the recursion reverses tail T
into reversed tail RT
and if I add head
+H
at the end of RT
, then the result is reversed list L
.==
je strožji od operatorja =
v smislu, da je za slednjega dovolj,
-da elementa lahko naredi enaka (unifikacija). Morda z uporabo =
narediš predikat
-memb/2
delujoč tudi v kakšni drugi smeri.==
is "stricter" than operator =
in the sense that
+for the latter it is enough to be able to make two elements equal (unification). Perhaps by using =
+you can make the predicate rev/2
more general (e.g. able to work with output arguments becoming inputs).N
enako kot N + 1
ali kaj podobno logično zlobnega).N
is equal to N + 1
,
+or something similarly impossible).rev(T, [RevTail|H])
? S tem vsiljuješ rekurziji
-da mora H
vstavi izven rekurzivnega klica.rev(T, [RevTail|H])
? This forces the recursive call to
+H
outside of the recursive call.last/2
, shiftleft/2
ali shiftright/2
tukaj ne bo veliko
-pomoči. Poskusi raje brez, bo lažje.last/2
, shiftleft/2
, or shiftright/2
will not be of
+much help here. Rather try without them, it will be easier.conc/3
morajo biti seznami. Si prepričan,
-da si ga tako uporabil?conc/3
are lists.
+Are you sure you used it properly?==
je strožji od operatorja =
v smislu, da je za slednjega dovolj,
da elementa lahko naredi enaka (unifikacija). Morda z uporabo =
narediš predikat
-memb/2
delujoč tudi v kakšni drugi smeri.rev/2
delujoč tudi v kakšni drugi smeri.
Seveda pa lahko nalogo rešiš brez obeh omenjenih operatorjev, spomni se, da lahko unifikacijo narediš implicitno že kar v argumentih predikata (glavi stavka).
''', -- cgit v1.2.1