반응형

코딩놀이! 10 Days of Statistics(HackerRank)

 Day 1-3: Standard Deviation



세 번째 문제!

 Objective 

In this challenge, we practice calculating standard deviation. Check out the Tutorial tab for learning materials and an instructional video!

Task 
Given an array, , of  integers, calculate and print the standard deviation. Your answer should be in decimal form, rounded to a scale of  decimal place (i.e.,  format). An error margin of  will be tolerated for the standard deviation.

Input Format

The first line contains an integer, , denoting the number of elements in the array. 
The second line contains  space-separated integers describing the respective elements of the array.

Constraints

  • , where  is the  element of array .

Output Format

Print the standard deviation on a new line, rounded to a scale of  decimal place (i.e.,  format).

Sample Input

5
10 40 30 50 20

Sample Output

14.1

Explanation

First, we find the mean

Next, we calculate the squared distance from the mean, , for each :

Now we can compute , so:

Once rounded to a scale of  decimal place, our result is .


음 세번째 문제는 Standard Deviation!!! 간단한 표준 편차 구하기 입니다.


그럼 바로 문제 해석 들어갑니닷!


문제해석!

1. 입력받을 숫자의 갯수를 n 입력받습니다.

2. n 개 만큼 입력 받는다.

3. 입력 받은 n개의 숫자 평균을 구한다.

4. n개의 숫자중 (첫번째 숫자 - 평균) + (두번째 숫자 - 평균) + .....(n번째 숫자 - 평균) 을 모두 더한다

5. 다시 n으로 나눈다!

6. 루트씌운다! 끝.

계산식!!!

1.없음! 필요...할까요??

(출처:http://www.ktword.co.kr/abbr_view.php?m_temp1=1657)


역시 말보단 코딩!

 class Solution {

     static void Main(String[] args)

    {

        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */

        int inputCount = Convert.ToInt32(Console.ReadLine());

        int[] arr_values = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

        Console.WriteLine(standardDeviation(arr_values, inputCount));

    }

    static double standardDeviation(int[] arr_values, int inputCount)

    {

        if (inputCount != arr_values.Length)

        {

            //return fail;throwException

        }

        int arrSum = 0;

        foreach(int values in arr_values)

        {

            arrSum += values;

        }

        int arrAvg = arrSum / inputCount;


        double deviationSum = 0;

        foreach(int value in arr_values)

        {

            deviationSum += Math.Pow(value - arrAvg, 2);

        }

        return Math.Round(Math.Sqrt(deviationSum/inputCount),1);

    }

}


끝입니다!ㅎㅎ

새벽이 다가오네요...아 잠와...


후기!. 사실 이 문제를 어쩌면 엄청나게 고민하면서 계산식이 들어가야 하는게 제대로된 공부라고 생각해요.

사실 제가 짠 코드는 보시는바와 같이

C#의 Math라는 Class를 이용해서 정말 편리하게 풀었어요 ㅎㅎ

Math.Pow(제곱대상, 몇제곱?) - 제곱근을 나타내는거고요 Pow의 리턴타입은 double입니다.

Math.Sqrt(루트안에값, 루트몇?) - 루트를 구해주는 함수입니다....이거없으면ㅠㅠ정말 고민이였을거예요...까먹은지가 너무 오래되서 ㅎㅎ

Math Class에 대한 자세한 설명은 (https://docs.microsoft.com/ko-kr/dotnet/api/system.math?view=netframework-4.7.2) 여기 나와있습니다. 정말 막강한 기능이 많아요. 똑똑한 사람들이 짜놓은 공통함수? 라고 생각되네요.


개발할때 자신만의 공통함수를 만들어 놓는것도 중요하지만 이미 Framework에서 지원하는 기능은 잘 이용하는게 좋겠죠?ㅎㅎ



RunCode!!

Congratulations!

You have passed the sample test cases. Click the submit button to run your code against all the test cases.

Input (stdin)
5
10 40 30 50 20
Your Output (stdout)
14.1
Expected Output 14.1 


역시나 크흐흐 Easy만 풀고싶다능...


그렇타면! submit!!!!!!!!!

Congratulations
You solved this challenge. Would you like to challenge your friends?
Input (stdin)Download
5
10 40 30 50 20
Expected OutputDownload
14.1
Compiler Message Success 


예쑤!~  다시한번 30점!! 득템입니다 ㅎㅎ



Day 1 에는 3문제 모두 Clear!!

Day 2에도...3문제가 있네요...

그럼이만!


(출처:https://www.hackerrank.com/challenges/s10-standard-deviation/problem)

반응형
반응형

코딩놀이! 10 Days of Statistics(HackerRank)

 Day 1-2: Quartiles


세 번째 문제!

(오늘은...잠안오는김에! 노트북을 켰습니다 ㅎㅎ)

 Objective 

In this challenge, we practice calculating the interquartile range. We recommend you complete the Quartiles challenge before attempting this problem.

Task 
The interquartile range of an array is the difference between its first () and third () quartiles (i.e., ).

Given an array, , of  integers and an array, , representing the respective frequencies of 's elements, construct a data set, , where each  occurs at frequency . Then calculate and print 's interquartile range, rounded to a scale of  decimal place (i.e.,  format).

Tip: Be careful to not use integer division when averaging the middle two elements for a data set with an even number of elements, and be sure to not include the median in your upper and lower data sets.

Input Format

The first line contains an integer, , denoting the number of elements in arrays  and 
The second line contains  space-separated integers describing the respective elements of array 
The third line contains  space-separated integers describing the respective elements of array .

Constraints

  • , where  is the  element of array .
  • , where  is the  element of array .
  • The number of elements in  is equal to .

Output Format

Print the interquartile range for the expanded data set on a new line. Round your answer to a scale of  decimal place (i.e., format).

Sample Input

6
6 12 8 10 20 16
5 4 3 2 1 5

Sample Output

9.0

Explanation

The given data is:

InterquartileRange

First, we create data set  containing the data from set  at the respective frequencies specified by 

As there are an even number of data points in the original ordered data set, we will split this data set exactly in half:

Lower half (L): 6, 6, 6, 6, 6, 8, 8, 8, 10, 10

Upper half (U): 12, 12, 12, 12, 16, 16, 16, 16, 16, 20

Next, we find . There are  elements in  half, so  is the average of the middle two elements:  and . Thus, .

Next, we find .There are  elements in  half, so  is the average of the middle two elements:  and . Thus, .

From this, we calculate the interquartile range as  and print  as our answer.


음 두번째 문제는  Interquartile Range!!! 중앙값? 구하기 ㅎㅎ(Day 1일차에 quartiles랑 비슷하네요. 아니 똑같네요 ㅋㅋ)

Q1과 Q3 구하기!

역시나 문제읽기는 대충 패스! 인풋 아웃풋! 샘플


그럼 바로 문제 해석 들어갑니닷!


문제해석!

1. 입력받을 숫자의 갯수를 n 입력받습니다.

2. n 개 만큼 입력 받는다.

3. 입력 받은 n 숫자의 중앙 값을 찾습니다.

4. n중앙값(Q2)을 기준으로 왼쪽에 있는 값들의 중앙값을 찾습니다.-> Q1!

5. n중앙값(Q2)을 기준으로 오른쪽에 있는 값들의 중앙값을 찾습니다. -> Q3!

6. Q3 뺴기 Q1을 출력합니다.

계산식!!!

1. n가 짝수 인지 홀수 인지 확인!(if(n%2==0))

* (여기서 잠깐!. % 는 mod 를 나타냅니다 만약(if) n을 2로 나눠서 나머지가 0인가? 라는 질문에서 0이면 짝수!, 0이아니면 홀수 겟죠??)*

 짝수인 경우(ex.1, 2, 3, 4, 5, 6)

홀수인경우 (ex. 1,2,3,4,5)

 2.중앙(3.5)에서 왼쪽(3)+오른쪽(4) 값을 2로나누면 Q2(3.5)

 3. 3.5의 왼쪽 값 1, 2, 3 의 중앙값은 Q1(2)

 4. 3.5의 오른쪽 값 4, 5, 6 의 중앙값은 Q3(5)

 2. 중앙의 값은 Q2(3)

 3. 중앙(3) 왼쪽 값 1,2 의 중앙값은 Q1(1.5 )

 4. 중앙(3) 오른쪽 값 4,5의 중앙값은 Q3(4.5)

이렇게 풀면 되는 문제 입니다! ㅎㅎ

-----------------------------------------------여기까지 복붙'S  같은 문제니깐요 ㅎㅎ

하지만 이전 글을 못 보신 분을 위해 다시한번 복붙'S! 게시글 우려먹기'S

그래서 준비한! 이해력을 위한 꿀팁!

 n이 홀수일 경우!

Example: 5, 7, 4, 4, 6, 2, 8

Put them in order: 2, 4, 4, 5, 6, 7, 8

Cut the list into quarters:

Quartiles of 2, 4, 4, 5, 6, 7, 8

And the result is:

  • Quartile 1 (Q1) = 4
  • Quartile 2 (Q2), which is also the Median, = 5
  • Quartile 3 (Q3) = 7


 n이 짝수일 경우

Example: 1, 3, 3, 4, 5, 6, 6, 7, 8, 8

The numbers are already in order

Cut the list into quarters:

Quartiles

In this case Quartile 2 is half way between 5 and 6:

Q2 = (5+6)/2 = 5.5

And the result is:

  • Quartile 1 (Q1) = 3
  • Quartile 2 (Q2) = 5.5
  • Quartile 3 (Q3) = 7

(출처:mathsisfun, http//www.mathsisfun.com/data/quartiles.html)


이번 문제에서는 Q1과 Q3 만 구하라고 하네요 ㅎㅎ 

(도대체 왜 !!! 왜!!!!!! 문제를 나눠놨지?? 수학왕님들은 댓글좀 달아서 차이좀 알려줍숑)


바로! 코딩 들어갈게윱

 class Solution {

    static void Main(String[] args)

    {

        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */

        int inputCount = Convert.ToInt32(Console.ReadLine());

        int[] arr_Element = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

        int[] arr_Frequency = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

        Console.WriteLine(interquartileRange(arr_Element, arr_Frequency));

    }

    static string interquartileRange(int[] arr_Element, int[] arr_Frequency)

    {

        if (arr_Element.Length != arr_Frequency.Length)

        {

            //return fail;

        }


        List<int> dataSet = new List<int>();


        int count = 0;

        foreach (int element in arr_Element)

        {

            for (int i = 0; i < arr_Frequency[count]; i++)

            {

                dataSet.Add(element);

            }

            count++;

        }

        dataSet.Sort();


        int middle = dataSet.Count / 2;

        int lowerMiddle = middle / 2;

        int upperMiddle = (dataSet.Count) - lowerMiddle-1;

        decimal result, lowerHarf, upperHarf;

        if ((dataSet.Count) % 2 == 0)

        {

            if (middle % 2 == 0)

            {

                lowerHarf = (decimal)(dataSet[lowerMiddle] + dataSet[lowerMiddle - 1]) / 2;

                upperHarf = (decimal)(dataSet[upperMiddle] + dataSet[upperMiddle + 1]) / 2;

            }

            else

            {

                lowerHarf = dataSet[lowerMiddle];

                upperHarf = dataSet[upperMiddle];

            }   

        }

        else

        {

            if (middle % 2 == 0)

            {

                lowerHarf = (decimal)(dataSet[lowerMiddle] + dataSet[lowerMiddle - 1]) / 2;

                upperHarf = (decimal)(dataSet[upperMiddle] + dataSet[upperMiddle + 1]) / 2;

            }

            else

            {

                lowerHarf = dataSet[lowerMiddle];

                upperHarf = dataSet[upperMiddle];

            }

        }

        return String.Format("{0:0.0}", (upperHarf - lowerHarf));

    }

}


이전 문제랑 같은 소스;;;기때문에 별다를게 없네요 ㅎㅎ


오늘의 글은 회식후 의식의 흐름에 맞춰 쓰는중입니다..ㅠㅠ


후기!. 이전  Day 1: Quartiles 사분위수 구하기 문제와 같음! 뭐 수학적 의미는 모름!


그뒤!

RunCode!!

Congratulations!

You have passed the sample test cases. Click the submit button to run your code against all the test cases.

Input (stdin)
6
6 12 8 10 20 16
5 4 3 2 1 5
Your Output (stdout)
9.0
Expected Output 9.0 


음~~~좋아좋아~~~


submit!!!!!!!!!

Congratulations
You solved this challenge. Would you like to challenge your friends?
Input (stdin)Download
6
6 12 8 10 20 16
5 4 3 2 1 5
Expected OutputDownload
9.0
Compiler Message Success 


흐흠 ㅋㅋㅋㅋ 역시 좋아좋아 ㅋㅋㅋ 이번 Testcase는 6개나 되네요.

사실 문제 풀다가 제일 싫은게 Testcae 0부터 9까지 통과인데 Testcase10이 통과하지 못하면

정말...세젤귀... 세상에서 제일 귀찮은 에러가 나죠... 보통 저런경우 타입문제가 대부분이지만요 ㅋㅋ

Hackerrank에서는 가~~~~~~~~~~~~~~끔 말도안되는 큰 값을 넣어주는 경우가 발생하거든요 ㅋㅋㅋ


뭐 어쨋든 오늘(?..12시넘었구나..?)도 한문제 Clear!!!입니다.

그럼 오늘도 이만!!!


(출처:https://www.hackerrank.com/challenges/s10-interquartile-range/problem)

반응형
반응형

코딩놀이! 10 Days of Statistics(HackerRank)

 Day 1-1: Quartiles



두 번째 문제!

 Objective 

In this challenge, we practice calculating quartiles. Check out the Tutorial tab for learning materials and an instructional video!

Task 
Given an array, , of  integers, calculate the respective first quartile (), second quartile (), and third quartile (). It is guaranteed that , and  are integers.

Input Format

The first line contains an integer, , denoting the number of elements in the array. 
The second line contains  space-separated integers describing the array's elements.

Constraints

  • , where  is the  element of the array.

Output Format

Print  lines of output in the following order:

  1. The first line should be the value of .
  2. The second line should be the value of .
  3. The third line should be the value of .

Sample Input

9
3 7 8 5 12 14 21 13 18

Sample Output

6
12
16

Explanation

. When we sort the elements in non-decreasing order, we get . It's easy to see that .

As there are an odd number of data points, we do not include the median (the central value in the ordered list) in either half:

Lower half (L): 3, 5, 7, 8

Upper half (U): 13, 14, 18, 21

Now, we find the quartiles:

  •  is the . So, .
  •  is the . So, .
  •  is the . So, .


음 두번째 문제는 Quartiles!!! 사분위수 구하기 입니다.

제 1 사분위수, 제2사분위수, 제3사분위수를 구하면 되는 문제네요 ㅎㅎ

역시나 문제읽기는 대충 패스! 인풋 아웃풋! 샘플


그럼 바로 문제 해석 들어갑니닷!


문제해석!

1. 입력받을 숫자의 갯수를 n 입력받습니다.

2. n 개 만큼 입력 받는다.

3. 입력 받은 n 숫자의 중앙 값을 찾습니다. -> Q2!

4. n중앙값(Q2)을 기준으로 왼쪽에 있는 값들의 중앙값을 찾습니다.-> Q1!

5. n중앙값(Q2)을 기준으로 오른쪽에 있는 값들의 중앙값을 찾습니다. -> Q3!

계산식!!!

1. n가 짝수 인지 홀수 인지 확인!(if(n%2==0))

* (여기서 잠깐!. % 는 mod 를 나타냅니다 만약(if) n을 2로 나눠서 나머지가 0인가? 라는 질문에서 0이면 짝수!, 0이아니면 홀수 겟죠??)*

 짝수인 경우(ex.1, 2, 3, 4, 5, 6)

홀수인경우 (ex. 1,2,3,4,5)

 2.중앙(3.5)에서 왼쪽(3)+오른쪽(4) 값을 2로나누면 Q2(3.5)

 3. 3.5의 왼쪽 값 1, 2, 3 의 중앙값은 Q1(2)

 4. 3.5의 오른쪽 값 4, 5, 6 의 중앙값은 Q3(5)

 2. 중앙의 값은 Q2(3)

 3. 중앙(3) 왼쪽 값 1,2 의 중앙값은 Q1(1.5 )

 4. 중앙(3) 오른쪽 값 4,5의 중앙값은 Q3(4.5)

이렇게 풀면 되는 문제 입니다! ㅎㅎ

(제가 수학을 잊은지가 오래되서 잘 기억은안나지만 그래프! 를 보시면 조금더 어렵게 느껴지실거예요 ㅋㅋㅋ, 가 아니라 표를보는게 더 편해요ㅋ)

(출처: 위키미디어;https://upload.wikimedia.org/wikipedia/commons/1/1a/Boxplot_vs_PDF.svg)


역시나 그래프를 보면 어디서 본듯하지만 이해는 안됩니다 사.분.위.수.란...


그래서 준비한! 이해력을 위한 꿀팁!

 n이 홀수일 경우!

Example: 5, 7, 4, 4, 6, 2, 8

Put them in order: 2, 4, 4, 5, 6, 7, 8

Cut the list into quarters:

Quartiles of 2, 4, 4, 5, 6, 7, 8

And the result is:

  • Quartile 1 (Q1) = 4
  • Quartile 2 (Q2), which is also the Median, = 5
  • Quartile 3 (Q3) = 7


 n이 짝수일 경우

Example: 1, 3, 3, 4, 5, 6, 6, 7, 8, 8

The numbers are already in order

Cut the list into quarters:

Quartiles

In this case Quartile 2 is half way between 5 and 6:

Q2 = (5+6)/2 = 5.5

And the result is:

  • Quartile 1 (Q1) = 3
  • Quartile 2 (Q2) = 5.5
  • Quartile 3 (Q3) = 7

(출처:mathsisfun, http//www.mathsisfun.com/data/quartiles.html)


위 사진을 보면 바로 이해가 되실거예요 ㅎㅎ




자 이제 역시나 슈도코딩?!!!이 나름 끝났으니 끄적끄적 코딩!!!!!!

 class Solution {

    static void Main(String[] args)

        {

            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */

            int inputCount = Convert.ToInt32(Console.ReadLine());

            int[] arr_q = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            if (arr_q.Length != inputCount)

            {

                Console.WriteLine("error. a lot of number");

                //여기서 사실 다시 입력을 받아야겟죠?

            }

            foreach (decimal a_temp in quartiles(arr_q))

            {

                Console.WriteLine(a_temp);

            }

        }


        static List<decimal> quartiles(int[] arr_q)

        {

            Array.Sort(arr_q);

            

            decimal q1, q2, q3;

            int n = arr_q.Length;

            int q2mid = n / 2;

            int q1mid = (q2mid - 1) / 2;

            int q3mid = n - q1mid - 1;

            if (n % 2 == 0)

            {

                q2 = (decimal)(arr_q[q2mid] + arr_q[q2mid - 1]) / 2;

                if (q2mid % 2 != 0)

                {

                    q1 = arr_q[q1mid];

                    q3 = arr_q[q3mid];

                }

                else

                {

                    q1 = (decimal)(arr_q[q1mid] + arr_q[q1mid - 1]) / 2;

                    q3 = (decimal)(arr_q[q3mid] + arr_q[q3mid - 1]) / 2; 

                }

            }

            else

            {

                q2 = arr_q[q2mid];

                if (q2mid % 2 != 0)

                {

                    q1 = arr_q[q1mid];

                    q3 = arr_q[q3mid];

                }

                else

                {

                    q1 = (decimal)(arr_q[q1mid] + arr_q[q1mid + 1]) / 2;

                    q3 = (decimal)(arr_q[q3mid] + arr_q[q3mid - 1]) / 2;

                }

            }

            return new List<decimal> { q1,q2,q3 }; 

        }

}




짜란 역시...엄청난 하드코딩의 느낌이 나죠...네 맞습니다 ㅋㅋㅋ 하드코딩이지만 나름 고뇌를...ㅠㅠ


코드짜실때 팁은!

n을 짝수인지 홀수 인지 판단하시고

Q2를 기준으로 왼쪽, 오른쪽에 남은게 홀수?짝수? 판단을 해주셔야해요

그리고 배열의 시작은 0번째 부터입니다!!

처음에는 list를쓸지 array를 쓸지 dictionary를 쓸지 고민했는데요

의식의 흐름일까요? 그냥 쓰던데로 쓰게 되더군요 ㅋㅋㅋ


후기!. 이전  Day 0: Weighted Mean 문제와는 다르게 처음 n을 입력받는걸 고민하다가

그냥 n보다 많으면 숫자를 많이 넣으셨어요 하게 쳤습니다.  물론 다시 입력받고 하는건 귀찮아서...ㅋㅋㅋ


일단 메인 Quartiles 를 구하는건 짜놧으니 알!아!서!되겟쥬 ㅋㅋ


역시 문제를 풀고나서

RunCode!!

Compilation Successful :)

Click the Submit Code button to run your code against all the test cases.

  • Custom Testcase
Input (stdin)
5
1 2 3 4 5
Your Output (stdout)
1.5
3
4.5

잘 들어갓네요 ㅎㅎㅎ


그렇타면! 자싄감을 가지고 submit!!!!!!!!!


You have earned 30.00 points!
You are now 2 challenges away from the 2nd star for your 10 days of statistics badge.
0%3/5
Congratulations
You solved this challenge. Would you like to challenge your friends?
Input (stdin)Download
9
3 7 8 5 12 14 21 13 18
Expected OutputDownload
6
12
16
Compiler Message
Success


흐흠 ㅋㅋㅋㅋ 기분이 좋네윱 오늘은 30점!! 득템입니다 ㅎㅎ



Day 1 에는 3문제가 있네요 하지만 오늘 1문제뿐.....귀차....ㄶ지는 않고요 ㅋㅋ

하루에 1개씩 풀기로했으니(?!) ㅋㅋ 그럼오늘도 이만!


(출처:https://www.hackerrank.com/challenges/s10-quartiles/problem)

반응형
반응형

코딩놀이! HackerRank!! 소개 및 추천(?)


오늘 소개 해드릴 코드 놀이 사이트중 한개인 HackerRank 입니다..!!

이 사이트는.....음....

 

해커랭크

위키백과, 우리 모두의 백과사전.
둘러보기로 가기검색하러 가기
해커랭크.

해커랭크(HackerRank)는 소비자와 사업체를 위한 경쟁 프로그래밍 도전에 초점을 둔 기술 기업으로서[1] 개발자들은 주어진 사양에 따라 프로그래밍을 시도함으로써 경쟁한다.[2][3] 해커랭크의 프로그래밍 도전들은 다양한 프로그래밍 언어(자바C++PHP파이썬SQL자바스크립트 등)로 풀 수 있으며 여러 컴퓨터 과학 분야를 아우른다.[4]

컴퓨터 측에서 프로그래머가 프로그래밍 도전에 대한 해결책을 제출하면 출력의 정확도에 따라 제출 자료의 점수를 매긴다. 프로그래머들은 해커랭크 리더보드 전반에 걸쳐 순위가 매겨지며 사용자 간 경쟁을 유도하기 위해 성취에 기반한 배지가 수여된다. 개개의 프로그래밍 도전들 외에도 해커랭크는 콘텐츠(해커랭크에서는 코드스프린츠/CodeSprints로 부름)를 호스팅하고 있는데 여기에서 사용자들은 정해진 시간 동안 동일한 프로그래밍 도전들로 경쟁하며 행사가 끝날 무렵 순위가 매겨진다. 해커랭크는 경쟁적인 컴퓨터 프로그래밍 내에서 점차 커져가는 게임화 트렌드의 일부로 간주되며[5] 웹사이트의 소비자 측면에서는 코더들이 무료로 사용할 수 있다.




(출처:위키백과:https://ko.wikipedia.org/wiki/%ED%95%B4%EC%BB%A4%EB%9E%AD%ED%81%AC)

이거 라고 하네요 ㅎㅎㅎㅎ

그냥 알고리즘 이나 사람들이 만든 퀴즈같은걸 여러 프로그래밍 언어로 풀고 점수를 쌓고 자기만족도 하고 경쟁도 하고 그런 사이트 입니다.

더 나아가서는 기업에서 비즈니스 파트너가 되어 온라인 코딩시험을 진행 하기도 합니당 ㅎㅎ



그렇타면 이걸 왜 하냐???뭔재미냐????

라고 생각하실수 있는데요. IT 개발자로서, 개발덕후로서. 퇴근하면 채워지지 않는 엄청난 허전함... 그 뭔가 코드몽키(포프TV참조)가 되어간다는 불안감! 회사에서 돈을벌기위해 짜는 소스가 재미없고 같은일에 반복이라고 느껴질때! 좋은 도움이 됩니다!

정말 아! 그래 코드 짜면서 이렇게 생각해보고 저렇게 생각해보고 문제를 풀었을때 느끼는 성취감!!! 이라고 할수있죠!

그리고, 이걸 풀면서 조금은 도움이 되는?!그런건....바로바로!!!! nOO.., nOO, kOO... 등 여러 IT메이저 회사 에서는 입사 시험볼때 저런 코딩페이지를 통해서 온라인 시험이 치뤄지는건 안.비.밀.! ㅋㅋㅋㅋㅋ


먼저 HackerRank의 메인 화면입니다. (https://www.hackerrank.com).

보는것과 같이 이미 4million의 개발자가 가입되어 있다고하네요 ㅋㅋㅋㅋ


오른쪽 상단에 가입 혹은 로그인을 합니다( 가입, 로그인 못하는 분은 없다고 생각하고 건너 띌게요)



로그인후 주로 사용하는 언어(C#, JAVA, C, 등등)를 클릭하고 간단한 숫자문제를 풀고 Run을하게되면 축하한다는 메세지와 함께

다음 화면으로 넘어갑니다.


위에 보이시는 사진은 해커랭크에서 Dashboard라는 건데요

간단히 내가 도전하고 있는 챌린지나 풀던문제, 나를 위해 추천하는 문제 그런것들이 보여집니다

위 페이지에서 아래로 내리면

이런 것들도 있는데요

알고리즘이나, 데이터 스터럭쳐, 언어별, SQL문 등 연습할수 있는 퀴즈 들이 매우매우 많습니다.

알고 리즘에 한번 들어가보죠!

위 사진에 보시면 Solved(해결한문제), solveChallenge(도전할문제) 가 있습니다.


저렇게 문제에 SolveChallenge에 들어가서 문제를 이것저것 풀이볼수 있어요 ㅎㅎ

아! 이건 와이프 이름으로 새로 가입해서 아무것도 풀어져있지 않은 겁니당 하하하하하 나중에 제 계정에 점수가 높아지면 한번 공개하겠습니다 ㅋㅋㅋ


들어온김에 Easy 난이도에 10점짜리 문제! 93.92퍼센트의 성공률...을보인 Challenge를 풀어보죠 ㅋㅋㅋ


첫번째 연습문제: Compare the Triplets 입니다.

Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from  to  for three categories: problem clarityoriginality, and difficulty.

We define the rating for Alice's challenge to be the triplet , and the rating for Bob's challenge to be the triplet .

Your task is to find their comparison points by comparing  with  with , and  with .

  • If , then Alice is awarded  point.
  • If , then Bob is awarded  point.
  • If , then neither person receives a point.

Comparison points is the total points a person earned.

Given  and , determine their respective comparison points.

For example,  and . For elements , Bob is awarded a point because . For the equal elements  and , no points are earned. Finally, for elements  so Alice receives a point. Your return array would be  with Alice's score first and Bob's second.

Function Description

Complete the function compareTriplets in the editor below. It must return an array of two integers, the first being Alice's score and the second being Bob's.

compareTriplets has the following parameter(s):

  • a: an array of integers representing Alice's challenge rating
  • b: an array of integers representing Bob's challenge rating

Input Format

The first line contains  space-separated integers, , and , describing the respective values in triplet 
The second line contains  space-separated integers, , and , describing the respective values in triplet .

Constraints

Output Format

Return an array of two integers denoting the respective comparison points earned by Alice and Bob.

Sample Input 0

5 6 7
3 6 10

Sample Output 0

1 1

Explanation 0

In this example:

Now, let's compare each individual score:

  • , so Alice receives  point.
  • , so nobody receives a point.
  • , so Bob receives  point.

Alice's comparison score is , and Bob's comparison score is . Thus, we return the array .

Sample Input 1

17 28 30
99 16 8

Sample Output 1

2 1

Explanation 1

Comparing the  elements,  so Bob receives a point. 
Comparing the  and  elements,  and  so Alice receives two points. 

The return array is . 


음 역시나 영어는 읽기가.... 하지만 문제에 나오는 영어는 읽다보면 아 저런거군아 하게 됩니다 ㅋㅋ

HackerRank 문제를 풀면서 제 나름 노하우는 슈도코딩(?)을 먼저 짜고 계산식을 생각해 보는겁니다.


문제해석!

1. A 라는 사람이 숫자를 순서대로 3개 적어 낸다.

2. B 라는 사람도 숫자를 순서대로 3개 적어 낸다.

3. 점수판을 만들고 A, B 점수를 표기한다.

4. A라는 사람이 낸 첫번째 숫자와 B라는 사람이 낸 첫번째 숫자와 비교한다!

5. 높은 숫자의 사람에게 1point 준다!(단, 숫자가 같으면 아무도 point를 얻지 못한다)

6. 3번과 4번을 3번 반복한다.

7. A 사람 점수와 B 사람 점수를 보여준다.

*역시 삼세판이죠잉.


자 이제 풀어볼까요? 너무 간단한가요?ㅎㅎ


using 은 알아서!


class Solution {

// Complete the compareTriplets function below.
static List<int> compareTriplets(List<int> a, List<int> b) {
int count = 0;
int =0;
int bobPoint=0;

foreach(int a_temp in a)
{
if(a_temp > b.ElementAt(count)){
alicePoint++;
}else if(a_temp < b.ElementAt(count)){
bobPoint++;
}else{
//nothing
}
count++;
}
return new List<int> {alicePoint, bobPoint};
}

static void Main(string[] args) {
TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);

List<int> a = Console.ReadLine().TrimEnd().Split(' ').ToList().Select(aTemp => Convert.ToInt32(aTemp)).ToList();

List<int> b = Console.ReadLine().TrimEnd().Split(' ').ToList().Select(bTemp => Convert.ToInt32(bTemp)).ToList();

List<int> result = compareTriplets(a, b);

textWriter.WriteLine(String.Join(" ", result));

textWriter.Flush();
textWriter.Close();
}
}


뭐 이렇게 짜도 되고... 여러 방법이 있겟지요 ㅎㅎ

compareTriplets이놈이 문제 해석에3,4,5번을 합니다.


기본적으로 문제 풀때 Main 에 다 넣을수 있지만 객체 지향 프로그램언어는 그에 맞는 대우(?)를 해줘야겠죠?ㅎㅎ


간단한 문제지만 코드에 애정을 부을수록 더 완성도가 높아지고

익숙해지면 애정을 불어넣는것이 습관이되어 항상 완성도 높은 코드를 짤수 있겟죠?ㅎㅎ 노력합시당

이렇게 코드 를 풀고나면 Run Code를 눌러서 기본 Testcase 두개가 통과됩니다.



물론! 기본 문법에러나 답이 맞지않으면 아래와 같은 사진이 뜨고요. 다시 풀어서 RunCode하시면 됩니당.





문제를 다 풀고 완벽한 마음이 생겼다!! 라면 Submit Code를 누르면 아래와 같은 화면이 나옵니다. 


조금만 기다리시면!

땅!!!!!!!!! 제일 보기좋은 Congratulations 가 나왔습니다 ㅎㅎ


이번문제는 테스트 케이스가 많네요.

저렇게 모든 문제가 통과되면  Easy는 10점!을 얻습니다.

(문제 난이도에 따라 10,20,30,40,50,100,200,등등의 점수를 얻습니다.)


코드 작성하는곳 아래에 

upload code as File 은 IDE(visualStudio, ecllips등) 으로 풀어서 파일형식으로 올릴수도 있습니다.

Test again....custom..input은 내가 인풋을 만들어서 테스트 해볼수 있습니다. 좋은 기능이죠 ㅎㅎ



그리고 문제를 풀고 내계정에서 Hackos를 누르게 되면 내가 풀었던 문제와 얻은 점수 등을 볼수 있어요




그외에.. git과 같이 내가 커밋한 횟수 날자 등등 관리하기 좋은 괜찮은 기능이 많습니다ㅎㅎ


이 글을 보고 한번 따라해보시고 코딩놀이 세계로 빠져드세윱!!!!


그럼이만!!!!!










(출처!: https://www.hackerrank.com)








반응형
반응형

오늘 저녁메뉴로 가리비찜을 해먹었어요. 11월 ~ 12월 까지 가리비가 제철이래요.

제철음식은 항상 먹어줘야하죵ㅎㅎ
이때아니면 언제 먹을까 싶어서 택배주문햇어용 ㅎㅎ

배송하고 하루 뒤에 먹은거라서 보관법 설명해드릴께요.!!

★ 보관법
배송오면 스티리폼 안에 얼음이랑 비닐에 쌓여서 배송오더라구요. 배송업체한테 "하루뒤에 먹을려면 어떻게 보관하면 되냐"고 물으니
스티리폼째로 보관하지 마시고 비닐만빼서 하루 냉장보관 하고 먹으라고 하시더라구요.

*꼭 밀폐하고 보관하세요!! 세균이 번식하기때문에 가급적 빨리 드시는게 좋아요

제 생각에는 만약 더 잇다 드실려면 냉동보관을 해야할꺼에용

이제 해감&세척법을 알려드릴께요!

★가리비 해감


큰볼에 가리비가 잠길만큼 물을 부으신다음 소금 한스푼을 풀어주세요. 숟가락을 넣으면 금속과 소금물이 만나 화학반응을 일으켜 해감이 더 잘된다고 하네용ㅎㅎ 검은 봉지로 감싸고 1시간가량 놔둬주세용 이때 조개들이 바닷물인줄 착각하고 입을벌려 뻘을 뽑는다네용!!


1시간가량 해감한 가리비를 칫솔로 박박! 문질러 주세요. 그래야 겉에 붙은 이물질들이 빠집니당

★ 가리비 찌는 법!

끓는 물에 가리비 입벌리는 쪽이 위로 가게 놓아주세요. 그리고 소주를 한바퀴 둘러주세요! 비린내를 제거해줘야겟죵!!

시간은 총 15분걸려요.
10분은 끓이고 5분은 뜸들여주세요!!
오래끓이면 질겨져서 맛없다고 하네용

중간에 파랑 양파 다져서 넣어줫어요!
이렇게 15분뒤 가리비찜이 완성됐어요♥


★요약
1단계 소금물을 풀어 1시간 해감한다.
2단계 칫솔로 겉에묻은 이물질을 제거한다.
3단계 끓는 찜기에다가 가리비 입이 벌어지는쪽이 위로 가게 놓고 소주를 붓고 15분가량 찐다.
4단계 마싯게 먹는당ㅎㅎㅎ


가리비치즈구이랑 부추무침 계란말이까지해서 저녁클리어 햇네용ㅎㅎㅎ

올 겨울 제철인 가리비로 마싯는 저녁즐겨보세용♥♥


반응형
반응형

코딩놀이! 10 Days of Statistics(HackerRank)

 Day 0: Weighted Mean



첫 번째 문제!


 Objective 

In the previous challenge, we calculated a mean. In this challenge, we practice calculating a weighted mean. Check out the Tutorial tab for learning materials and an instructional video!

Task 
Given an array, , of  integers and an array, , representing the respective weights of 's elements, calculate and print the weighted mean of 's elements. Your answer should be rounded to a scale of  decimal place (i.e.,  format).

Input Format

The first line contains an integer, , denoting the number of elements in arrays  and 
The second line contains  space-separated integers describing the respective elements of array 
The third line contains  space-separated integers describing the respective elements of array .

Constraints

  • , where  is the  element of array .
  • , where  is the  element of array .

Output Format

Print the weighted mean on a new line. Your answer should be rounded to a scale of  decimal place (i.e.,  format).

Sample Input

5
10 40 30 50 20
1 2 3 4 5

Sample Output

32.0

Explanation

We use the following formula to calculate the weighted mean:

And then print our result to a scale of  decimal place () on a new line.



음..... 저는 보통 영어는 읽기....가...눈에.....안들어오죠 ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ

그래서 Sample Input 과 Sample Output 만 보고 푸는 경우가 다반사죠 ㅋㅋㅋ

그다음 아래 있는 Explanation 을 보고 대충 아 숫자 저렇게 오키오키 하고 풉니다.


문제 해석

1. 입력받을 숫자의 갯수를 A 입력받습니다.

2. 분자를 A 개 만큼 입력 받는다.

3. 분모를 A 개 만큼 입력 받는다.

계산식!!!

1. 분자 = 첫번째(분자*분모)+두번째(분자*분모)+세번째(분자*분모)........+A번째(분자*분모)

2. 분모 = 첫번째(분모)+두번째(분모)+세번째(분모).......+A번째(분모)

3. 분자/분모 하여 소수 첫번째 까지 표기!(*반올림*)


자 이제 슈도코딩?!!!이 나름 끝났으니 끄적끄적 코딩!!!!!!

class Solution {

    static void Main(String[] args) {

        int N = Convert.ToInt32(Console.ReadLine());       

        int[] x_arr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

        int[] w_arr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

        Console.WriteLine(weightMin(x_arr, w_arr));

    }

    

    static string weightMin(int[] paramNumerator, int[] paramDenominator)

    {

        int numerator = 0;

        for (var i = 0; i < paramNumerator.Length; i++)

        {

            numerator += paramNumerator[i] * paramDenominator[i];

        }

        

        int denominator = 0;

        foreach(int w_temp in paramDenominator)

        {

            denominator += w_temp;

        }

        

        decimal result = (decimal)numerator/denominator;

        return string.Format("{0:0.0}", result);

    }

}


위 코드 에 대한 설명은.........뭐 필요가 없는거 같네요 ㅋㅋ

그저... 변수들에 네이밍이 왜 저따구인지.........ㅠㅠㅠ

사실 고민하다가 ....걍 읽을수 있는 코드를 짜자! 라고 생각해서 길지만....ㅋㅋㅋ

param분모 param분자... 좋은 네이밍을 찾습니다..ㅠ

메인 에서는 문제와 같이 X,W를 썻구요

실제 weightMin에서는 분자,분모역할이기에 영알못이지만 Denominator, Numerator을 썻습니다.



-후기: 완벽한 코드가 아님 문제자와 의도를 알지만 내맘대로짬 하지만 Hackerrank 에서는 그냥 맞다고 처리해줌!ㅋㅋㅋ(왜냐? Hackerank는 오류를 범할 input을 만들지 않으니깐!) 오늘도 허점이 있는 개발을 짜버렷네요 ㅋㅋㅋ

--문제에 대한 질문: 처음 입력받는 N 은 왜 입력 받는걸까요?..... 분자를 입력받다가 저 숫자를 넘어서면 분모입력받은걸로 처리하려고 하나요? 이건 프로그램에 문제는 아니지만 음...글쎄올시다! 아래 체점하는 Input에는 분명 엔터가! 있는데!!! 음 모르겠습니다 ㅋㅋㅋ


--아래 Congratulations 는 참 보기 좋습니다 ㅋㅋㅋㅋ

Congratulations
You solved this challenge. Would you like to challenge your friends?
Input (stdin)Download
30
10 40 30 50 20 10 40 30 50 20 1 2 3 4 5 6 7 8 9 10 20 10 40 30 50 20 10 40 30 50
1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 10 40 30 50 20 10 40 30 50 20
Expected OutputDownload
26.1
Compiler Message
Success






*나만의 뻘짓;;고백

첫번째 뻘짓 입니다;;

중간에 count 보시면 ++ 시키죠...

문제를 제대로 읽지 않으면 이렇게 됩니다 ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ

신기하게 Run Code 는 정상 통과인데 Submit Code에서 3,4번째 체점만 안되는겁니다 ㅋㅋㅋ

그저 운이좋게 1,2는 통과한거더군요 ㅋㅋㅋ


이 문제의 가장 큰팁? 은 분자=분자*분모! 인거같네요 ㅋㅋ


그럼 이만!!!!!!!!!!!!!!!!!!!!!!









생각해보니깐 Hackerrank의 기능? 사용법? 간략하게 설명을 안했네요 ㅋㅋ 다음글은 Hackerrank의 간략한 소개와 사용법 올릴게요 ㅋㅋㅋ



(출처:https://www.hackerrank.com/challenges/s10-weighted-mean/problem)

반응형
반응형


아무힘이 안나는 오후 3시 직장동료들과 콧구녕에 바람이나 쐬러나가자 해서 나왔는데 팥빙수 카페가 보이더라구요.


수제 팥하고 우유얼음..진짜마싯엇어요..


인테리어까지 깔끔한 카페에요.!


귀여운 쿠폰도장까지

심지어 10개다모으면 커피가 아니라 빙수!!!
10개다모을래여ㅜㅡㅜ완전마싯


근처사시면 가보시면 좋을 것 같아요!!ㅎ



행복이 가득한 집(후암동 단팥죽 팥빙수)

서울 용산구 후암로 23 1층





반응형
반응형



코딩놀이! 10 Days of Statistics(HackerRank)





(남편의덕업일체)

오늘부터 HackerRank의 문제를 조금씩 풀어보려 합니다.


도전1: 10 Days of Statistics


(출처: https://www.hackerrank.com/domains/tutorials/10-days-of-statistics?filters%5Bstatus%5D%5B%5D=unsolved&badge_type=10-days-of-statistics)



언어는....C#? JAVA? PHP? C++? Python?으로 풀어볼 생각입니당 물론....코딩스텐다드는 없지만....

막무가내 코딩으로 하나하나 배워나갈예정입니당 ㅋㅋㅋㅋ



Curriculum 소개.



와우... 이렇게 보니깐 정말 많네요ㅋㅋㅋㅋ


하루 1~3개 정도 되는 내용이니깐...음...

저는 하루1개를 목표로!! 26일?정도 걸리겠네요 ㅋㅋㅋ

11월이 끝나기 전에 모두 푸는걸로 목표를 잡겠습니다..

물론, 난이도 Easy의 문제지만 저는 영알못! 이기때문에...(핑계)




아자아자 화이팅!









반응형
반응형
오늘은 제가 제일 좋아하는 유투버 김포프님을 만나고 왔습니다♥

홍대 입구역 4번 출구 오분거리?! 한빛미디어 에서 진행됐어요 ㅋㅋㅋ


리더스홀 발견!.!
오르막길이 엄청납니다.....ㅠㅠ
아내는 여기 왜왔는지 아직도 잘 모르네요 ㅋㅋㅋㅋ



포프님 입장전 이 강연에대한 유투브 를 다같이 시청중입니다 ㅎㅎ 포프님 만날 생각에 너무 떨려서 심장이 바운스!!

강의실 입장!! 역시나 ㅋㅋㅋㅋㅋ 약을 파는 느낌은 저뿐인가요 ㅋㅋㅋ 아주 강력하고 달콤하고 몸에좋은 약이네요
POCU 뽀큐!!(발음조심..) ㅋㅋ 강연마지막쯤 포큐 아카데미에 대한 설명도 있었어요


초반에는 프로그래밍 입문자에 대한 예기와 알고리즘이란의 주제로 진행되고

중후반부 부터 코드몽키와 전문엔지니어 일류!가 되는법에 대해 포프님 생각을 들을수 있었습니당 ㅋㅋㅋ

강의는 분명 초급자 입문자를 위한 교육 이였는데  역시나!!!! 팬분들 실무자들 등 질문 수준이 정말 다양 했어요 ㅎㅎㅎ


질문도 정말 많은 분들이 해주셨는데요

가장 기억에 남는 질문은 어떤 여자분이셨는데

게임회사 공동 대표직에 있고 외국으로 진출해서 법인을 만들고 인큐베이터에 들어갈려고 하는데 꼭 외국 법인이 필요한가요? 였습니다.

포프: 엑셀레이터 기업이 되려면 굳이 외국에 나가서 비싸게 법인을 만들고 그럴필요없다. 한국에서 키워서 인정받고 넘어가도 늦지않고 투자회사들이 많으니 한번 알아봐랑

이였습니다. 저도 꿈꾸는 대화 같아서 참 좋터군요 ㅎㅎㅎ



제 질문은! 간략한 제소개 후, Html5 wasm 에 관한거 였습니다. 사실 무엇을 어떻게 해 나아갈까요?가 아닌 기술을 통해 웹브라우저 상에 도는 게임이 언제쯤 시장에서 인정받을수 있을까요?
였는데 너무 떨리는 나머지....ㅋㅋㅋ

포프: 재미있네요. 페이먼트 시스템 2년하고 웹,게임 이 재미있어서 옮기다니요ㅋㅋ 이미 기술을 나왔고 실제로 만들어지고 있어요. 한번 재미있게 해보세요.

뭔가 속시원하고 좋았습니다ㅋㅋㅋㅋ

사실.....이직할때 포프님의 이직결정표 동영상 보고 많이 도움 됬거든요 ㅎㅎ
혹시나 이직 고민중 이신 분은 아래 동영상보시면 도움이 되실거예요 ㅎㅎ
포프tv 이직결정표



대한민국 최고 개발자를 꿈꾸며 오늘도 개발덕질 완료 했습니다 ㅋㅋㅋㅋ

다음에는 제가 생각하는 wasm에 대해서 올려볼게요 ㅎㅎ

아자아자 화이팅!!
- 여전히 우리 이쁜 마눌님은 이곳에 왜 와서 일 하고 사진찍어주고 덕후구경 하는지 모르겠다함 ㅠㅠ


반응형

+ Recent posts