Beta

Unicode Math

Description
Loading description...
Unicode
Fundamentals
  • Please sign in or sign up to leave a comment.
  • user9644768 Avatar

    Please use new python test framework.

  • lechevalier Avatar

    Guess I share Voile's point of view: this kata - and especially the notion of implicit values of a unicode string - is too vague to be considered helpful. There are litterally too much possibilities to extract a value out of unicode values, and no visible example or clean description to put warriors on the right path.

    I understand your point, trying to describe this task without pointing the answer, but at the moment, description nearly doesn't give any hint at all.

    • lechevalier Avatar

      An interesting example that you can put in the description is:

      unicode_math('3½', [lambda a, b: a + b]) == 3.5
      

      This should allow players to grasp what you intend by implicit value of a unicode character without spoiling too much.

    • zebulan Avatar

      @lechevalier,

      I have added your example to the description.

      Thanks for the downvote!

      Suggestion marked resolved by zebulan 8 years ago
    • lechevalier Avatar

      Let's see if this example alone is sufficient; in that case, I will update my vote.

    • zebulan Avatar

      @lechevalier,

      Your comment doesn't make much sense since this kata has only had 22 (oops!) 9 people finish it in a year. Who exactly are you expecting to come along and find it "sufficient" (at the bottom of the Beta kata list)? All you've done is push it even farther down haha

    • lechevalier Avatar

      In fact, 22 people try to complete this kata, only 9 succeeded: you should ask why there are so few completions. Anyway, you should expect this kata to be validated sooner as it only needs one more completion to proceed.

    • zebulan Avatar

      @lechevalier,

      In fact, 22 people try to complete this kata, only 9 succeeded

      My mistake, thanks for pointing out the typo! Unfortunately, it makes my point even stronger.

      you should ask why there are so few completions.

      Laziness? Finding a function in the Python standard library is easy, even you managed to do it.

      Anyway, you should expect this kata to be validated sooner as it only needs one more completion to proceed.

      I don't mind if this kata doesn't get approved, it was just a quick attempt to share something I learned with others.

      Thanks for your time!

  • Blind4Basics Avatar

    Well... That was useful... But that was painful... :o

    Maybe you should add a comment/hint about where to find the "trick" to convert the "weirdest unicodes" (I'm not used to handle unicodes. I spent a long time searching for a way to convert things like \U0001420a or something like that...)

    • zebulan Avatar

      This comment has been hidden.

    • Blind4Basics Avatar

      This comment has been hidden.

    • zebulan Avatar

      @Blind4Basics,

      It took me almost 1 hour before I found what I needed.

      My goal with this kata was to try and help people learn something new (which it seems like you did!) but I never intended for it to take that long to solve. My katas are far from perfect but I just thought it was something I hadn't seen used in a kata before so I tried to contribute back to Codewars.

      What would you think about to simply add a link toward the unicode python documentation?

      That's a great idea, I'll add that link to the description now! Hopefully that will help people learn something new and be able to solve this kata in a reasonable amount of time.

      Thanks for the suggestion!

    • Blind4Basics Avatar

      cool thing! :)

      Suggestion marked resolved by Blind4Basics 8 years ago
  • Voile Avatar

    This comment has been hidden.

    • zebulan Avatar

      @Voile,

      Unicode characters are involved

      The kata is called "Unicode Math" and has two other mentions of "unicode" in the description.

      ... characters should also be accepted and converted, not just digits

      There was a specific reason for me not to use that word, feel free to enlighten yourself by reading the other comments.


      Thanks for another well thought out comment!

      Issue marked resolved by zebulan 8 years ago
    • Voile Avatar

      This comment has been hidden.

    • zebulan Avatar

      @Voile,

      The amusing part is how much trouble you seem to have had with such a simple kata.

  • daddepledge Avatar

    In one of your example tests, unicode_math(u'a1b2', [lambda a, b: a - b]) == -1

    Am I supposed to skip the a & b, leaving a 1 & 2 hence 1 - 2 = -1?

    • zebulan Avatar

      @daddepledge,

      Yes, the a and b dont have the "implicit values" needed for the mathematical operations. So yes, in that case 1 - 2 = -1.

      Sorry about being so vague, I just couldn't figure out how to word the description without giving away the answer! I'm open to suggestions though, let me know if you have any!

    • daddepledge Avatar

      Thanks. I have the 6 example tests working, but no more than that. Could you add some more tests to the examples, so I could see the unicode strings (I lack the skill to print these beasts out I think) - or is that the idea of the Kata?

    • zebulan Avatar

      @daddepledge,

      I purposely chose those particular example tests not only to show what was expected but to try and trick people into taking a particular path. I thought it might be a good learning opportunity for people to bump into that "wall" and then realize there must be another value associated with unicode characters.

      I had the same printing issues but I just moved on after having such little interest shown towards this kata (only 16 people have attempted it in 3 months). I will try again tonight to see if I can simplify printing the unicode strings for both versions of Python.

      Thanks for trying out this kata!

    • daddepledge Avatar

      Found the answer, which took me some time. Thanks. I think the 'wall' is a useful learning tool.

    • zebulan Avatar

      @daddepledge,

      Congratulations on finishing it!

  • Micromind Avatar

    This comment has been hidden.

    • zebulan Avatar

      This comment has been hidden.

    • zebulan Avatar

      This comment has been hidden.

    • Micromind Avatar

      This comment has been hidden.

    • Micromind Avatar

      This comment has been hidden.

    • zebulan Avatar

      @Micromind,

      I tried writing a function that would print for whichever version of Python a user chose. Python 3 still has an issue.

      from sys import stdout, version_info
      
      
      def unicode_print(s):
          if version_info.major == 2:
              print(s.encode('utf-8', 'surrogatepass'))
          else:
              stdout.buffer.write(s.encode('utf-8', 'surrogatepass'))
      

      As a test, I added the unicode_print function call above each random test to help a user while debugging.

      • Python 2: works fine, prints out the unicode strings with one above each test
      • Python 3: the unicode characters print out fine (thanks for that!) but they are all bunched together in a single string that prints before the first Basic Tests and nowhere else

      I'm open to any suggestions on how to get them back to printing above each test as expected but I'm still stuck without proper printing at the moment. Anyways, I will keep trying to fix it.

      Thanks for your help!

    • Micromind Avatar

      @zebulan,

      since the print-statement does that automatically, did you try to add a linebreak ('\n') at the end of each string?

    • zebulan Avatar

      @Micromind,

      EDIT:

      I added a newline character at the end of the Python 3 version (using stdout.buffer.write) and it does make a difference by splitting up each line, so thanks for that point!

      The main issue remains though. All of the random test lines are printed above the first test.describe('Basic Tests') in a single "Log" output box. They are not printed above each random test (that's where the "unicode_print" function calls are). In other words, there is almost no easy way to associate them with each particular random test.

    • Micromind Avatar

      OK, next try:-)

      The following part for python3 seems to be working for me as intended:

      sys.stdout.buffer.write(uni_str.encode('utf-8', 'surrogatepass'))
      sys.stdout.buffer.write(b"\n")
      sys.stdout.flush()
      
    • zebulan Avatar

      This comment has been hidden.

    • Micromind Avatar

      For the first issue, can you try and put the flush before sys.stdout.buffer.... It seems that there are two different buffers for stdout at work here, that have to be flushed in the correct order.

      The second issue I don't understand at all. I've seen it during some tests exactly once yesterday and once today, but so far I can't reproduce it. Usually I get the correct unicode symbols.

  • GiacomoSorbi Avatar

    After a quarter of a hour, I have no clue about how to work on the last example case: any hint in that regard? As Unnamed mentioned, the first part is not very clear to me.

  • Unnamed Avatar

    mathematical operations on the character values of a unicode string

    The meaning of "character values" is not obvious at all. Is it intentional?