דילוג לתוכן
  • דף הבית
  • קטגוריות
  • פוסטים אחרונים
  • משתמשים
  • חיפוש
  • חוקי הפורום
כיווץ
תחומים

תחומים - פורום חרדי מקצועי

💡 רוצה לזכור קריאת שמע בזמן? לחץ כאן!
  1. דף הבית
  2. תכנות
  3. אתגרים מגוגל foo.bar

אתגרים מגוגל foo.bar

מתוזמן נעוץ נעול הועבר תכנות
8 פוסטים 3 כותבים 194 צפיות
  • מהישן לחדש
  • מהחדש לישן
  • הכי הרבה הצבעות
התחברו כדי לפרסם תגובה
נושא זה נמחק. רק משתמשים עם הרשאות מתאימות יוכלו לצפות בו.
  • yossizY מנותק
    yossizY מנותק
    yossiz
    כתב ב נערך לאחרונה על ידי yossiz
    #1

    תגובה: קריאת JSON בPYTHON

    @chagold אמר בקריאת JSON בPYTHON:

    אבל תשתף אותנו באתגרים אח"כ...

    הנה הראשון:

    Given two almost identical lists of prisoner IDs x and y where one of the lists contains an additional ID, write a function solution(x, y) that compares the lists and returns the additional ID.

    For example, given the lists x = [13, 5, 6, 2, 5] and y = [5, 2, 5, 13], the function solution(x, y) would return 6 because the list x contains the integer 6 and the list y doesn't. Given the lists x = [14, 27, 1, 4, 2, 50, 3, 1] and y = [2, 4, -4, 3, 1, 1, 14, 27, 50], the function solution(x, y) would return -4 because the list y contains the integer -4 and the list x doesn't.

    התשובה שלי:

    def solution(x, y):
      return set(x).symmetric_difference(set(y)).pop()
    

    📧 יוסי@מייל.קום | 🌎 בלוג | ☕ קפה

    תגובה 1 תגובה אחרונה
    3
    • yossizY מנותק
      yossizY מנותק
      yossiz
      כתב ב נערך לאחרונה על ידי
      #2

      האתגר השני קצת יותר מסובך...

      Lovely Lucky LAMBs

      ==================

      Being a henchman isn't all drudgery. Occasionally, when Commander Lambda is feeling generous, she'll hand out Lucky LAMBs (Lambda's All-purpose Money Bucks). Henchmen can use Lucky LAMBs to buy things like a second pair of socks, a pillow for their bunks, or even a third daily meal!

      However, actually passing out LAMBs isn't easy. Each henchman squad has a strict seniority ranking which must be respected - or else the henchmen will revolt and you'll all get demoted back to minions again!

      There are 4 key rules which you must follow in order to avoid a revolt:

      1. The most junior henchman (with the least seniority) gets exactly 1 LAMB. (There will always be at least 1 henchman on a team.)

      2. A henchman will revolt if the person who ranks immediately above them gets more than double the number of LAMBs they do.

      3. A henchman will revolt if the amount of LAMBs given to their next two subordinates combined is more than the number of LAMBs they get. (Note that the two most junior henchmen won't have two subordinates, so this rule doesn't apply to them. The 2nd most junior henchman would require at least as many LAMBs as the most junior henchman.)

      4. You can always find more henchmen to pay - the Commander has plenty of employees. If there are enough LAMBs left over such that another henchman could be added as the most senior while obeying the other rules, you must always add and pay that henchman.

      Note that you may not be able to hand out all the LAMBs. A single LAMB cannot be subdivided. That is, all henchmen must get a positive integer number of LAMBs.

      Write a function called solution(total_lambs), where total_lambs is the integer number of LAMBs in the handout you are trying to divide. It should return an integer which represents the difference between the minimum and maximum number of henchmen who can share the LAMBs (that is, being as generous as possible to those you pay and as stingy as possible, respectively) while still obeying all of the above rules to avoid a revolt. For instance, if you had 10 LAMBs and were as generous as possible, you could only pay 3 henchmen (1, 2, and 4 LAMBs, in order of ascending seniority), whereas if you were as stingy as possible, you could pay 4 henchmen (1, 1, 2, and 3 LAMBs). Therefore, solution(10) should return 4-3 = 1.

      To keep things interesting, Commander Lambda varies the sizes of the Lucky LAMB payouts. You can expect total_lambs to always be a positive integer less than 1 billion (10 ^ 9).

      📧 יוסי@מייל.קום | 🌎 בלוג | ☕ קפה

      yossizY תגובה 1 תגובה אחרונה
      1
      • yossizY מנותק
        yossizY מנותק
        yossiz
        השיב לyossiz ב נערך לאחרונה על ידי
        #3

        הפתרון שלי לאתגר השני:

        def solution(total_lambs):
            def fib(n):
                a, b = 1, 1
                for _ in range(n):
                    yield a
                    a, b = b, a + b
        
            def powers_of_2(n):
                a = 1
                for _ in range(n):
                    yield a
                    a *= 2
        
            def stingy(n):
                remaining, iterations = n, 0
                for i in fib(10 ** 9):
                    remaining -= i
                    if remaining < 0:
                        break
                    iterations += 1
        
                return iterations
        
            def generous(n):
                remaining, iterations = n, 0
                for i in powers_of_2(10 ** 9):
                    remaining -= i
                    if remaining < 0:
                        break
                    iterations += 1
        
                return iterations
        
            return stingy(total_lambs) - generous(total_lambs)
        

        📧 יוסי@מייל.קום | 🌎 בלוג | ☕ קפה

        תגובה 1 תגובה אחרונה
        1
        • yossizY מנותק
          yossizY מנותק
          yossiz
          כתב ב נערך לאחרונה על ידי
          #4

          השלישי:

          Please Pass the Coded Messages

          ==============================

          You need to pass a message to the bunny prisoners, but to avoid detection, the code you agreed to use is... obscure, to say the least. The bunnies are given food on standard-issue prison plates that are stamped with the numbers 0-9 for easier sorting, and you need to combine sets of plates to create the numbers in the code. The signal that a number is part of the code is that it is divisible by 3. You can do smaller numbers like 15 and 45 easily, but bigger numbers like 144 and 414 are a little trickier. Write a program to help yourself quickly create large numbers for use in the code, given a limited number of plates to work with.

          You have L, a list containing some digits (0 to 9). Write a function solution(L) which finds the largest number that can be made from some or all of these digits and is divisible by 3. If it is not possible to make such a number, return 0 as the solution. L will contain anywhere from 1 to 9 digits. The same digit may appear multiple times in the list, but each element in the list may only be used once.

          📧 יוסי@מייל.קום | 🌎 בלוג | ☕ קפה

          תגובה 1 תגובה אחרונה
          0
          • OdedDvirO מנותק
            OdedDvirO מנותק
            OdedDvir
            כתב ב נערך לאחרונה על ידי
            #5

            אפשר מקור בבקשה?

            yossizY תגובה 1 תגובה אחרונה
            0
            • yossizY מנותק
              yossizY מנותק
              yossiz
              השיב לOdedDvir ב נערך לאחרונה על ידי
              #6

              @OdedDvir
              https://foobar.withgoogle.com
              אבל זה רק בהזמנה.
              אני חיפשתי משהו לתומי בגוגל (קשור לפייתון) וקיבלתי הזמנה. תמשיך לחפש בגוגל אולי יום אחד תקבל הזמנה...

              📧 יוסי@מייל.קום | 🌎 בלוג | ☕ קפה

              תגובה 1 תגובה אחרונה
              4
              • chagoldC מנותק
                chagoldC מנותק
                chagold
                כתב ב נערך לאחרונה על ידי
                #7

                @yossiz אני רק חושש בשבילך אם המנוע של גוגל יגלה להם שהעתקת לכאן את זה (מילא עד היום הם היו צריכים לשלם 8 ש"ח אבל עכשיו הפורום נפתח להם..).

                yossizY תגובה 1 תגובה אחרונה
                0
                • yossizY מנותק
                  yossizY מנותק
                  yossiz
                  השיב לchagold ב נערך לאחרונה על ידי
                  #8

                  @chagold חחח... כמה תשובות:

                  • בכל מקרה אני לא מתכנן לעבוד עבור גוגל...
                  • פורום התכנות תמיד היה פתוח לבוט של גוגל. אפשר להווכח בכך כאשר אתה מקבל תוצאות מפורום התכנות בחיפושי גוגל
                  • גוגל היא חברה גדולה מאוד, אין סיכוי שיש כזה שיתוף פעולה הדוקה בין הסניפים

                  📧 יוסי@מייל.קום | 🌎 בלוג | ☕ קפה

                  תגובה 1 תגובה אחרונה
                  6

                  בא תתחבר לדף היומי!
                  • התחברות

                  • אין לך חשבון עדיין? הרשמה

                  • התחברו או הירשמו כדי לחפש.
                  • פוסט ראשון
                    פוסט אחרון
                  0
                  • דף הבית
                  • קטגוריות
                  • פוסטים אחרונים
                  • משתמשים
                  • חיפוש
                  • חוקי הפורום