[GO] [Out of 100 points] I thought about a coding test for programming school graduates [Ruby]

Introduction

My name is yuki. Thanks to DMMWEBCAMP, I am now working as a WEB engineer, gathering my friends to develop services, tutoring programming, and enjoying my engineer life every day.

We also provide support and error questions for those who are aiming from inexperienced, so if you are interested, please contact DM.

This time, at some point, I was asked, "What would you give a coding test to a graduate of a programming school?", So I would like to write my answer at that time (about 6 months ago). ..

Nowadays, I want to listen to ** sort **, but I will share it as a memory of those days. If you have just graduated from learning Ruby, please try it. I was the same graduate when I made it.

problem

It is a perfect score of 100 points.

【Problem statement】
You are a student studying programming, and you study a lot every day.
Assume today is the first day of the month.
As a hard worker, you decided to set rules on how to study programming this month.
Please answer the following questions after observing the conditions.

【conditions】
・ Write and submit the code within 90 minutes
・ Solve without looking at the Internet or the notes you have learned so far
・ As the problem statement says, today*November 1, 2020*To solve by assuming
* You can use it according to the month you read this article.

・ Because it is a point addition method, try to write the code as much as possible even if you do not understand
* At that time, enter the part you did not understand as a comment

【problem】
(1) Output the last day of this month using the date object.
* However, require'date'You can use it by writing.

(2) You decided to solve one problem every day while you were studying.
In addition, I decided to solve 2 questions on days with 4 on the date and 3 questions on prime day.
If you start learning from day one, how many questions will you be able to solve this month?
* However, the Prime class cannot be used.

(3) Please output this month's calendar in the following format.
https://drive.google.com/file/d/1_Km62H6c1WTzv1rWz4NfnwgVXDBC9r2c/view?usp=sharing

Answers, explanations and evaluation criteria

answer.rb


#60 points or more out of 100 points pass

# (1)Answer example
require 'date'
year = Date.today.year
month = Date.today.mon
lastday = Date.new(year, month , -1).day 
puts "(1)answer:"+"#{lastday}"

=begin
    (1)Evaluation criteria perfect score [10 points]
* Year and month are not required, and no points will be deducted even if the last day is directly entered as 2020 5.
* However, if there is a tie candidate.year or.Evaluate those who write reusable code such as mon
    1.Date.new is made [5 points]
    2.The answer is 28,29,30,Any of 31 corresponds to the last day of this month [5 points]
=end

# (2)Answer example
#The number of solved problems is being initialized.
count = 0

#This is a method for determining prime numbers.#Call with 1.
def prime?(num)
  return false if num == 1 
  (2..num).each do |i|
    if num % i == 0 && num == i
      return true
    elsif num % i == 0
      return false
    end
  end
end

#Iterates from the first day to the last day.
(1..lastday).to_a.each do |date|
    #This is the process when the number 4 is included in the date.
  if date.to_s.split("").include?("4")
    count += 2
    #This is the process when one day is a prime number.
  elsif prime?(date)
    count += 3
  else
    count += 1
  end
end
puts "(2)answer:"+"#{count}"

=begin
(2)Evaluation criteria perfect score [30 points]
    1.Primality test code can be written [10 points]
* If all prime numbers are written out, [5 points]
    2.I can write the code to judge the day when 4 is attached(All can be written out) [5 points]
    3.I can write a code to solve one question every day using repetition [5 points]
    4.Variables that add points can be initialized and added [5 points]
    5.There is an answer [5 points]
=end

# (3)About the problem
puts "(3)answer:\n" 
week = ["Su","Mo","Tu","We","Th","Fr","Sa"]
puts week.join(" ") 

#The day of the week on the first day of each month is quantified.
day = Date.new(year,month,1).wday
#Day of the week+Half-width space for single-digit date=The first week is right-justified by multiplying by 3 half-width spaces.
print "   " * day

(1..lastday).each do |date|
  print date.to_s.rjust(2) + " "
  day += 1
  if day % 7 == 0
    puts "\n"
  end
end

if day % 7 != 0
  print "\n"
end

=begin
(3)Evaluation criteria perfect score [50 points]
    1.The output of the day of the week on the first line is possible [10 points]
    2.The date is output [5 points]
    3.I devised a way to output with a half-width space between each day [5 points]
      ※"1 ","2 "If you enter manually like [5 points]
    4.It is divided into 7 days [10 points]
* If you use puts a lot without repeating or using line breaks, [5 points]
    5.When outputting a 1-digit date, a space can be inserted at the beginning [5 points]
    6.The first week is right-justified [5 points]
    7.The last week is left-justified [5 points]
    8.The answers are correct [5 points]
=end

=begin
(Other)Perfect score [10 points]
From the viewpoint of readability of the answer code, consideration for the reader, processing method, process to be derived, etc.
The grader should add up to 10 points along with the reason for evaluation.
=end

Summary

I thought it was nostalgic. Of course, I had some thoughts about why I had such a problem, but I forgot it after a long time. Regardless of the good or bad of the coding test, I would like to look back on those days and think about what kind of test to make now.

Please contact me if you can solve it (◞´ • ௰ • `) ◞

Recommended Posts

[Out of 100 points] I thought about a coding test for programming school graduates [Ruby]
VS Code plugin recommended for programming school students
Introduction to Programming for College Students: Introduction
Introduction to Programming for College Students: Variables
[Out of 100 points] I thought about a coding test for programming school graduates [Ruby]
I thought about the best way to create a ValueObject in Ruby
Awareness of object-oriented programming for half a year
I made a Docker image of SDAPS for Japanese
[RSpec] I wrote a test for uploading a profile image.
I learned about the existence of a gemspec file
I have a question about keyboard input of numbers