Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

recursive to imperatif

Name: Anonymous 2010-10-11 8:55

I dont understand how to turn recursive algorythm into imperatif one.

Can /prog/ give me an exemple on this:
taking a list and generate all combinaison without double:

def foo(cdr):
    if cdr == []: return ['']
    solution = ['']
    for car in cdr:
        tmp = list(cdr)
        tmp.remove(car)
        solution += [car + x for x in compose_me(tmp)]
    return solution

>>> foo(['1', '2', '3'])
['', '1', '12', '123', '13', '132', '2', '21', '213', '23', '231', '3', '31', '312', '32', '321']

Name: Anonymous 2010-10-11 9:05

[quote]
imperatif
exemple
combinaison
[/quote]

back to /b/ please

Name: Anonymous 2010-10-11 9:22

imperatif
Enjoyer vot're l'Hadopi

Name: Anonymous 2010-10-11 10:22

turn recursive algorythm into imperatif

Why!?

Name: Anonymous 2010-10-11 11:10

To treat the result while finding them,
here i have to wait the end of recursion to have complete data as far as each answer is foo(n) + foo(n - 1) + foo(n -1 -1)...

I though that with no recursive algo it would be possible to have complete result while creatign the list of results

Name: Anonymous 2010-10-11 11:19

>>4
I second that!

Name: Anonymous 2010-10-11 11:47

Uh... Where's the recursion? Also, generally speaking, in order to have complete data, you must wait for a function to complete.

Name: Anonymous 2010-10-11 13:26

It is generating all possibility, so after the whole list is generated it is possible to test them.

But it would be nice that it generate one possibility, test it, then generate second one test it and so on, like that if it find the good possibility before generating the whole list the process can stop.

bad c/c the recursion should have been here:

solution += [car + x for x in foo(tmp)]

Name: Anonymous 2010-10-11 14:09

car
cdr
I don't think you know the meaning of those two words

Name: Anonymous 2010-10-11 20:03

>>9
My other car is a cdr

Name: Anonymous 2010-10-11 22:51

lump

Name: Anonymous 2010-10-12 5:38

she's a bump, a bump, a bump she's in my head

Name: Anonymous 2010-10-12 5:48

COOL FREE PUBLIC WIFI

Name: Anonymous 2010-10-12 7:54

>>13
COOL FREE SOFTWARE http://fsf.org/

Name: Anonymous 2010-10-12 9:42

Someone draw an AA picture of RMSCOOL

Name: Anonymous 2010-10-13 10:28

Recursive -> Imperative can't be done for every instance of a recursive algorithm.

also
#!/bin/sh
echo {1,2,3}{1,2,3}{1,2,3}

Name: Anonymous 2011-02-04 16:50

Name: Anonymous 2013-09-01 10:52



           ,ヘヽ.
           ヽヽ \                __________
          i"´ ̄`"'-、,ヽ.            /
          ヽ二ニ_- 、., `ヽ、____        /
              ,>.、\ .i  ``'ヽ.,      | 良 地 み
            /   `ヽ-'     `ヽ.  | い 球 ん
           / /  i 、  ヽ.      ',  .| と .は な
           | i | ,'!_ ',   ', ',     i. | こ  と  :
           レヽヘ!/、」_`ハ   i  i     | .| ろ  て. :
            _ン  'ト i`i !  ,ハ. |   i   | | だ  も
             .l    └' ' レ' | iヽ!  |  | ヽ、
             `ー.、   "  /| /    |  |    ̄ノノ ̄
::               r'     ,イ /|.     |  ', ....:::::´:::::::::::::::
::::               ,.>-r<,/ |. ',    |   !`ヽ、:::::::::::::::::::
::::::::          /´ヽ::::!へ/ ,ハヽ.   |   ノ::::/::`ヽ:::::::::::::
::::::::::::::        ,.イ:::::::::ヽ:::|-|/、 /i i  ./ /::::/::::::::::::`ヽ:;::::
::::::::::::::::::::: _,,.. -''"::::';::::::::::::ヽ!‐-、,./:::レ'ヽ ./'"::::::::_!;;:::-‐'''"::::::::::
:::::::::::::::;:'">'"\´7  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄r‐-‐''" ̄`ヽ!ヽ.:::::::::::::::
:::::::::::::!/    i   [ZAYAKU]     `ー-ァ    ヽ,!:::::::::::;:イ

Don't change these.
Name: Email:
Entire Thread Thread List