Code Monkey home page Code Monkey logo

lab3b-f17's Introduction

CPEN 221 / Fall 2017

Lab 3B: Problem Solving / Programming Proficiency Practice

General Instructions

  • Can you solve the provided question in one hour?
  • Skeleton code can be obtained by cloning this repository. Add JUnit to your build path in Eclipse.

Addition Closure

The skeleton source code for this question is in the package additionClosure. You have to implement the methods isClosed.

You are given a List of Integers, listInt, and another integer n. We will define closure under addition for listInt to mean that for two distinct values of i and j, (listInt[i]+listInt[j]) % n is in listInt or k * n + (listInt[i]+listInt[j]) % n (for some int k) is in listInt.

Your goal is to determine if a given List of Integers is closed under addition for some modulus n. You will implement a method, isClosed, that will return true if a List is closed under addition for a given n and false otherwise.

Examples

  • input list: [-1, 0, 1]; n = 2

    • Returns: true
    • (-1 + 0) % 2 = -1; (-1 + 1) % 2 = 0, (0 + 1) % 2 = 1.
  • input list: [-2, 3]; n = 4

    • Returns: false
  • input list: [1, 1, 0]; n = 2

    • Returns: true
  • input list: [1, 1]; n = 3

    • Returns: false
  • input list: [1, 1, 2]; n = 2

    • Returns: true
  • input list: [0, 1, 1, 2]; n = 2

    • Returns: true
  • input list: [0, 1, 100, 50, 50], n = 100

    • Return: false
  • input list: [0, 1, 100, 50, 50], n = 50

    • Return: true

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.