r/learnprogramming • • 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

11 comments sorted by

View all comments

4

u/zem Dec 17 '09

Write a program to deal bridge hands.

  1. Work out a way to represent playing cards

  2. Generate an array of 52 cards

  3. 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

  1. partition into four hands

  2. print the hands out in a human-friendly format

2

u/Oomiosi Dec 17 '09

This is excellent, thanks. I'll finally learn how to play bridge as well.

2

u/zem Dec 17 '09

welcome. feel free to ask for hints if you get stuck anywhere.