codewars / codewars-runner-cli

Old CodeRunner project. See https://github.com/codewars/runner instead.
GNU Affero General Public License v3.0
400 stars 141 forks source link

hardly interpretable swift error while code execution #455

Closed Lausbert closed 7 years ago

Lausbert commented 7 years ago

While trying to "attempt" the "Some Egyptian fractions" kata I got an error I don't know how to solve, even after research. "Run Sample Tests" is working fine. Name on codewars is Lausbert.

Solution:

func decompose(_ nrStr: String, _ drStr: String) -> String {

    guard var nr = Int(nrStr), var dr = Int(drStr) else {return "input error"}
    let nrDrGcd = gcd(nr, dr)
    nr = nr/nrDrGcd; dr = dr/nrDrGcd

    if nrStr == "1" {return String(nr) + "/" + String(dr)}

    if nr/dr >= 1 {return String(nr/dr)}
    let subtractDr = dr/nr + 1

    subtract(&nr, &dr, subtractDr)
    return "1/" + String(subtractDr) + "," + decompose(String(nr), String(dr))
}

func subtract(_ nr: inout Int, _ dr: inout Int, _ subtractDr: Int) {
    let drLcm = lcm(dr, subtractDr)
    let factorOne = drLcm/dr, factorTwo = drLcm/subtractDr
    nr = factorOne*nr-factorTwo
    dr = drLcm
}

func gcd(_ a : Int, _ b : Int) -> Int {
    var b = b, a = a
    while b != 0 {
        (a, b) = (b, a % b)
    }
    return abs(a)
}

func lcm( _ a : Int, _ b : Int) -> Int {
    return (a / gcd(a, b)) * b
}

Error:

0  swift           0x00000000034bf568 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift           0x00000000034c0146
2  libpthread.so.0 0x00007f2a5b910330
3  libpthread.so.0 0x00007f2a5bc857c5
4  libpthread.so.0 0x00007f2a5bc85ea1
5  libpthread.so.0 0x00007f2a5bc872e8
6  libpthread.so.0 0x00007f2a5bc85efb
7  libpthread.so.0 0x00007f2a5bc87395
8  libXCTest.so    0x00007f2a58083641
9  libXCTest.so    0x00007f2a580a2460
10 libXCTest.so    0x00007f2a5809f5c5
11 libXCTest.so    0x00007f2a580a1806
12 libXCTest.so    0x00007f2a580899e0
13 libXCTest.so    0x00007f2a580835c5     _TF6XCTest14XCTAssertEqualuRxs9EquatablerFTKzT_xKzT_xKT_SS4fileVs12StaticString4lineSu_T_ + 101
14 libXCTest.so    0x00007f2a5bc85deb _TF6XCTest14XCTAssertEqualuRxs9EquatablerFTKzT_xKzT_xKT_SS4fileVs12StaticString4lineSu_T_ + 62924939
15 libXCTest.so    0x00007f2a5bc86559 _TF6XCTest14XCTAssertEqualuRxs9EquatablerFTKzT_xKzT_xKT_SS4fileVs12StaticString4lineSu_T_ + 62926841
16 libXCTest.so    0x00007f2a5bc87880 _TF6XCTest14XCTAssertEqualuRxs9EquatablerFTKzT_xKzT_xKT_SS4fileVs12StaticString4lineSu_T_ + 62931744
17 libXCTest.so    0x00007f2a5bc85b5e _TF6XCTest14XCTAssertEqualuRxs9EquatablerFTKzT_xKzT_xKT_SS4fileVs12StaticString4lineSu_T_ + 62924286
18 libXCTest.so    0x00007f2a5bc87815 _TF6XCTest14XCTAssertEqualuRxs9EquatablerFTKzT_xKzT_xKT_SS4fileVs12StaticString4lineSu_T_ + 62931637
19 libXCTest.so    0x00007f2a580b66ab
20 libXCTest.so    0x00007f2a5808d1a2
21 libXCTest.so    0x00007f2a580b6660
22 libXCTest.so    0x00007f2a580b63e0
23 libXCTest.so    0x00007f2a5808c280 _TFC6XCTest10XCTestCase10invokeTestfT_T_ + 112
24 libXCTest.so    0x00007f2a580a4219 _TTSf4g_n___TFC6XCTest10XCTestCase7performfCS_9XCTestRunT_ + 313
25 libXCTest.so    0x00007f2a5808c14e _TFC6XCTest10XCTestCase7performfCS_9XCTestRunT_ + 14
26 libXCTest.so    0x00007f2a5808bf45 _TFC6XCTest6XCTest3runfT_T_ + 629
27 libXCTest.so    0x00007f2a580a4ee5 _TTSf4g_n___TFC6XCTest11XCTestSuite7performfCS_9XCTestRunT_ + 789
28 libXCTest.so    0x00007f2a580a53b3 _TTSf4g_n___TFC6XCTest11XCTestSuite7performfCS_9XCTestRunT_ + 2019
29 libXCTest.so    0x00007f2a580a53b3 _TTSf4g_n___TFC6XCTest11XCTestSuite7performfCS_9XCTestRunT_ + 2019
30 libXCTest.so    0x00007f2a580916db _TF6XCTest7XCTMainFGSaT13testCaseClassMCS_10XCTestCase8allTestsGSaTSSFzS0_T_____Os5Never + 4283
31 libXCTest.so    0x00007f2a5bc850e9 _TF6XCTest7XCTMainFGSaT13testCaseClassMCS_10XCTestCase8allTestsGSaTSSFzS0_T_____Os5Never + 62868169
32 swift           0x0000000000c795f2 llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 1042
33 swift           0x0000000000c7d0ff llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::vector<std::string, std::allocator<std::string> > const&, char const* const*) + 1215
34 swift           0x000000000083ca6f swift::RunImmediately(swift::CompilerInstance&, std::vector<std::string, std::allocator<std::string> > const&, swift::IRGenOptions&, swift::SILOptions const&) + 2303
35 swift           0x00000000008364f8
36 swift           0x0000000000831377 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2551
37 swift           0x00000000007f8788 main + 3016
38 libc.so.6       0x00007f2a5a0b9f45 __libc_start_main + 245
39 swift           0x00000000007f5e56
Stack dump:
0.  Program arguments: /swift-vol/swift-gen/usr/bin/swift -frontend -interpret /tmp/swift117614-14-7ri4d6.pqlxnfusor/solution.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -module-name solution
jhoffner commented 7 years ago

@kazk this might be due to the new swift runner.

jhoffner commented 7 years ago

Note that the new runner is up on www but not for red users yet.

Update: actually maybe the new Swift runner didn't get deployed, I'm seeing multiple Passed statements under each spec when I test. That shouldn't be the case (should only ever be one correct?).

kazk commented 7 years ago

@jhoffner I don't think it's the new swift-runner because of 0. Program arguments: /swift-vol/swift-gen/usr/bin/swift. The new image doesn't create volumes.


Note that the new runner is up on www

How are the compatibility issues handled? I'm also concerned about how I avoided the concatenation. I can test some on preview if you can deploy it there.

kazk commented 7 years ago

@Lausbert

"Run Sample Tests" is working fine.

Actual tests might contain some edge cases. How are you validating the input? Is it possible to do division by zero somewhere?

Lausbert commented 7 years ago

You were actually right. Thank you and sorry for wasting your time! :)

kazk commented 7 years ago

@Lausbert no problem. I'll look into if we can improve the error output somehow.