떢븻각걎냇갅갸꺚뵟숣욄뵴뵞뤼갈갌뤔떌옊메늄숭캸긶꺛옖갍뇐쩢곴듇걯궄옕왹눞솴걃끗긬땉궿가쌀낐걄숤뺴늘걘꽸숢걂갋갃쫐꼔솾쩡쇔솿끛뤜간븺쩬웨딴옠뤛갂뵪덠놤빐옋귒늂갰갖놥궾갆옌뼘묰거갎긷낤겼


  • 24
    def judgePoint24(self, nums):
        bad = '떢븻각걎냇갅갸꺚뵟숣욄뵴뵞뤼갈갌뤔떌옊메늄숭캸긶꺛옖갍뇐쩢곴듇걯궄옕왹눞솴걃끗긬땉궿가쌀낐걄숤뺴늘걘꽸숢걂갋갃쫐꼔솾쩡쇔솿끛뤜간븺쩬웨딴옠뤛갂뵪덠놤빐옋귒늂갰갖놥궾갆옌뼘묰거갎긷낤겼'
        return chr(int(''.join(map(str, sorted(nums)))) + 42921) not in bad
    

    There are really only 495 possible inputs, of which 404 are solvable and 91 aren't. The above is the shortest encoding of those 91 that I could think of. One character for each case. The +42921 is for getting all characters from the same unicode range (from the "Hangul Syllables" range) so that it looks good. For extra style points I shuffled them, otherwise they'd look somewhat sorted.

    Edit: Then again, after a few iterations my "normal" solution ended up being shorter than this. But at least this is still much faster and imho more fun :-)


  • 2
    A

    I am just speechless after seeing this post, how did you even end up with such a solution. You have got to be seeing something extra in the questions that I am not able to see, please share your thought process.


  • 6

    @ashish.katiyar I helped preparing the problem for the contest. For that, I tested solutions on all inputs. That's where I realized there aren't that many. And the solutions took about two minutes for all inputs, I think that's where I thought about pre-computing. Partly because I wanted a fast solution to easily compare other solutions against.

    And then I just had fun making it small. I like doing things differently and coming up with stuff people don't usually think of. In the end I was a bit inspired by people occasionally posting here in Chinese or so. At least that's why I used the string as my title, just a little joke.


  • 0

    @StefanPochmann Just FYI, your solution is not in Chinese. It`s Korean. lol


  • 0

    @Ivan_Ouyang Yeah I know. I had tried Chinese first, but the characters didn't look as homogeneous. So I tried Korean instead and that looked much better. I just hope it's complete gibberish and not something offensive. I don't know any Korean and Google Translate didn't help at all.


  • 0

    @StefanPochmann Sorry, I cannot tell. Maybe ask a Korean friend to help and check if it is offensive or not.


  • 0
    S
    This post is deleted!

  • 8
    S

    Chinese version:

    class Solution:
        def judgePoint24(self, nums):
            """
            :type nums: List[int]
            :rtype: bool
            """
            bad = '对撒剘劥圞剜劏哱掶桺泛揋掵従剟剣彫寣污悫壛梄甏咍哲汭剤堧点卋嬞勆叛汬泐塵栋劚嚮咃宠吖剗楗囧力桻攋壯劯嗏桹劙剢剚焧啫栕炸栫栖嚲彳剛撑烃洿宋汷彲剙揁妷埻撧汢吩壙劇剭埼吕剝汣敯憇勇剥咎囻匓'
            return chr(int(''.join(map(str, sorted(nums)))) + 19968) not in bad
    

  • 20

    有人面试能写出来这个我名字倒过来写


  • 0

    Such useless post.


  • 0
    C

    @eat_watermelon 没看明白其实。


  • 0
    S

    @cicean Just an interesting hash table solution using Korean character encoding for short codes :)


  • 4

    91 is evenly divisible by 13, so this hardcoded C++ solution looks decent...

    class Solution{
    public:
        bool judgePoint24(vector<int>& nums){
            sort(nums.begin(),nums.end());
            return !NOT_24.count(nums[0]*10*10*10+nums[1]*10*10+nums[2]*10+nums[3]);
        }
        
    private:
        const set<int> NOT_24 {
            1111, 1112, 1113, 1114, 1115, 1116, 1117, 1119, 1122, 1123, 1124, 1125, 1133,
            1159, 1167, 1177, 1178, 1179, 1189, 1199, 1222, 1223, 1299, 1355, 1499, 1557,
            1558, 1577, 1667, 1677, 1678, 1777, 1778, 1899, 1999, 2222, 2226, 2279, 2299,
            2334, 2555, 2556, 2599, 2677, 2777, 2779, 2799, 2999, 3358, 3467, 3488, 3555,
            3577, 4459, 4466, 4467, 4499, 4779, 4999, 5557, 5558, 5569, 5579, 5777, 5778,
            5799, 5899, 5999, 6667, 6677, 6678, 6699, 6777, 6778, 6779, 6788, 6999, 7777,
            7778, 7779, 7788, 7789, 7799, 7888, 7899, 7999, 8888, 8889, 8899, 8999, 9999,
        };
    };
    

  • 0
    L

    What can I say.


  • 2
    P

    @StefanPochmann Hi, I am a native Korean, and I can confirm that the sentence doesn't make sense at all, so not offensive. Pretty funny & creative way of solving this problem.


  • 0

    @pungrue26 Great, thanks :-)


  • 0
    Z

    no words for your program......


  • 0
    P
    This post is deleted!

  • 1
    M

    Thought it was spam at first LOL
    Thank you for this really interesting and humorous solution


  • 0
    J

    I am speechless after seeing this solution.....
    :-O


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.