For the last day of the semester, I decided to have some fun with my students and I showed them Code Golf... poor guys, they're addicted now.
The goal was to compete against the other students to solve those problems with what would be very usual rules for you. They had to use C# (because it's the language they are learning right now) so please do the same.
The length of each method must be the shortest including the method signature!
Tasks
Write functions that do the following:
- Input:
string
,int
.
Output:string
.
Description: the output string repeats the input string as many times as the input int.
Example:a("Hi", 5)
returns"HiHiHiHiHi"
. - Input:
int
.
Output:int
.
Description: the output is the quantity of prime numbers lower or equal to the input.
Example:b(10)
returns4
.b(100)
returns25
. - Input:
object[]
.
Output:object[]
.
Description: returns the input without thenull
values.
Example:c(new object[] { "Hello", 42, null, new Program(), null, null, false })
returns an array containing[Hello, 42, Program instance, false]
. - Input:
int
.
Output:int
.
Description: the output is the sum of all the integers from 1 to int input.
Example:d(4)
returns10
(because 1 + 2 + 3 + 4 = 10). - Input:
char
.
Output:char
.
Description: the output is the input char with the other case. non-letters don't need to be checked.
Example:e('a')
returns'A'
.e('A')
returns'a'
.e('-')
may have unexpected results. - Input:
string
,int
.
Output:bool
.
Description: true if and only if the length of the input string is a multiple of the input int.
Example:f("Programmer", 5)
returnstrue
.f("Programming", 5)
returnsfalse
. - Input:
string
.
Output:boolean
.
Description: true if and only if the input string is a palindrome.
Example:g("level")
returnstrue
.g('label')
returnsfalse
.
Their solutions
I took the best of each task that they presented to me.
- 64
- 135
- 105
- 30
- 71
- 45
- 83
Total: 533
(I will write their complete answers when the challenge is over).
Your rules
- Use C# to be evaluated equally to my students.
- Write each task on a separate line with the method signature (
string a(string s,int i)
), it is part of the answer. - Write your best score for each task so we know what score matches what task.
- Write the sum of all task scores in the title of your answer.
- The shortest overall score wins, but honorary mention may be awarded to the lowest score of a given task.
Note: It is not impossible that many of you have the same answer, my students did without cheating. Please consider that someont who has the same answer as you may simply have taken the same path and did not steal your idea.
FAQ:
- Why should people here use C#? It's not the best language for code golfing !
I know, but I would like to have some examples from pros like you to show them what a real golfer would do in their shoes.
294
Yeee - Oh, post closed... \$\endgroup\$