3 kyu

Alphametics Solver

171 of 431docgunthrop
Description
Loading description...
Puzzles
Performance
Cryptography
Algorithms
  • Please sign in or sign up to leave a comment.
  • Origami Master Avatar

    This comment has been hidden.

  • yy_tman Avatar

    How come? Screenshot

  • svemij Avatar

    I am trying to solve this in C#, but I get an error in the beginning with "using Math.NET;", which was preset here (this is the message: "src/Solution.cs(1,7): error CS0246: The type or namespace name 'Math' could not be found(are you missing a using directive or an assembly reference?)"). Any ideas with this? I am new to programming and C# especially, so I apologize if this is some trivial error.

  • artem-phys Avatar

    timed out with python code

    I have no idea how to improve brute-force algorithm except some evident heuristics. However, they do not let avoid n! complexity

  • Persa Avatar

    I think 25-30 test cases can be enough for python.

  • FArekkusu Avatar

    Python 3.8 should be enabled.

  • alexc19 Avatar

    This comment has been hidden.

  • Jari Jarvis Avatar

    How do you color your description?

  • xromatron Avatar

    This comment has been hidden.

  • SansPapyrus683 Avatar

    "Each unique letter may only be assigned to one unique digit" Just to clarify, a number can be assigned to multiple letters, right? For example, can A and B can both have the value 5?

  • user6552504 Avatar

    For JavaScript, module and require are disabled, and most prototypes are frozen (except Array and Fuction)

    Cheers.

  • doooom Avatar

    I tried python first, but time out. Then I switch to JS. Had spent a lot of time to improve the efficiency. I have finished couple of 2kyu and 3kyu katas. To me, this complexity worths a 2kyu.

  • Davo36 Avatar

    Hi, I have passed this kata in GoLang. But the same algorithm doesn't even come close to passing in Python. So what this means is that Python coders are being unfairly treated. Users on the Gitter forum have suggested I mention this here.

    Also, Python is running REALLY slowly on the CW runner just now. This seems to be a known problem. So I guess this needs to be taken into account now please.

  • DunetsNM Avatar

    I suggest to add following extra-long test for more fun (found on internet). Columnwise algorithm would probably choke on it but a more generic approach can do it in fraction of second ;)

    "THIS + A + FIRE + THEREFORE + FOR + ALL + HISTORIES + I + TELL + A + TALE + THAT + FALSIFIES + ITS + TITLE + TIS + A + LIE + THE + TALE + OF + THE + LAST + FIRE + HORSES + LATE + AFTER + THE + FIRST + FATHERS + FORESEE + THE + HORRORS + THE + LAST + FREE + TROLL + TERRIFIES + THE + HORSES + OF + FIRE + THE + TROLL + RESTS + AT + THE + HOLE + OF + LOSSES + IT + IS + THERE + THAT + SHE + STORES + ROLES + OF + LEATHERS + AFTER + SHE + SATISFIES + HER + HATE + OFF + THOSE + FEARS + A + TASTE + RISES + AS + SHE + HEARS + THE + LEAST + FAR + HORSE + THOSE + FAST + HORSES + THAT + FIRST + HEAR + THE + TROLL + FLEE + OFF + TO + THE + FOREST + THE + HORSES + THAT + ALERTS + RAISE + THE + STARES + OF + THE + OTHERS + AS + THE + TROLL + ASSAILS + AT + THE + TOTAL + SHIFT + HER + TEETH + TEAR + HOOF + OFF + TORSO + AS + THE + LAST + HORSE + FORFEITS + ITS + LIFE + THE + FIRST + FATHERS + HEAR + OF + THE + HORRORS + THEIR + FEARS + THAT + THE + FIRES + FOR + THEIR + FEASTS + ARREST + AS + THE + FIRST + FATHERS + RESETTLE + THE + LAST + OF + THE + FIRE + HORSES + THE + LAST + TROLL + HARASSES + THE + FOREST + HEART + FREE + AT + LAST + OF + THE + LAST + TROLL + ALL + OFFER + THEIR + FIRE + HEAT + TO + THE + ASSISTERS + FAR + OFF + THE + TROLL + FASTS + ITS + LIFE + SHORTER + AS + STARS + RISE + THE + HORSES + REST + SAFE + AFTER + ALL + SHARE + HOT + FISH + AS + THEIR + AFFILIATES + TAILOR + A + ROOFS + FOR + THEIR + SAFE == FORTRESSES"

  • Gorgi Avatar

    Just curious how far off I am.. passing the sample tests at 2.7s but timing out on the main test. Am I way off or close? :s (python)

  • Bertjebertje Avatar

    Could you include the constraint that leading zeroes are not allowed to the description?

  • docgunthrop Avatar

    C# translation published.

  • docgunthrop Avatar

    Go translation published.

  • hobovsky Avatar

    This comment has been hidden.

  • Blind4Basics Avatar

    Ruby translation!

    conform to the python version, for the random tests. Perf are varying from 3 to 9s, average around 6.

  • Blind4Basics Avatar

    Java translation!

    I used the fastest version I could come up with, so I'm not sure that the perf constraint isn't a bit "too much". Hard to tell... For now: around 5-6s to complete (2.5s of those are compile time), while the timeout is at 16s in java. But since I do a lot of tests (17 loops against only 3 in python), the timings seems pretty consistent (1s of variation, 2 at most).

    Now the really hard part...: I'll try to do a ruby version... x)

  • Blind4Basics Avatar

    Hi doc,

    I found some ideas of edge cases that you could add. Some of them are "out of the constraints" for now, because they have 10x10 letters are even more, but none of them will cause any performances issue, they are very simple to solve. I designed them to have one unique solution that checks if the implementation behaves correctly in some special cases:

    fixed_tests = (
        "OPPPPPPPPP + OOPPPPPPPP + OOOPPPPPPP + OOOOPPPPPP + OOOOOPPPPP + OOOOOOPPPP + OOOOOOOPPP + OOOOOOOOPP + OOOOOOOOOP = AZERTYUIOP",
        "AACO + AACT + AACO + AACC + AACC + AAOC = CBAXO",
        "ACDCD + ACDCC + ACDCE = DCEAP",
        "P + OPPPPPPPPP + OOPPPPPPPP + OOOPPPPPPP + OOOOPPPPPP + OOOOOPPPPP + OOOOOOPPPP + OOOOOOOPPP + OOOOOOOOPP + OOOOOOOOOP = AZERTYUIOP",
        )
    
    1. handle one column with the exact same digit everywhere (unkown)
    2. same as above, but with a non zero digit (unkown)
    3. check that the code handle encountering a column where all the digits have already been found (without being a column with only one digit)
    4. this one is a bit special. It's valid, and just need a small update in the code but, currently, both our solutions fail on this one. P is a zero. ;) (note: this one need an update of your regex because it's considered invalid)

    Cheers!

  • JohanWiltink Avatar

    Can there be leading zeroes?

  • Blind4Basics Avatar

    Hi,

    Just to be sure (might be useful to add those ino in the description?):

    • only sums?
    • only 1 word on the right of the equal?
  • docgunthrop Avatar

    JavaScript translation coming soon...