6 Programming Exercises - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › 6 Programming Exercises (3169 Views)
| 6 Programming Exercises by Kodejuice(op): 5:25pm On Jan 13, 2016 |
1. String length Language: Any Language Determine the length of a string without using the default function provided by the programming language you're using.
2. Closed Parenthesis Language: Any Language Write a function that takes a string containing opened and closed brackets, your function should be able to determined if the brackets are well placed, if there are not then fix it and return the fixed version.
3. Vowel count Language: Any Language Count the number of vowels that appear in a string and also return the counted vowels.
4. argSwitch Language: Any Language Create a function named "argSwitch", this function will take 2 arguments and return each of the argument one after the other, when the function is called, the same argument should not be returned twice
5. Color validate Language: JavaScript Create a function named "isValidColor", this function would test if the string passed to it is a valid color or not. Rule: Do not use any list of valid colors to validate.
6. String replace Language: Any Language Create a function that replaces strings without the use of the default function provided by the language you're using. No RegExp support. But if you feel you're a geek, include RegExp replacing.
Post your solutions. |
| Re: 6 Programming Exercises by Fulaman198(m): 7:22pm On Jan 13, 2016 |
Nice exercises, I'll take a look at these soon |
| Re: 6 Programming Exercises by ChinenyeN(m): 7:04am On Jan 14, 2016*. Modified: 2:50pm On Jan 14, 2016 |
6. String Replace Language: C
|
| Re: 6 Programming Exercises by Fulaman198(m): 7:32am On Jan 14, 2016*. Modified: 7:54am On Jan 14, 2016 |
Programme: VowelCount Language: Java
Below is programme output
|
| Re: 6 Programming Exercises by Fulaman198(m): 7:34am On Jan 14, 2016 |
ChinenyeN decided to add comments to his programme, it makes me feel bad. I should have done the same. I will in the future. Good programming ethics ChinenyeN |
| Re: 6 Programming Exercises by ChinenyeN(m): 8:08am On Jan 14, 2016 |
If it's any consolation, Fulaman198, I don't think your program needs any comments. It's very self-explanatory. But you are right. It's always good to make a habit of commenting one's code. I added comments to mine mostly to make it easier to read on NL, since NL's code tag doesn't come with syntax highlighting (unless there's something I don't know). |
| Re: 6 Programming Exercises by Fulaman198(m): 8:22am On Jan 14, 2016 |
ChinenyeN:You are right about that my friend. |
| Re: 6 Programming Exercises by DonSegmond(m): 12:44pm On Jan 14, 2016 |
php
|
| Re: 6 Programming Exercises by Kodejuice(op): 3:52pm On Jan 14, 2016 |
Fulaman198:You approach to solve the problem is yucky, and doesnt follow the rule completely, return the vowels! Language: JavaScript
|
| Re: 6 Programming Exercises by ChinenyeN(m): 3:56pm On Jan 14, 2016*. Modified: 4:16pm On Jan 14, 2016 |
3. Vowel Count Language: C
|
| Re: 6 Programming Exercises by robby1(m): 4:34pm On Jan 14, 2016 |
[size=14pt]Language: Scala [/size] 3. Vowel Count Solution def countVowel(word: String): String = {Result on the repl is: scala> countVowel('robert')6. String Replace Solution def stringReplace(orig: String, toReplace: String, replaceWith: String) = {Result on the repl is: scala> stringReplace('hello world', 'world', 'nairalander') |
| Re: 6 Programming Exercises by Fulaman198(m): 5:04pm On Jan 14, 2016*. Modified: 10:08pm On Jan 14, 2016 |
Kodejuice:Look at the method vowelsCounted(), that is what it's for. Java and JavaScript are different languages. I created the main class to illustrate how it works. EDIT: In case you don't know what I'm referring to, I'm talking about the method here
In Java, functions are referred to as Methods. |
| Re: 6 Programming Exercises by ChinenyeN(m): 5:32pm On Jan 14, 2016 |
1. String Length Language: C
|
| Re: 6 Programming Exercises by Nobody: 8:59pm On Jan 14, 2016*. Modified: 8:34pm On Jan 16, 2016 |
![]() string length: java import java.util.*; alternatively ... import java.util.*; many ways to kill a rat. import java.util.*; |
| Re: 6 Programming Exercises by Kodejuice(op): 10:35am On Jan 16, 2016 |
|
| Re: 6 Programming Exercises by Kodejuice(op): 10:41am On Jan 16, 2016 |
Fulaman198:You dont get, return all vowels in the passed string not just the number of vowels.
|
| Re: 6 Programming Exercises by Fulaman198(m): 6:34pm On Jan 16, 2016 |
Kodejuice:Oh ok, I didn't follow the instructions properly. Sorry about that. |
| Re: 6 Programming Exercises by Nobody: 9:09pm On Jan 16, 2016 |
Kodejuice: |
| Re: 6 Programming Exercises by Nobody: 9:09pm On Jan 16, 2016 |
.. |
| Re: 6 Programming Exercises by ChinenyeN(m): 1:08am On Jan 17, 2016 |
2. Closed Parenthesis -- I want so badly to try an implementation of this in Standard C, but I just know it will take a whole bunch of code (especially so, if I want to add some fool-proofing) and I doubt anyone would be willing to read through it all. |
| Re: 6 Programming Exercises by ChinenyeN(m): 4:48am On Jan 17, 2016*. Modified: 6:25am On Jan 17, 2016 |
Ah, whatever. I decided I'd do it anyway, complete with comments. I decided I'd go with a simpler implementation than what I originally had in mind. We can all be grateful, I guess. 2. Closed Parenthesis Language: C
|
| Re: 6 Programming Exercises by tr3y(m): 8:09pm On Jan 17, 2016 |
Nice. |
| Re: 6 Programming Exercises by Naijaepic: 10:55pm On Jan 26, 2016 |
ChinenyeN:Here is my three attempt to solve three of the exercises Language: Python
|
| Re: 6 Programming Exercises by danvery2k6(m): 12:23am On Jan 28, 2016*. Modified: 12:51am On Jan 28, 2016 |
|
| Re: 6 Programming Exercises by danvery2k6(m): 9:48am On Jan 28, 2016 |
Vowel Count
|
| Re: 6 Programming Exercises by danvery2k6(m): 10:04am On Jan 28, 2016 |
ArgSwitch
|
| Re: 6 Programming Exercises by Naijaepic: 12:47pm On Jan 28, 2016*. Modified: 6:24pm On Feb 06, 2016 |
Name: Python argSwitch function with Python
|
| Re: 6 Programming Exercises by timtoday: 2:41pm On Jan 28, 2016 |
Language: Perl - one-liner #1
to use the default function provided by Perl is like so:
# 3
# 4
# 6
All are one-liner Perl Scripts. |
| Re: 6 Programming Exercises by timtoday: 5:32pm On Jan 28, 2016 |
# 2
Used the following input (3+3), (5+2)*3), (2+2(( I might not have tested this enough though! Enjoy!!! |
| Re: 6 Programming Exercises by unphilaz(m): 6:12pm On Jan 28, 2016 |
nice thread how a problem can be solved using different programs kudos guys |
| Re: 6 Programming Exercises by Naijaepic: 5:34pm On Feb 19, 2016 |
Language Python Exercise: closedBracket Solution: This python function had been rigorous test to work on any mathematical expression irrespective of number of parenthesis in the expression and it will do the needful. Below is the python code def closedBracket(string_input): """ This function was implemented by NaijaEpic in response to online exercise on Nairaland 1. This function is name closedBracket(), it take mathematical expression, iterate over the expression to determine the number of both open and closing parenthesis, if there is unbalance number of parenthesis, the function will return a balance version of the mathematical expression 2. The function take on parameter 3. """ import unicodedata, re left_bracket = re.compile('[\u0028]') # compiling unicode of left bracket right_bracket = re.compile('[\u0029]') # compiling unicode of right bracket string_holder = [] # Declaring empty List to hold split string string_holder[:0] = string_input # Change the input string to list left_bracket = string_holder.count('\u0028') # Checking how many left bracket exist in the string_holder list right_bracket = string_holder.count('\u0029') final_string = [] # Accumulator of if left_bracket > right_bracket: # Remove some leftmost brackets or add more right brackets count = 0 while count < (left_bracket - right_bracket): final_string.append('\u0029',) # Generating number of right_bracket (i.e. '\u0029') that is need to balance the deficit count += 1 final_string = ''.join(final_string) print('False', string_input + final_string) elif left_bracket < right_bracket: # Remove the last Rightmost Brackets or add another leftmost brackets count = 0 number_right_bracket = (right_bracket - left_bracket) while count < number_right_bracket: final_string.append('\u0028',) # Generating number of left_bracket (i.e. '\u0028') that is need to balance the deficit count += 1 final_string = ''.join(final_string) print('False', final_string + string_input) else: return True closedBracket("5+((3)*2)))))" ![]()
|
| Re: 6 Programming Exercises by Sirnuel: 5:21am On Feb 22, 2016 |
. |
100 Little Programming Exercises For Beginners • . • 2 • 3 • 4
Cost Of Building An Android App For A Magazine • Buy And Sell Digital And Ecurrency In Seconds. RC 1502336 • Web Development Vs Software Development. Which Is Better In Nigeria?
; //=>Hello Nairalanders