Ek Code Chef challenge- Welcome Developers, Hackers & Noobs

owlX

Well-known member
  • Jul 13, 2014
    1,321
    400
    83
    /usr/bin
    ඔන්න එහෙනම් පලවෙනි Challenge එක ඉවරායි. නිවැරදිව කරපු අය තමයි මේ :
    1.kolavari (Python)
    2.MihiCherub (Java)
    3.markhaloce(C++)

    පලවෙනි එකේ Constrain කලින් දැනුවත් නොකල නිසා ලාවට අල ‍වුවත් දෙවන එකේ සිට නිවැරදිව කරගෙන යාමට සහය දක්වන ලෙස ඉල්ලා සිටිමි. මෙයට තරග සංවීධායක මන්ඩලය :lol:
    කඹ ඇදීමට වඩා Rep දෙවනු එකේ සිට ලැබෙනු ඇත. තවද අලුත් Thread එක්කින් ii ලෙස ආරම්භ වෙනු ඇත. එවිට වාඩා පැහැදිලි වනු ඇත.
    ජය වේවා


    ඔබ සතු ගැටළු PM කරන්න ඊලග තරගයට.
    සැ.යු ගැටළුව අදාල පුද්ගලයාට තරගය ඉදිරිපත් විය නොහැක :rofl:
     
    Last edited:

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,852
    1
    9,598
    113
    Gampaha
    :)
    ඔන්න එහෙනම් Rep දෙන්න බලන්න කට්ටිය.
    Ayeshlive ගේ එකත් පට්ට ට්‍රයි කරපං මචං :cool::cool:
    Good Luck!
    PS : මං array එක import කරන්නැතුව compile කරලා තිබ්බේ උඹ ඒක දාල තිබ්බේ නෑනේ :rofl:
    ඊලග එකේ සිට නිවරදි නීති පද්දතියක් ඇතුල කරනු ලැබේ.. (භාවිතා කල හැකි libraries හා inbuilt function පිලිබදව :))
    රෙප් නම් එපා බන්.. :dull: කෝඩ් එක එඩිට් කලේ නෑ, උබ හරියට කම්පයිල් කරල නෑ. මම ඔක්කොම දාල තිබ්බෙ.. :rofl::rofl:

    ඔන්න user inputs දාලම තව එකක් ලිව්ව. මේක නම් ide එකෙන් කලේ.. වෙලා නෑ නෝට් පෑඩ් වල කරන්න.


    PHP:
    import java.util.Arrays;
    import java.util.InputMismatchException;
    import java.util.Scanner;
    
    /**
     *
     * @author Tharindu
     */
    class Numbers {
    
        public static void main(String[] args) {
    
            Scanner Sc = new Scanner(System.in);
            int lines = 0;
            try {
                System.out.print("How many numbers in the list: ");
                lines = Sc.nextInt();
    
                if (lines > 100000) {
                    System.out.print("Please Enter value less than 100000");
                    return;
                }
    
            } catch (InputMismatchException ex) {
                System.out.println("Please Enter valid number: " + ex);
                return;
            }
    
            int[] arr = new int[lines];
    
            for (int i = 0; i < lines; i++) {
                try {
    
                    System.out.print("Please Enter your list number: ");
                    int num = Sc.nextInt();
                    if (num <= 0 || num >= 100000) {
                        System.out.println("List number should be between 0 and 100000");
                        i--;
                    } else {
                        arr[i] = num;
                    }
    
                } catch (InputMismatchException ex) {
                    System.out.println("Please Enter valid list number: " + ex);
                    return;
                }
            }
    
            Arrays.sort(arr);
            System.out.println("Sorted list: ");
            for (int number : arr) {
                System.out.println(number);
    
            }
        }
    }
     

    Ayeshlive

    Well-known member
  • Jul 1, 2011
    10,570
    943
    113
    *̶͑̾̾​̅ͫ͏̙̤g͛͆̾ͫ̑͆&
    Make a 1000 Line of 'A' without using for,while,do..while..goto..
    or the new line character(\n) and with the least amount of codes.

    USE ONLY JAVA :yes:
    example out put..

    A
    A
    A
    A
    A
    A
    .
    .
    .

    U cannot use new line character \n :no:

    Fine.
    Using System.getProperty("line.separator").

    Ungolfed:
    PHP:
    class X
    {
        public static void main (String[] args)
        {
            System.out.println(new String(new char[1000]).replace("\0", "A" + System.getProperty("line.separator")));  
        }
    }

    Golfed (150 bytes):

    PHP:
    class X{public static void main (String[] a){System.out.println(new String(new char[1000]).replace("\0", "A"+System.getProperty("line.separator")));}}
     
    Last edited:

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,852
    1
    9,598
    113
    Gampaha
    මේ තියෙන්නෙ sort වෙන්න ගහපු project එකක්..
    යාලුවෙක් වෙනුවෙන් හැදුවෙ.

    SLIIT 2nd Year Algorithm Simulator Project - Java

    Insertion / Selection


    File Size: 2.00MB
    mediafire

    ProjectScreen3.jpg


    cards2_zps4nnbtjv8.gif


    ඕන අය බාගන්න. codes ටික දෙන්නෙ උවමනාම අයට විතරයි. :baffled:
     

    Ayeshlive

    Well-known member
  • Jul 1, 2011
    10,570
    943
    113
    *̶͑̾̾​̅ͫ͏̙̤g͛͆̾ͫ̑͆&
    PHP:
    ## Code by owlX for Ek 3C
    ## Combatible with Python 3.x
    import math
    
    def prime_factorization(x):
      if x == 0 | x == 1:
        return None
      result = []
      for i in range(2,int(math.floor(math.sqrt(x)+1))):
        while x % i == 0:
          x /= i
          result.append(i)
      if x != 1:
        result.append(x)
      return result
    
    while True:
        n = int(input("Enter Value :"))
        if n == -1:  ##if you want to stop, enter -1
            break
        x = prime_factorization(n)
        if len(x)==2:
            print (x)
        else:
            print (0)
    හරිද මචං?​
    :cool::nerd::nerd:

    Ela machan output ekanam hari. Anith aya dala thibune na ne algorithms compare karanna. mama rep dunna.
     

    KingCM

    Well-known member
  • Jul 23, 2013
    6,920
    948
    113
    www.biogen.lk
    මේ තියෙන්නෙ sort වෙන්න ගහපු project එකක්..
    යාලුවෙක් වෙනුවෙන් හැදුවෙ.



    ඕන අය බාගන්න. codes ටික දෙන්නෙ උවමනාම අයට විතරයි. :baffled:


    code eka PM karapanko ban.:):):):nerd:
     

    agnipra

    Active member
  • May 25, 2008
    720
    59
    28
    Colombo
    ane manda bn mama php vat py.. vat dan na c# valin kora
    balapallako

    static void Main(string[] args)
    {
    try
    {
    List<int> lst = new List<int>();
    int chk = -1;
    bool isProcess = false;
    y:
    if (!isProcess)
    {
    Console.Clear();
    Console.WriteLine("Please enter the numbers(Random numbers with <= 100,000). Type 'END' to process!");
    var line = Console.ReadLine();


    if (string.IsNullOrEmpty(line.ToString()))
    {
    Console.WriteLine("Please enter numaric value");
    goto y;
    }
    else
    {
    if (line.ToString().Trim().ToUpper().Equals("END")) isProcess = true;
    else
    {
    int.TryParse(line.ToString(), out chk);
    if (chk == 0)
    {
    Console.WriteLine("Please enter numaric value");
    goto y;
    }
    }
    }
    if (!isProcess) lst.Add(Convert.ToInt32(line));
    goto y;
    }
    else
    {
    lst.Sort();
    foreach (int n in lst)
    Console.WriteLine(n.ToString());
    Console.ReadKey();
    }


    }
    catch (Exception e)
    {
    Console.WriteLine(e.Message);
    Console.ReadKey();
    }

    }
     

    Lihrox

    Well-known member
  • Jul 11, 2009
    989
    56
    48
    මේ තියෙන්නේ මම selection sort & Insertion sort simulate කරන්න හදපු software එකක්.

    Output + psudo code + dry run

    Sorting ගැන ඉගෙනගන්න කැමති අයට වැදගත් වෙයි

    Code එක ඕනේ නම් කියන්න simulator එකේ code එකත් එවන්නම්


    Download
     
    Last edited:

    markhaloce

    Member
    Mar 7, 2013
    10,298
    677
    0
    17
    The Real North
    අයේශ්ලයිව්ගෙ වැඩේ කරගෙන යද්දි c++ වල වෙක්ටර්ස් ව්අල අවුලක් ආව සිඞ්හලයෝ :(
    හිරවෙලා ඉන්නෙ :(
    වෙලාව දියං කල්ල දෙන්නං.. :(
    කාලෙකිං ඇල්ලුවෙ.
     

    Ayeshlive

    Well-known member
  • Jul 1, 2011
    10,570
    943
    113
    *̶͑̾̾​̅ͫ͏̙̤g͛͆̾ͫ̑͆&
    අයේශ්ලයිව්ගෙ වැඩේ කරගෙන යද්දි c++ වල වෙක්ටර්ස් ව්අල අවුලක් ආව සිඞ්හලයෝ :(
    හිරවෙලා ඉන්නෙ :(
    වෙලාව දියං කල්ල දෙන්නං.. :(
    කාලෙකිං ඇල්ලුවෙ.
    Ela. Looking forward to.
     
    • Like
    Reactions: owlX

    KingCM

    Well-known member
  • Jul 23, 2013
    6,920
    948
    113
    www.biogen.lk
    මේ තියෙන්නේ මම selection sort & Insertion sort simulate කරන්න හදපු software එකක්.

    Output + psudo code + dry run

    Sorting ගැන ඉගෙනගන්න කැමති අයට වැදගත් වෙයි

    Code එක ඕනේ නම් කියන්න simulator එකේ code එකත් එවන්නම්


    Download

    code eka pm karapanko (for study purpose)​
     

    owlX

    Well-known member
  • Jul 13, 2014
    1,321
    400
    83
    /usr/bin
    Ela machan output ekanam hari. Anith aya dala thibune na ne algorithms compare karanna. mama rep dunna.
    :sorry: මං ඕක දාන්නද ඊ්ලග එකට මගෙ එක අයින් කරමු.. පට්ට problem එකක් මචං ඒක.. සෑහෙන්න බිව්වා :P

    ane manda bn mama php vat py.. vat dan na c# valin kora
    balapallako

    static void Main(string[] args)
    {
    try
    {
    List<int> lst = new List<int>();
    int chk = -1;
    bool isProcess = false;
    y:
    if (!isProcess)
    {
    Console.Clear();
    Console.WriteLine("Please enter the numbers(Random numbers with <= 100,000). Type 'END' to process!");
    var line = Console.ReadLine();


    if (string.IsNullOrEmpty(line.ToString()))
    {
    Console.WriteLine("Please enter numaric value");
    goto y;
    }
    else
    {
    if (line.ToString().Trim().ToUpper().Equals("END")) isProcess = true;
    else
    {
    int.TryParse(line.ToString(), out chk);
    if (chk == 0)
    {
    Console.WriteLine("Please enter numaric value");
    goto y;
    }
    }
    }
    if (!isProcess) lst.Add(Convert.ToInt32(line));
    goto y;
    }
    else
    {
    lst.Sort();
    foreach (int n in lst)
    Console.WriteLine(n.ToString());
    Console.ReadKey();
    }


    }
    catch (Exception e)
    {
    Console.WriteLine(e.Message);
    Console.ReadKey();
    }

    }

    මචං https://ideone.com/py2HaM :nerd:

    මේ තියෙන්නේ මම selection sort & Insertion sort simulate කරන්න හදපු software එකක්.

    Output + psudo code + dry run

    Sorting ගැන ඉගෙනගන්න කැමති අයට වැදගත් වෙයි

    Code එක ඕනේ නම් කියන්න simulator එකේ code එකත් එවන්නම්


    Download
    තැන්කිව් මචං ඊලග එකේ problem එක solve කරන්නත් එන්න
     

    owlX

    Well-known member
  • Jul 13, 2014
    1,321
    400
    83
    /usr/bin
    Ela. One nam performance measure karanna puluwan code eka 10000 times wage repeat karala.

    ඔව් මචං කට්ටිය ගොඩක් submit කරාම ඊ්ලග එකේ ඉදං කරමු. කට්ටිය නෑනේ, SE Salary නම් අහනවා හැමදාම කව්රු හරි :D

    _________________________________________________________________

    එක්වන්න
    Elakiri <3C/>
    සමග.
    ඔබේ හැකියාවන් දියුණු කරගන්න.
    සාදර අනුග්‍රහය scurvy :cool:
     

    markhaloce

    Member
    Mar 7, 2013
    10,298
    677
    0
    17
    The Real North
    Ela. Looking forward to.

    PHP:
    #include <iostream>
    #include <vector>
    #include <list>
    using namespace std;
    
    bool isPrime(const int& num)
    {
    	if (num == 0)
    		return false;
    	if (num == 1)
    		return true;
    
    	for (int i{2}; i < num; i++)
    	{
    		if (num % i == 0)
    			return false;
    	}
    
    	return true;
    }
    
    
    void getPrimes(const int& num, vector<int> *vect)
    {
    	for (int i{}; i <= num/2; i++)
    	{
    		if (isPrime(i))
    		{
    			vect->push_back(i);
    		}
    	}
    }
    
    bool canBeMultByTwoPrimes(const int& input, int* num1, int *num2)
    {
    	vector<int> primes;
    	getPrimes(input, &primes);
    	int len = primes.size();
    
    	for (int i{}; i < len; i++)
    	{
    		for (int j{}; j < len; j++)
    		{
    			if (primes[i] * primes[j] == input)
    			{
    				*num1 = primes[i];
    				*num2 = primes[j];
    
    				return true;
    			}
    		}
    	}
    
    	return false;
    }
    
    void main()
    {
    	int a, b;
    	if (canBeMultByTwoPrimes(22, &a, &b))
    		printf("%i\t%i", a, b);
    }

    const int& කෑලි එහෙම දැම්මෙ උඹට හොඳටම පර්ෆෝමන්ස් ඕනෙ කිව්ව නිසා :lol: :lol:
    පොයින්ටර්ස් දැම්මෙත් ඒකයි :D :D