Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

EECS 468 Fall 2023 ICPs, Assignments of Computer Science

programming paradigms, mainly ICPs

Typology: Assignments

2022/2023

Uploaded on 04/04/2024

mikaela-navarro
mikaela-navarro 🇺🇸

3 documents

Partial preview of the text

Download EECS 468 Fall 2023 ICPs and more Assignments Computer Science in PDF only on Docsity! Author: Mikaela Navarro KU ID: 2998217 Date Created: 11/12/23 Program Name: Assignment 7 Description: Haskell functions for replicate, perfects, find, positions, and scalarproduct Inputs: number of replications, element to replicate, number of perfects, element of find, list of pairs to find, element to look for position, list to look at for position, and two lists of numbers for scalarproduct Outputs: list of replicated elements, list of perfect numbers, list of found values, list of index positions, and a value of the scalar product Collaborators: ChatGPT and an online haskell compiler (tutorialspoint) Date Updated: 11/13/23 -- the type signature of the function takes an integer and a value (a), then it will result in a list of the value repeated the number of times by the integer replicate' :: Int -> a -> [a] -- the replicate function is defined by taking in 'n' and 'x' as the arguments, and by using a list comprehension, for every x that will appear, it will repeat it until the list is the length of n replicate' n x = [x | _ <- [1..n]] -- the type signature of the function takes an integer and result in a list of integer(s) perfects :: Int -> [Int] -- the perfects function is defined by taking in 'n' as the argument, and by using a list comprehension, for every x (integer that will appear) it will look at the numbers of x from 1 to x-1 (y) and check if the remainder of y/[1..x-1] is zero, if it is zero, then the sum of each y should be the same number as x, then it will be in the list perfects n = [x | x <- [1..n], x == sum [y | y <- [1..x-1], x `mod` y == 0]] -- the type signature of the find function takes a key and makes a table, and returns a of the value(s) that have the key find :: Eq a => a -> [(a,b)] -> [b] -- the find function takes in a key and table, look for the pairs that have the key, and return a list with those corresponding values find key table = [value | (k,value) <- table, k == key] -- the type signature of the positions function is taking an element and a list, and return a list of integers positions :: Eq a => a -> [a] -> [Int] -- the positions functions takes in the element to look for, and a list to look into, use the zip function to pair the elements of the list and its index, then use the find function to find the indexes that has the element as a list positions x xs = find x (zip xs [0..])
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved