දවසේ පැනය. තමන් කැමති ඕනැම දෙයකින් කල හැක

HAneo

Well-known member
  • Jan 30, 2007
    12,969
    29,168
    113
    Homagama

    කැමති ඕනෙම ප්රෝග්‍රමින්ග් ලන්වේජ් එකක් තෝරා ගන්න. අලුත් ලන්වේජ් වලින් කරලා දාපල්ලා අනින් උනුත් ඉන්ස්පයර් ද මොකක්ද එක වෙන්න. තේරෙන්නේ නැති උන් අහපල්ලා ඕක සිංහලෙන් කියල දෙයි කව්රු හරි​


    1.png
     

    CorD SaC

    Well-known member
  • Feb 4, 2015
    15,789
    28,158
    113
    Bump

    Updated:


    C#:
    public static class Program {
      static void Main(string[] args) {
        int B = 1, A = 1, L = 2, O = 2, N = 1, count = 0;
        //var s = "BAOOLLNNOLOLGBAX";
        var s = "BAONXXOLL";
    
        while (s.Count(x => x == 'B') >= B && s.Count(x => x == 'A') >= A && s.Count(x => x == 'L') >= L && s.Count(x => x == 'O') >= O && s.Count(x => x == 'N') >= N) {
          ++count;
          s = s.ReplaceChar('B', B);
          s = s.ReplaceChar('A', A);
          s = s.ReplaceChar('L', L);
          s = s.ReplaceChar('O', O);
          s = s.ReplaceChar('N', N);
        }
    
        Console.WriteLine("Number of moves: " + count.ToString());
      }
    
      public static string ReplaceChar(this string s, char c, int i) {
        var regex = new Regex(Regex.Escape(c.ToString()));
        return regex.Replace(s, string.Empty, i);
      }
    }


    මේ රීප්ලේස් සීන් එකට රෙජෙක්ස් එකක් ලියාගත්තනම් මීට වඩා මේ වැඩේ කොලිටි

    දැන් මෙතන තියෙන්නෙ, BALLON කියන වචනෙනෙ, ඉස්සරහට වෙන වචනයක් ආවොත්, ඒකටත් සෙට් වෙන්න ලියනවනම්, අදාල වචනෙ alphabetical character count එක <key,value> pair අරගෙන ඒක through ,loop කරලා ගත්තනම් හරි. :rolleyes:



    C#:
    public static void generateAlphabiticalDict(string input)
    {
        Dictionary<Char, int> alphabets = new Dictionary<Char, int>();
    
        for (int i = 0; i < input.Length; i++)
        {
            char character = input[i];
            if (Char.IsLetter(character))
            {
                if (alphabets.ContainsKey(character))
                    alphabets[character] = alphabets[character] + 1;
                else
                    alphabets.Add(character, 1);
            }
        }
    }
     
    Last edited:

    u_make_me_sick_

    Well-known member
  • Oct 1, 2011
    11,521
    7,318
    113
    Java 8+, without any 3rd party libraries.
    Meeta wada optimized widi godak ethi. eka paratama oluwata aawe meka.


    Java:
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.LinkedHashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.stream.Collectors;
    
    public class EKTest {
    
      public int getMaxMoves(String string) {
        Map<String, Long> occurrences = Arrays.stream(string.split("")).collect(
            Collectors.groupingBy(s -> s, LinkedHashMap::new, Collectors.counting()));
    
        return Collections.min(List.of(
            (occurrences.get("B") != null ? occurrences.get("B").intValue() : 0),
            (occurrences.get("A") != null ? occurrences.get("A").intValue() : 0),
            (occurrences.get("L") != null ? (occurrences.get("L").intValue())/2: 0),
            (occurrences.get("O") != null ? (occurrences.get("O").intValue())/2: 0),
            (occurrences.get("N") != null ? (occurrences.get("N").intValue()) : 0)
            ));
      }
    
      public static void main(String [] args) {
        EKTest ek = new EKTest();
        System.out.println("Max Moves: " + ek.getMaxMoves("QAWABAWNL"));
        System.out.println("Max Moves: " + ek.getMaxMoves("BAONXXOLL"));
        System.out.println("Max Moves: " + ek.getMaxMoves("BAOOLLNNOLOLGBAXBBOOALLNN"));
      }
    }
     
    Last edited:

    HAneo

    Well-known member
  • Jan 30, 2007
    12,969
    29,168
    113
    Homagama
    රා කට්ටක් ගහලා පිසා කෑල්ලක් කකා අතල් එකේ හිටියේ.
    කෑවා ආතල් මගුලක් දාලා

    View attachment 180252
    Code ekath dapan machan study karana unta help ekak weyi
    And pls explain how you approached this. it's a learning curve

    Java 8+, without any 3rd party libraries.
    Meeta wada optimized widi godak ethi. eka paratama oluwata aawe meka.


    Java:
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.LinkedHashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.stream.Collectors;
    
    public class EKTest {
    
      public int getMaxMoves(String string) {
        Map<String, Long> occurrences = Arrays.stream(string.split("")).collect(
            Collectors.groupingBy(s -> s, LinkedHashMap::new, Collectors.counting()));
    
        return Collections.min(List.of(
            (occurrences.get("B") != null ? occurrences.get("B").intValue() : 0),
            (occurrences.get("A") != null ? occurrences.get("A").intValue() : 0),
            (occurrences.get("L") != null ? (occurrences.get("L").intValue())/2: 0),
            (occurrences.get("O") != null ? (occurrences.get("O").intValue())/2: 0),
            (occurrences.get("N") != null ? (occurrences.get("N").intValue()) : 0)
            ));
      }
    
      public static void main(String [] args) {
        EKTest ek = new EKTest();
        System.out.println("Max Moves: " + ek.getMaxMoves("QAWABAWNL"));
        System.out.println("Max Moves: " + ek.getMaxMoves("BAONXXOLL"));
        System.out.println("Max Moves: " + ek.getMaxMoves("BAOOLLNNOLOLGBAXBBOOALLNN"));
      }
    }
    MAchan explain how you approached this as it will help to others
    ------ Post added on Jul 30, 2022 at 9:07 PM
     

    helplesser

    Well-known member
  • Nov 20, 2017
    18,235
    27,943
    113
    36
    Mirihana
    alis.alberta.ca
    Code ekath dapan machan study karana unta help ekak weyi
    And pls explain how you approached this. it's a learning curve


    MAchan explain how you approached this as it will help to others
    ------ Post added on Jul 30, 2022 at 9:07 PM
    They use words like balloon to trick you. Just understanding the real requirement will leads you to the right direction. This is what happens in the real world too. Business centric people use buzz words while explaining the requirements which is confusing. But as develpors we should able to filter the real thing from what they telling.
     

    BinDT

    Well-known member
  • Apr 21, 2022
    1,007
    1,585
    113
    Andromeda Galaxy
    Python:
    letters=[]
    x=input("word: ")
    letters=list(x)
    word=list("BALLOON")
    round=0
    number=0
    set_no=1
    n=1
    
        
    while len(letters)!=n:
        while n<len(letters):
            if word[round] ==letters[n-1]:
                number=number+1
                
                
                if number==7:
                    set_no=set_no+1
                    round=0
                    n=n+1
                    
                    
                else:
                    n=n+1
                    round=round+1
            else:
                n=n+1
      
    
    
    
    print(set_no)

    (samaharawita waradi athi.baninna epa hode. api thaama aadunikai programming walata:))
     

    HAneo

    Well-known member
  • Jan 30, 2007
    12,969
    29,168
    113
    Homagama
    Python:
    letters=[]
    x=input("word: ")
    letters=list(x)
    word=list("BALLOON")
    round=0
    number=0
    set_no=1
    n=1
    
       
    while len(letters)!=n:
        while n<len(letters):
            if word[round] ==letters[n-1]:
                number=number+1
               
               
                if number==7:
                    set_no=set_no+1
                    round=0
                    n=n+1
                   
                   
                else:
                    n=n+1
                    round=round+1
            else:
                n=n+1
     
    
    
    
    print(set_no)

    (samaharawita waradi athi.baninna epa hode. api thaama aadunikai programming walata:))
    Hurray we have a python one.
    a meka competition ekak neme machan.
    just to polish our brain ne. uba meka python walin kala eka loku deyak. podi wistharekuth denna problem ekata enter un widiha
    :love:
     

    siri_ayya

    Well-known member
  • Feb 1, 2022
    16,963
    1
    29,874
    113
    They use words like balloon to trick you. Just understanding the real requirement will leads you to the right direction. This is what happens in the real world too. Business centric people use buzz words while explaining the requirements which is confusing. But as develpors we should able to filter the real thing from what they telling.
    මේකද approach ඒක :rolleyes:
     
    • Like
    Reactions: HAneo