Skip to content

Instantly share code, notes, and snippets.

@Btibert3
Created April 9, 2021 21:21
Show Gist options
  • Save Btibert3/3073b1e76506e38900f06e2671433c90 to your computer and use it in GitHub Desktop.
Save Btibert3/3073b1e76506e38900f06e2671433c90 to your computer and use it in GitHub Desktop.
# challenge from charlie
#-----
# Write a function called "reconcileHelper" that processes two arrays of integers.
# Each array passed in will have only distinct numbers (no repeats of the same integer in
# the same array), and the arrays are not sorted.
# Your job is to find out which numbers are in array a, but not array b,
# and which numbers are in array b, but not in array a.
# Your function should return a string formatted as so:
# "Numbers in array a that aren't in array b:
# <num1> <num2> <num3>...
# Numbers in array b that aren't in array a:
# <num1> <num2> <num3>...
# "
# Each list of numbers should be listed in ascending order (lowest to largest)
# So for instance, if I passed in:
# reconcileHelper([5, 3, 4], [4, 3, 10, 6])
# The function would return this multiline string:
# "Numbers in array a that aren't in array b:
# 5
# Numbers in array b that aren't in array a:
# 6 10
# ---
# imports
import numpy as np
# the function
def reconcileHelper(a, b):
"""the function, needs two arrays a and b"""
# coerce to numpy array
# TODO checks + assertions
a = np.array(a)
b = np.array(b)
# make sets
a = set(a)
b = set(b)
# a not b
a_not_b = a.difference(b)
# b not a
b_not_a = b.difference(a)
# return statements
print("Numbers in array a that aren't in array b:")
print(" ".join(str(x) for x in a_not_b))
print("Numbers in array b that aren't in array a:")
print(" ".join(str(x) for x in b_not_a))
# return
return None
# test
a = [1,2,3]
b = [3,4,5]
reconcileHelper(a,b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment