Skip to content

laurelkeys/programming-paradigms

Repository files navigation

programming-paradigms

Exercises and examples developed while taking Programming Paradigms (MC346) at Unicamp.

It's main focus was the familiarization with the functional and logic paradigms, by using Haskell and Prolog. Some neat Python 3 features were also mentioned towards the end of the semester (e.g. iterators, decorators, numpy, etc).

See below a summary of the interesting features/topics covered, linked to their reference files, and the description of the Haskell and Prolog final projects.

Haskell

Topics

  • Basic syntax, list manipulation and recursion: #1 (improved in #2)
  • Tail recursion: #2
  • List comprehension: #3
  • String splitting: #4
  • Binary search tree: #5
  • Currying and higher order functions: #6
  • Piping ($), function composition (.) and matrices: #7
  • Finding the most common vowel in a string: #8
  • Types, Maybe and monads: #9
  • Weighted mean calculation from IO input: #10

A Google Maps/Waze-ish algorithm to calculate the shortest (quickest) path between two points mixing public transportation and walking, implementing Dijkstra's SPF algorithm.

Input

Paths in the form origin destination mode time (walking is defined as a-pe); followed by a new line and: Transports in the form mode wait, where wait is the average wait time untill the public transport (walking wait time is 0 and shouldn't be included here); followed by a newline and: Route in the form start end, where these were used as an origin/destination in the paths.

The above should be added to a file, e.g.:

a b a-pe 0.4
b a a-pe 0.6
b c a-pe 0.5 
c b a-pe 0.5
c d a-pe 0.3
d c a-pe 0.3
a d linha-370 0.1
d f a-pe 3
f h linha-567 1.2
f h a-pe 12.3

linha-370 15.0
linha-567 12.0

a h

Output

The output shows the origin/destination's used in the Paths intercalated with the modes of transports used to travel between them, such that the given trajectory is the quickest one from start to end. Following that, the total time is also outputted, e.g.:

a a-pe b a-pe c linha-370 f a-pe h a-pe i
17.5

Usage

Save the input to a file, for example test-entry.in and run:

>>> runhaskell projeto-01.hs < test-entry.in

Prolog

Topics

  • Binary search tree and dictionary: #13

Search for intersections (of at least 4 characters) between endings and beginnings of strings in a list, and assembly of new strings joining the given ones on it's intersections, inspired by DNA recombination.

Input

A list of strings added to a file, e.g.:

xxxxxababababyyyyyy
yyaaaaaaaaaaa
yyyyyyeeeeeeeeeeeeee
cccccccccccccccxxxxx
fffffffffffffffwwwwww
wwwwwwgggggggggggxx

Output

The combined strings, e.g.:

cccccccccccccccxxxxxababababyyyyyyeeeeeeeeeeeeee
fffffffffffffffwwwwwwgggggggggggxx
yyaaaaaaaaaaa

Usage

Save the input to a file, for example test-entry.in, and run:

>>> swipl -q -g main projeto-02.pl < test-entry.in

Python 3

Topics

  • Iterators: #19
  • Decorators: #20

About

Exercises and examples from Programming Paradigms (MC346)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published