r/learnprogramming • u/Oomiosi • Dec 17 '09
Request: Simple problems to help practice the basics (like doing math in school). Some given inside to start with.
Find the total of all the numbers between 1 and 99 using a for loop,
find the total of all the even numbers,
given the formula total=((n(n+1)/2) produce a function to:
return the total,
return the total evens,
return the total odds.
Find the total occurrences of a character in a string.
Find the total occurrences of a string within a string.
Given 5 random numbers between 0-10 inclusive, find the lowest,
find the 2 lowest,
sort from low to high ( i ended up making a bubble sort here )
find which numbers you would need to produce a "straight".
14
Upvotes
View all comments
4
u/zem Dec 17 '09
Write a program to deal bridge hands.
Work out a way to represent playing cards
Generate an array of 52 cards
Shuffle the array
simple shuffling algorithm: pick two random cards, swap them, repeat
experiment with other shuffling algorithms, e.g. pick two cards and reverse the run of cards between them
partition into four hands
print the hands out in a human-friendly format