T3 ejercicios de recursividad-grupo6
Upcoming SlideShare
Loading in...5
×
 

T3 ejercicios de recursividad-grupo6

on

  • 1,805 views

 

Statistics

Views

Total Views
1,805
Views on SlideShare
1,805
Embed Views
0

Actions

Likes
0
Downloads
41
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    T3 ejercicios de recursividad-grupo6 T3 ejercicios de recursividad-grupo6 Presentation Transcript

    • INTELIGENCIA ARTIFICIAL - CICLO 2012-I - GRUPO 6
    • (defun fibonacci(posiNum) ( if (= posiNum 1) 1 ( if (= posiNum 2) 2 ( + ( fibonacci(- posiNum 1) ) ( fibonacci(- posiNum 2) ) ) ) ))Ejemplo: fibonacci 6 => 13 2 de 11 INTELIGENCIA ARTIFICIAL - CICLO 2012-I - GRUPO 6
    • (defun factorial(numero) (if (= numero 1) 1 ( * numero ( factorial(- numero 1) ) ) ))Ejemplo: factorial 5 => 120 3 de 11 INTELIGENCIA ARTIFICIAL - CICLO 2012-I - GRUPO 6
    • ( defun sumatoria( Knumero ) ( if (= Knumero 0) 0 ( + Knumero ( sumatoria(- Knumero 1) ) ) ))Ejemplo: sumatoria 5 => 15 4 de 11 INTELIGENCIA ARTIFICIAL - CICLO 2012-I - GRUPO 6
    • (defun multi(multiplicando multiplicador) ( if (= multiplicador 0) 0 ( if (> multiplicador 0) ( + multiplicando ( multi multiplicando (- multiplicador 1) ) ) ( + (* -1 multiplicando) (multi multiplicando (+ multiplicador 1) ) ) ) ))Ejemplo: multi 5 -2 => -10 multi 5 2 => 10 multi -5 2 => -10 5 de 11 multi -5 -2 => 10 INTELIGENCIA ARTIFICIAL - CICLO 2012-I - GRUPO 6
    • ( defun potencia(base exponente) ( if (= exponente 0) 1 ( * base ( potencia base (- exponente 1) ) ) ))Ejemplo: potencia 2 5=> 32 6 de 11 INTELIGENCIA ARTIFICIAL - CICLO 2012-I - GRUPO 6
    • (defun par( lista ) ( cond ( (null lista) nil ) ( ( evenp(car lista) ) ( cons ( car lista) ( par (cdr lista) ) ) ) ( t (par (cdr lista))) ))Ejemplo: par (1 2 9 8 5 9) => (2 8) 7 de 11 INTELIGENCIA ARTIFICIAL - CICLO 2012-I - GRUPO 6
    • ( defun contPar (lista) (cond ( (null lista) 0 ) ( (numberp lista) (if (evenp lista) 1 0) ) ( (cdr lista) ( + (contPar (car lista)) (contPar(cdr lista))) ) ( t ( contPar (car lista) ) ) ))Ejemplo: contPar (1 2 7 9 8 4 3 2)=> 4 8 de 11 INTELIGENCIA ARTIFICIAL - CICLO 2012-I - GRUPO 6
    • ( defun sublista (exp) ( if ( or (null exp) (atom exp) ) 0 ( + ( if (atom (car exp)) 0 1) (sublista (car exp)) (sublista (cdr exp)) ) ))Ejemplo: sublista (4 5 8 (1 2) 8 (7 8 9 (2 4))) => 3 9 de 11 INTELIGENCIA ARTIFICIAL - CICLO 2012-I - GRUPO 6
    • (defun productoEs (v1 v2) ( if ( or (null v1) (null v2) ) 0 ( + ( * (car v1) (car v2) ) ( productoEs (cdr v1) (cdr v2) ) ) ))Ejemplo: productoEs (5 6 1) (2 4 3)=> 37 10 de 11 INTELIGENCIA ARTIFICIAL - CICLO 2012-I - GRUPO 6
    • (defun contAtom (exp) (cond ((null exp) 0 ) ((atom exp) 1) ( t (+ ( contAtom(car exp)) (contAtom(cdr exp)) ) ) ))Ejemplo: contAtom (5 6 2 (4 5 7(1 2)) 2 8 (5 0)) => 12 11 de 11 INTELIGENCIA ARTIFICIAL - CICLO 2012-I - GRUPO 6