<commit_before>;;;
;;; COGS 502 Symbols and Programming
;;; Sample solutions for Mid-term Exam 1
;;;

;; Q3

(defun isect (set1 set2)
  (let ((store nil))
    (dolist (x set1 (reverse store))
      (if (member x set2)
        (setf store (cons x store))))))

;; Q4 

(defun nthcdrr (n lst)
  (let ((counter 1)
        (result nil))
    (dolist (x lst (reverse result))
      (if (> counter n)
        (setf result (cons x result)))
      (setf counter (+ counter 1)))))

(defun nthcdrr2 (n lst)
  (let ((counter 1)
        (result lst))
    (dolist (x lst result)
      (if (<= counter n)
        (setf result (cdr result)))
      (setf counter (+ counter 1)))))

;; Q5

(defun rotate-left (lst)
  (let ((take nil)
        (store nil))
    (dolist (x lst (append store (list (car lst))))
      (if take 
        (setf store (append store (list x)))
        (setf take t)))))<commit_msg>1541670052<commit_after>;;;
;;; COGS 502 Symbols and Programming
;;; Sample solutions for Mid-term Exam 1
;;;

;; Q3

(defun isect (set1 set2)
  (let ((store nil))
    (dolist (x set1 (reverse store))
      (if (member x set2)
        (setf store (cons x store))))))

;; Q4 

(defun nthcdrr (n lst)
  (let ((counter 1)
        (result nil))
    (dolist (x lst (reverse result))
      (if (> counter n)
        (setf result (cons x result)))
      (setf counter (+ counter 1)))))

(defun nthcdrr2 (n lst)
  (let ((counter 1)
        (result lst))
    (dolist (x lst result)
      (if (<= counter n)
        (setf result (cdr result)))
      (setf counter (+ counter 1)))))

;; Q5

(defun rotate-left (lst)
  (let ((take nil)
        (store nil))
    (dolist (x lst (append store (list (car lst))))
      (if take 
        (setf store (append store (list x)))
        (setf take t)))))

; for fully correct behavior:

(defun rotate-left2 (lst)
  (let ((take nil)
        (store nil))
    (dolist (x lst (if lst (append store (list (car lst)))))
      (if take 
        (setf store (append store (list x)))
        (setf take t)))))
{'fraction_non_alphanumeric': 0.15930521091811414, 'fraction_numerical': 0.021339950372208438, 'mean_word_length': 2.422750424448217, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6571221', 'n_tokens_mistral': 770, 'n_tokens_neox': 737, 'n_words': 258}