Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

All Delphi Programers - Re-useable code

Status
Not open for further replies.

Darookpark

Technical User
Jul 16, 2003
3
AU
I am entering a programming competition soon. You are allowed to enter the competition with pre written code. Re-useable pieces of code that you might use. Most of the competition questions use strings in the questions. Could everyone please send me pieces of code they have in there library’s that i may be able to use.
Thanks Heaps

 
If you can not write a piece of code why do you enter a contest?

Steven van Els
SAvanEls@cq-link.sr
 
I can write code. I was just looking for other peoples pieces of code. I dont have my own collection of re useable code and was wondering if people could help me.
 
If you can program you can make such code yourself easily.

I doubt you're allowed to enter the competition with code written by others, so anything we give you you either couldn't use or you'd have to pass it of as your own which is at the very least unethical.
 
by reusable code in delphi I think you mean components or some general library.

there are many free components and libraries on the net like at torry.net.
most of them contain source.

you can have a look at the source and get some ideas.

but please dont copy other peoples work and pass of it as your own. atleast give credit where it is due.

good luck with your codeing the competition
 
If you expect everyone on this list to send you every piece of re-usable code they have on their hard drive, then you are in for a lot of reading.

Perhaps you could post a link to the contest questions, so we can get some idea of what sort of problems you are trying to solve.
 
Maybe we can enter the contest and win something!

Steven van Els
SAvanEls@cq-link.sr
 
It's a high school contest. The questions - looking at previous years normally have questions involving testing strings or numbers. So just things like spliting strings reversing them. Here is last years comp.

Task 1 - Anagram
Description
An anagram is a word or phrase obtained by rearranging the letters of another word or phrase.
For example Neo is an anagram of One. And Tom Marvolo Riddle is an anagram of I am Lord Voldemort

Write a program which, given two strings string1 and string2, prints:


"string1" is an anagram of "string2"


if they are anagrams, and

"string1" is NOT an anagram of "string2"


otherwise.
Test Data
String 1 String 2
One Neo
Eat, Fish A he fist!
Howard! Sorry?
Tom Marvolo Riddle I am Lord Voldemort
Sheep eat feed eeeee Shp at fd
Sheep eat feed eeee Shp at fd

Sample Output

"One" is an anagram of "Neo"

"Eat, Fish" is an anagram of "A he fist!"

"Howard!" is NOT an anagram of "Sorry?"


Constraints
Ignore punctuation, digits, and all other non-letters. Ignore the case of letters (as in the examples above). You may assume each string is no longer than 80 characters.




--------------------------------------------------------------------------------

Task 2 - Factor Pairs
Description
A factor pair of a whole number is a pair of whole numbers which equal the initial number when multiplied together. All numbers have a factor pair which is one and themself (eg 7 = 7 * 1) - we call this the trivial factor pair.

Write a program which, given a whole number, prints a factor pair for it. Only print the trivial factor pair if there are no other factor pairs. If the number has more than one non-trivial factor pair you may print whichever you wish.

The format of your output is to match the examples below. Print the smaller of the numbers in the factor pair first, then the larger one.

Test Data
Find factor pairs for the numbers below: 7
48
100
561
17947
25849
197203

Sample Output

7 = 1 * 7

144 = 6 * 24


Constraints
You may assume each input is a whole number greater than 1 and less than 64000.




--------------------------------------------------------------------------------

Task 3 - Seventeen
Description
Write a program which, given a list of numbers returns all ways of combining some or all of the numbers using plus and minus to produce 17.

For example 1,3,3,7,9 can be combined as follows


17 = 1 + 7 + 9

17 = 1 + 3 - 3 + 7 + 9

17 = 1 - 3 + 3 + 7 + 9


Only consider cases where the numbers are in the same order they appear in the input list. (eg "17 = 7 + 9 + 1" would not be valid in the example above).

You may not use a number more times than it appears in the input list. (e.g. in the example above 3 can be used zero, one or two times, and the other numbers can only be used at most once).

Test Data
1,3,3,7,9
1,1,1,1
17,14,3
17,14,3,13,4
1,3,5,7,9,11,13,2

Output
If there is no way of combining the input numbers to produce 17 print "No solution possible". Otherwise match the format of the output given in the example above.
Where there is more than one way of combining the numbers to produce 17 you may return them in whichever order you wish.

Constraints
You may assume the input is at most 20 numbers. You may assume all the input numbers are whole numbers and are not negative.




--------------------------------------------------------------------------------

Task 4 - Buckets
Description
If you had a 3 litre bucket called A, and a 5 litre bucket called B, and a water tap, you could measure 4 litres with the following procedure:


fill B from the tap

tip 3 into A

empty A

tip 2 into A

fill B from the tap

tip 1 into A

Done!


Write a program which, given the size of A, the size of B, and the desired amount to measure, returns a series of lines describing how to measure it.

Test Data
Size of A (litres) Size of B (litres) Amount to measure
3 5 4
3 5 2
11 5 3
10 5 3

Output
If there is no way of producing the desired amount print "No solution possible". Otherwise match the format of the output in the example above.
Hint: You may assume that if there is a solution it can be obtained by repreatedly pouring one container into the other.





--------------------------------------------------------------------------------

Task 5 - Round Robin
Description
n teams are to play each other in a competition. In each round each team plays exactly one other team. We wish to have as few rounds as possible.

Write a program which, given an even number n, produces a "draw table" showing which team plays which team in each round. It is to take the minimum possible number of rounds. If more than one such draw table is possible your program may return whichever you wish.

For example here is an 4 player draw table


A B C D

A 1 2 3

B 1 3 2

C 2 3 1

D 3 2 1


The letters represent the four teams, the numbers say which round each pair of teams is playing.

Test Data
Number of teams
4
6
8
10

Output
Match the format of the output in the example above.
Where there is more than one "draw table" you may return whichever you wish.

Constraints
You may assume the input is even.




--------------------------------------------------------------------------------

Task 6 - Pig
Description
You wish to alter the words in a sentence. You use the following procedure: If the word starts with a vowel add the letters "tay" to the end of the word. Otherwise move the first letter of the word to the end of the word, and then add "ay" to the end of this new word.

Write a program which, given a string of words, alters each word in accordance with the above procedure. Assume each "word" starts and finishes with a space character or is at the start or the end of the string.

Example
Here is an example of an altered sentance:

I like nix aeroplane Jelly


becomes

Itay ikelay ixnay, aeroplanetay Ellyjay.


Test Data
Phrase to encode
I like nix aeroplane jelly
You have to see it for yourself
Are you ready
Read my lips

Output
Match the format of the output in the example above. Ignore punctuation. If a word starts with a capital letter in the input phrase, then the corresponding word in the output phrase must also. If the first letter of the original word is uppercase convert it to lowercase when you move it UNLESS every letter in the original word is uppercase.
Constraints
You may assume the input is less than 80 characters long.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top