diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2024-10-03 21:13:24 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2024-10-03 21:13:24 +0100 |
| commit | 7e66febccdc320ea321a9b1fa2b709b25599d5dc (patch) | |
| tree | ff7c2ddaf4a1cb03fa427838d6aecb393cc732c6 /challenge-171/paulo-custodio/python/ch-2.py | |
| parent | d33b08c40ad968f11986685d38b40b59c13f1f1d (diff) | |
| download | perlweeklychallenge-club-7e66febccdc320ea321a9b1fa2b709b25599d5dc.tar.gz perlweeklychallenge-club-7e66febccdc320ea321a9b1fa2b709b25599d5dc.tar.bz2 perlweeklychallenge-club-7e66febccdc320ea321a9b1fa2b709b25599d5dc.zip | |
Add Python solution to challenge 171
Diffstat (limited to 'challenge-171/paulo-custodio/python/ch-2.py')
| -rw-r--r-- | challenge-171/paulo-custodio/python/ch-2.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-171/paulo-custodio/python/ch-2.py b/challenge-171/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..f780acf173 --- /dev/null +++ b/challenge-171/paulo-custodio/python/ch-2.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +# Challenge 171 +# +# Task 2: First-class Function +# Submitted by: Mohammad S Anwar +# +# Create sub compose($f, $g) which takes in two parameters $f and $g as +# subroutine refs and returns subroutine ref i.e. compose($f, $g)->($x) = +# $f->($g->($x)) +# +# e.g. +# +# $f = (one or more parameters function) +# $g = (one or more parameters function) +# +# $h = compose($f, $g) +# $f->($g->($x,$y, ..)) == $h->($x, $y, ..) for any $x, $y, ... + +import sys + +def compose(f, g): + return lambda x: f(g(x)) + +def times3(x): + return 3 * x + +def times5(x): + return 5 * x + +h = compose(times3, times5) +print(h(int(int(sys.argv[1])))) |
