Ek Code Chef challenge- Welcome Developers, Hackers & Noobs

Sx3

Well-known member
  • Apr 4, 2014
    3,394
    2,382
    113
    Ungolfed:
    Code:
    /* package whatever; // don't place package name! */
     
    import java.util.*;
    import java.lang.*;
    import java.io.*;
     
    /* Name of the class has to be "Main" only if the class is public. */
    class Ideone
    {
        public static void main (String[] args) throws java.lang.Exception
        {
            System.out.println(new String(new char[1000]).replace("\0", "A\n"));  
        }
    }
    Golfed (205 bytes):
    Code:
    import java.util.*;import java.lang.*;import java.io.*;class Ideone{public static void main (String[] args) throws java.lang.Exception{System.out.println(new String(new char[1000]).replace("\0", "A\n"));}}
    Online:
    http://ideone.com/fork/iRJhpL

    U cannot use new line character \n :no:
     

    owlX

    Well-known member
  • Jul 13, 2014
    1,321
    400
    83
    /usr/bin
    Code:
    import java.util.Arrays;
    import java.util.Scanner;
    
    
    public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            int num = scan.nextInt();
            int[] arr = new int[num];
            for(int i =0;i<num;i++){
                arr[i] = scan.nextInt();
            }
            System.out.println("");
            Arrays.sort(arr);
            for(int j:arr){
                System.out.println(j);
            }
        }

    :D
    වැඩ නෑ මචං :no:

    PHP:
    import java.util.Arrays;
    
    class numbers{
    
        private final static int lines = 8;
        private final static int numbers[] = new int[]{5,3,6,7,5,3,1,5};
    
    
        public static void main(String[] args) {
    
                int[] arr = new int[lines];
    
                for(int i =0;i<lines;i++){
                    arr[i] = numbers[i];
                }
    
                Arrays.sort(arr);
    
                for(int number:arr){
                    System.out.println(number);
                }
            }
    }

    :P:cool:
    මචං User එයාලගේ values දෙන්න ඕන​

    pahala link ekata gihilla code eka dala ... thaman kemathi lenguage ekak select karagena ... inputs dala test karala balala ... eken thamange code ekata generate wena link eka share karanam hari :D

    https://ideone.com/

    තැන්කිව් මචං​

    weddo mekatath help ekak denna puluwanda balapalla

    xml or html (help)
    එල මචං​

    patta wadak :D
    තැන්කිව් මචං​

    Ai ban code challenges walata language ekak one na. Pseudo code hari kamak na concept Ekai enna one.
    Anith eka language eke thiyena features use karana kisi athal ekak na ne.
    මචං‍ ගොඩක් අය logic එක දන්නවා ඒත් code කරන්න ගියාම බෑ. අනිවා company එකක හරි software competition එක්ක මෙහෙම බලන්නැතුව, හරි එක්කෙනෙක් තෝරන්න අමාරුයි. මොකද හරි logic ගොඩක් තියෙන්න පුළුවංන්නේ.. තැන්කිව් මචං ‍​

    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
    .
    .
    .
    තැන්කිව් මචං. මාත් ට්‍රයි කරන්නම්​

    I am little bit busy machan. What you're asking is bubble sort method. I don't have hands on experience with this so i don't like to be the wise guy by copy pasting a code from internet.

    Great work by posting this thread machan. This will help lots of people to face better in their technical interviews. Specially Virtusa, WSO2.

    Competitors, please try to avoid JDK or Language facilities to solve problems. Like arrays.sort(); Big companies expect you to learn those functions but they need to know that you know the theory behind it.


    thanks_for_sharing.png

    Finally you got it මචං. අනිවා software competition එක්කට ගියොත් මෙහම කරන්න වෙනවා. සමහර ඒවගේ submit කරන්න කලින් code එක run කරන්න දෙන්නෙත් නෑ. Notepad විතරයි. :nerd:

    Ungolfed:
    Code:
    /* package whatever; // don't place package name! */
     
    import java.util.*;
    import java.lang.*;
    import java.io.*;
     
    /* Name of the class has to be "Main" only if the class is public. */
    class Ideone
    {
        public static void main (String[] args) throws java.lang.Exception
        {
            System.out.println(new String(new char[1000]).replace("\0", "A\n"));  
        }
    }
    Golfed (205 bytes):
    Code:
    import java.util.*;import java.lang.*;import java.io.*;class Ideone{public static void main (String[] args) throws java.lang.Exception{System.out.println(new String(new char[1000]).replace("\0", "A\n"));}}
    Online:
    http://ideone.com/fork/iRJhpL
    එල මචං මං දාපු එකත් try කරහන්​


    Code:
    public class Sort {
    
    	public static void main(String[] args) {
    
    		int[] arr = {5, 3, 6, 7, 5, 1, 3, 5 };
    
    		sortArray(arr);
    		printArray(arr);
    
    	}
    
    	private static void sortArray(int[] arr) {
    		
    		for (int i = 0; i < arr.length; i++) {
    				
    			int low = i;
    			
    			for (int k = i + 1; k < arr.length; k++) {
    				
    					if (arr[k] < arr[low])
    
    					low = k;
    					
    				int temp = arr[i];
    				arr[i] = arr[low];
    				arr[low] = temp;
    	
    			}
    		}
    
    	}
    
    	private static void printArray(int[] arr) {
    
    		for (int i = 0; i < arr.length; i++)
    
    			System.out.println(arr[i]);
    
    	}
    
    }

    :)
    මචං user inputs දෙන්න ඕන​
    here is my challenge.
    (I work for a company as a security audit, and this is a cryptography 101 algorithm. There are no "perfect" algorithms and such algorithms are not practical for today. But if you can write a good one, you are many steps ahead in your programming career! At least give it a try.


    You need to write an algorithm that accepts a 32 bit integer. Then, it has to provide two integers back, that when multiplied, produces the given number. Now the challenge is that BOTH of these returns values should be Prime numbers. If it can't find a prime number factorization, it should return 0.

    Example: input = 35; output should be "7 * 35".
    Input = 143; output should be 11*13 because 11*13 = 143.

    You can find examples off the internet. But try to write one first.

    Winner is chosen after a reasonable number of submissions. Fastest code wins.
    At the time of evaluation, a sample input will be given, and the snippet that takes the smallest amount of time yet provides the correct answer wins.

    එල ම‍චෝ try කරන්නම් :nerd:
    මචං "7 * 35" නෙමේ "7 * 5" වෙන්න ඕන නේද?​


    patta thread ekak mchooo ela ela digatama yamu... :D
    තැන්කිව් මචං​
     
    Last edited:

    kolavari

    Well-known member
  • Aug 11, 2012
    33,746
    1
    25,653
    113
    කැළෑ පොජ්ජේ
    Input දෙන්න ඕන තියෙන විදියට බං.. උඹ කෑල්ලක් අත ඇරලා කරලා තියෙන්නේ..
    Input must be:

    3
    4
    12
    1

    output :
    1
    4
    12

    එල PHP දාමු මචං ඊලග එකේ ඉදං.. මට නෙමේනේ Rep හම්බෙන්නේ උඹලටනේ :P

    Input eka ohoma new line eke denna oneda? uba kiyanne ethakota first input eka awilla number of integers in the list kiyala da? ethakota api output karanna one e gaanata wenakan?
     

    owlX

    Well-known member
  • Jul 13, 2014
    1,321
    400
    83
    /usr/bin
    here is my challenge.
    (I work for a company as a security audit, and this is a cryptography 101 algorithm. There are no "perfect" algorithms and such algorithms are not practical for today. But if you can write a good one, you are many steps ahead in your programming career! At least give it a try.


    You need to write an algorithm that accepts a 32 bit integer. Then, it has to provide two integers back, that when multiplied, produces the given number. Now the challenge is that BOTH of these returns values should be Prime numbers. If it can't find a prime number factorization, it should return 0.

    Example: input = 35; output should be "7 * 35".
    Input = 143; output should be 11*13 because 11*13 = 143.

    You can find examples off the internet. But try to write one first.

    Winner is chosen after a reasonable number of submissions. Fastest code wins.
    At the time of evaluation, a sample input will be given, and the snippet that takes the smallest amount of time yet provides the correct answer wins.

    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:
     
    Last edited:
    • Like
    Reactions: Ayeshlive

    owlX

    Well-known member
  • Jul 13, 2014
    1,321
    400
    83
    /usr/bin
    කව්රුත් තාම හරි එක දැම්මේ නෑ.. ඉක්මන් කරන්න දැන්ම ඔබේ Rep සියල්ල ලබා ගන්න.
    Rep Sponsors : CrazyBuddy, Wolverine_GTR and Many :lol:
     
    Last edited:

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,852
    1
    9,598
    113
    Gampaha
    මචං User එයාලගේ values දෙන්න ඕන​

    උබට කවුද මචන් මේ කතාව කිව්වෙ.. අනේ මන්ද මම workshops ගොඩකට සහභාගි වෙලා තියෙනව. colombo uni එකෙන් කරන ඒව වගේම UK ඒවට පවා. question එකේ user input කියල තිබ්බට ඒක final variable එකකින් තමා represent කරන්නෙ.. :)

    scanner class ලියන්න වෙලාව දෙන්නෙත් නෑ. වැඩකුත් නෑ. මාත් ඉස්සර scanner class දදා තමා කලේ. ඒත් colombo uni සර් කෙනෙක් තම එකක්දි කියල දුන්නෙ user inputs use කරන විදිය.
     

    kolavari

    Well-known member
  • Aug 11, 2012
    33,746
    1
    25,653
    113
    කැළෑ පොජ්ජේ
    උබට කවුද මචන් මේ කතාව කිව්වෙ.. අනේ මන්ද මම workshops ගොඩකට සහභාගි වෙලා තියෙනව. colombo uni එකෙන් කරන ඒව වගේම UK ඒවට පවා. question එකේ user input කියල තිබ්බට ඒක final variable එකකින් තමා represent කරන්නෙ.. :)

    scanner class ලියන්න වෙලාව දෙන්නෙත් නෑ. වැඩකුත් නෑ. මාත් ඉස්සර scanner class දදා තමා කලේ. ඒත් colombo uni සර් කෙනෙක් තම එකක්දි කියල දුන්නෙ user inputs use කරන විදිය.

    Meka attha..wadagath wenne user input eka ganna widihata wada code eke logic ekai..logic eka awul nam user input eken wadak na..:)
     

    owlX

    Well-known member
  • Jul 13, 2014
    1,321
    400
    83
    /usr/bin
    උබ මරුසිරා එකේ හිටපු වවුලා නේද..? :oo:
    :shocked::shocked::shocked:


    උබට කවුද මචන් මේ කතාව කිව්වෙ.. අනේ මන්ද මම workshops ගොඩකට සහභාගි වෙලා තියෙනව. colombo uni එකෙන් කරන ඒව වගේම UK ඒවට පවා. question එකේ user input කියල තිබ්බට ඒක final variable එකකින් තමා represent කරන්නෙ.. :)

    scanner class ලියන්න වෙලාව දෙන්නෙත් නෑ. වැඩකුත් නෑ. මාත් ඉස්සර scanner class දදා තමා කලේ. ඒත් colombo uni සර් කෙනෙක් තම එකක්දි කියල දුන්නෙ user inputs use කරන විදිය.
    කව්ද මචං සර් භාග්‍ය ද?

    Meka attha..wadagath wenne user input eka ganna widihata wada code eke logic ekai..logic eka awul nam user input eken wadak na..:)

    මේකයි මචං කේස් එක, අපි කොච්චර Logic එක දැනගෙන හිටියත් වෙලාවකට code කරගන්න බෑ. ඒක පැත්තකින් තියමුකෝ උඹලා කියන කතාව ඇත්ත. ඒත් හොද coder කෙනෙක් code කරන්නේ අප‍ට ‍‍ලේසි වෙන්න නෙමේ use කරන කෙනාට ලේසි වෙන්න. SMART CODING. Google I/O එකේ මේක ගැන කතා උනා මට මතක විදියට මේ සැරේ. ඒ වගේම UCSC මං join උන workshop එක්කනම් ‍මං කියලා තියන විදියමයි කරේ. මගේ logic එක හරි උනත් අවසානෙට space එකක් ආපු හින්දා fail කරා. මේකමයි ගොඩක් වෙලාවට interview එක්කදි බලන්නෙත්.:) ඒ වගේම උඹලා කියන එකටත් මං එකගයි. මං එහෙම කරන්න කිව්වේ ඉගෙන ගන්න ලේසියට අනිත් අයටත්
     
    Last edited:

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,852
    1
    9,598
    113
    Gampaha
    Meka attha..wadagath wenne user input eka ganna widihata wada code eke logic ekai..logic eka awul nam user input eken wadak na..:)
    අනිවා. :cool: මට මතක විදියට

    1. Logic
    2. Efficiency
    3. Semantics
    එහෙම නැතුව user inputs අරන් මේ code එක ලියනව නම් හෙන කෙලියක් කරන්න ඕනෙ හරියටම ක්‍රෑශ් නොවී රන් වෙන්න නම්... :frown:
     

    owlX

    Well-known member
  • Jul 13, 2014
    1,321
    400
    83
    /usr/bin
    අනිවා. :cool: මට මතක විදියට

    1. Logic
    2. Efficiency
    3. Semantics
    එහෙම නැතුව user inputs අරන් මේ code එක ලියනව නම් හෙන කෙලියක් කරන්න ඕනෙ හරියටම ක්‍රෑශ් නොවී රන් වෙන්න නම්... :frown:
    එ්ක problem එකෙන් problem එකට වෙනස් වෙනවා මචං. උඹ හිතහන් මේක පටලවලා තියෙන්නේ problem is problem නේ :P බලහන් මගේ problem එකේ විදියට

    input :
    5
    5
    45
    1
    4
    5

    output :
    1
    4
    5
    5
    45

    මේක දැකපු ගමන් සමහර උන්ට හිතෙන්නේ මං වැරදියට type කරලා කියලා. සමහර උන් confuse වෙනවා කෝ අනිත් 5 කියලා. ඒක තමා problem එකේ ස්භාවය ඕක කෙලින්ම දුන්නානම් sort කරන්න විතරනේ බං තියෙන්නේ.. ඒක තමා problem එක
    think different
     

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,852
    1
    9,598
    113
    Gampaha
    කව්ද මචං සර් භාග්‍ය ද?

    මේකයි මචං කේස් එක, අපි කොච්චර Logic එක දැනගෙන හිටියත් වෙලාවකට code කරගන්න බෑ. ඒක පැත්තකින් තියමුකෝ උඹලා කියන කතාව ඇත්ත. ඒත් හොද coder කෙනෙක් code කරන්නේ අප‍ට ‍‍ලේසි වෙන්න නෙමේ use කරන කෙනාට ලේසි වෙන්න. SMART CODING. Google I/O එකේ මේක ගැන කතා උනා මට මතක විදියට මේ සැරේ. ඒ වගේම UCSC මං join උන workshop එක්කනම් ‍මං කියලා තියන විදියමයි කරේ. මගේ logic එක හරි උනත් අවසානෙට space එකක් ආපු හින්දා fail කරා. මේකමයි ගොඩක් වෙලාවට interview එක්කදි බලන්නෙත්.:) ඒ වගේම උඹලා කියන එකටත් මං එකගයි. මං එහෙම කරන්න කිව්වේ ඉගෙන ගන්න ලේසියට අනිත් අයටත්
    මේ මොන පිස්සු කතාවක්ද? user inputs validate කරගෙන user friendly වෙන්න algorithm ලියන්නෙ මොන workshop එකේද බන්?
    :lol::rofl::rofl:
     

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,852
    1
    9,598
    113
    Gampaha
    එ්ක problem එකෙන් problem එකට වෙනස් වෙනවා මචං. උඹ හිතහන් මේක පටලවලා තියෙන්නේ problem is problem නේ :P බලහන් මගේ problem එකේ විදියට

    input :
    5
    5
    45
    1
    4
    5

    output :
    1
    4
    5
    5
    45

    මේක දැකපු ගමන් සමහර උන්ට හිතෙන්නේ මං වැරදියට type කරලා කියලා. සමහර උන් confuse වෙනවා කෝ අනිත් 5 කියලා. ඒක තමා problem එකේ ස්භාවය ඕක කෙලින්ම දුන්නානම් sort කරන්න විතරනේ බං තියෙන්නේ.. ඒක තමා problem එක
    think different
    අනේ මන්ද මචන් ඒක තමා මගේ කෝඩ් එකේ මම වෙනම lines කියල variable එකකට ඒක assign කරන් තියෙන්නෙ. රිවිව් කරන කෙනාට පැහැදිලිව පේනව කෝඩර් ඒක අදුන ගත්ත බව.

    එහෙම නැත්නම් මට තිබුන arrays.length කියල පාවිච්චි කරන්න. එහෙම උනා නම් කෝඩ් එක ෆේල්... එක user input එකක් represent වෙලා නෑ.. :dull:

    මම freelancer එකේ දැන්ට uni assignments 10ට වඩා කරල තියෙනව. ඔක්කොම පාස්. 5 star ratings තියෙනව. කවදාවත් user inputs අරන් කෝඩ් ලියල නෑ. :no:


    ෆයිනලි නෝ ඔෆ්ෆෙන්ස් මචෝ. උබ කියන විදියට කරගෙන යමු.:cool: උබ පටන් ගත්ත වැඩේ නෙ.
    11.gif