intial attempt a R versio of promblem 3