Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My solution of Dominoes works fine in my local machine and breaks on Exercism #466

Closed
iammateus opened this issue Mar 31, 2022 · 2 comments

Comments

@iammateus
Copy link

iammateus commented Mar 31, 2022

Here is my solution of the Dominoes challenge.

(ns dominoes)

(defn vec-remove
  [pos coll]
  (into (subvec coll 0 pos) (subvec coll (inc pos))))

(defn can-complete-chain?
  [stones rem-stones]
  (cond
    (and (= 0 (count rem-stones)) (= (first (first stones)) (last (last stones)))) true
    (= 0 (count rem-stones)) false
    :else (let [last-stone (last stones)
                necessary-value (last last-stone)
                possible-stones (filter (fn [item] (or (= necessary-value (get item 0)) (= necessary-value (get item 1)))) rem-stones)
                can-complete-chain-arr (map (fn [item]
                                              (let [index-of (.indexOf rem-stones item)
                                                    updated-rem-stones (vec-remove index-of rem-stones)
                                                    right-pos-stone (if (= necessary-value (get item 0)) item (reverse item))
                                                    updated-stones (concat stones [right-pos-stone])
                                                    ]
                                                (can-complete-chain? updated-stones updated-rem-stones)
                                                )
                                              ) possible-stones)
                ]
            (some true? can-complete-chain-arr)
            )
    )
  )

(defn can-chain?
  ([stones]
   (if (= (count stones) 0)
     true
     (can-chain? stones 0)
     )
   )
  ([stones index]
   (let
     [stone (get stones index)
      inverted-stone (reverse stone)
      rem-stones (vec-remove index stones)
      stone-can-be-start-of-chain (can-complete-chain? [stone] rem-stones)
      inverted-stone-can-be-start-of-chain (can-complete-chain? [inverted-stone] rem-stones)
      ]
     (cond
       (or stone-can-be-start-of-chain inverted-stone-can-be-start-of-chain) true
       (<= (inc index) (dec (count stones))) (recur stones (inc index))
       :else false)
     )
   ))

The problem is that in my local machine all tests work fine but on the platform the tests seem to fail.
Can someone help me?

@bobbicodes
Copy link
Member

It's the .indexOf method, which isn't available because the online test runner is powered by SCI.

We apologize for the confusion because there's no way you would have known that. We're still working out how we can make this more clear.

@iammateus
Copy link
Author

It's the .indexOf method, which isn't available because the online test runner is powered by SCI.

We apologize for the confusion because there's no way you would have known that. We're still working out how we can make this more clear.

Thanks for answering! I had to implement a index-of function manually and after that it worked fine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants