#include #include #include #include #include char *PAIRS[] = { "A ROLLING STONE","GATHERS NO MOSS", "HISTORY","REPEATS ITSELF", "A FIVE-POUND NOTE","HAS NO EFFECT UPON A SIX-PENNY SLOT MACHINE", "THE COCK CROWS, BUT THE HEN","LAYS THE EGGS", "A BUTTERFLY","LIVES LONG ENOUGH", "A CIVIL SERVANT","MUST NOT BECOME AN UNCIVIL MASTER", "ONE DIVORCE","COSTS MORE THAN FIFTY MARRIAGES", "THE CRUNCHING OF A MAN'S TOAST","IS LOUDER THAN GOD'S OWN THUNDER", "THE FIRE THAT MELTS LEAD","TEMPERS STEEL", "NO INK","IS AS RED AS BLOOD", "APPETITE","WAS DISCOVERED BEFORE VITAMINS", "IF IT ISN'T ONE THING IT","IS ANOTHER", "HE WHO LIVES BY THE SWORD","SHALL DIE BY THE SWORD", "APRIL","IS THE CRUELEST MONTH", "MARCH COMES IN LIKE A LION AND","GOES OUT LIKE A LAMB", "FATHER","KNOWS BEST", "A JACK OF ALL TRADES","IS MASTER OF NONE", "NATURE","ABHORS A VACUUM", "EVERY MAN","HAS A PRICE", "ANYTHING","GOES", "ALL'S WELL THAT","ENDS WELL", "THE EXCEPTION","PROVES THE RULE", "CONSISTENCY","IS THE LAST REFUGE OF THE UNIMAGINATIVE", "A JOB WELL DONE","NEVER NEEDS REDOING", "DRINK","IS THE CURSE OF THE WORKING CLASSES", "A ROSE BY ANY OTHER NAME","WOULD SMELL AS SWEET", "A GOOD WOMAN","IS MORE PRECIOUS THAN RUBIES", "A GOOD NAME","IS BETTER THAN GREAT WEALTH", "THE QUALITY OF MERCY","IS NOT STRAINED", "A WORD TO THE WISE","IS SUFFICIENT", "THE GRASS","IS ALWAYS GREENER ON THE OTHER SIDE OF THE FENCE", "FAITH","MOVES MOUNTAINS", "WAR","IS HELL", "THE PRICE OF FREEDOM","IS ETERNAL VIGILANCE", "SOMETHING THERE IS THAT","DOESN'T LOVE A WALL", "IT'S AN ILL WIND THAT","BLOWS NO GOOD", "A PLUMP BRIDE","MAKES A FAT WIFE", "LIFE","IS JUST A BOWL OF CHERRIES", "A PICTURE","IS WORTH A THOUSAND WORDS", "ANYTHING WORTH DOING","IS WORTH DOING WELL", "PATRIOTISM","IS THE LAST RESORT OF THE SCOUNDREL", "IN THE COUNTRY OF THE BLIND THE ONE-EYED MAN","IS KING", "THE LION","IS KING OF THE JUNGLE", "IN THE BEGINNING GOD","CREATED THE HEAVEN AND THE EARTH", "WEDLOCK","IS A PADLOCK", "A HAUGHTY SPIRIT","GOES BEFORE DESTRUCTION", "THE FOOLISHNESS OF GOD","IS WISER THAN MEN", "A MERRY HEART","DOETH GOOD LIKE A MEDICINE", "A WISE SON","MAKES A GLAD FATHER", "A SOUND HEART","IS THE LIFE OF THE FLESH", "RIGHTEOUSNESS","EXALTS A NATION", "A SOFT ANSWER","TURNS AWAY WRATH", "WINE","IS A MOCKER", "HONOR","IS NOT SEEMLY FOR A FOOL", "THE WRINGING OF THE NOSE","BRINGS FORTH BLOOD", "CALAMITY","IS VIRTUE'S OPPORTUNITY", "HE WHO FORESEES CALAMITY","SUFFERS THEM TWICE OVER", "SEEING","IS BELIEVING", "THE DEVIL","FINDS WORK FOR IDLE HANDS", "AN IDLE MIND","IS THE DEVIL'S WORKSHOP", "BAD BREATH","IS BETTER THAN NO BREATH AT ALL", "MONEY","ISN'T EVERYTHING", "ANYBODY WHO HATES DOGS AND CHILDREN","CAN'T BE ALL BAD", "ONE","CANNOT CHEAT AN HONEST MAN", "IMITATION","IS THE SINCEREST FORM OF FLATTERY", "EXPERIENCE","IS THE BEST TEACHER", "A TURNABOUT","IS FAIR PLAY", "IT'S A BIRD, IT'S A PLANE, IT","IS SUPERMAN", "EXTREMISM IN THE DEFENSE OF LIBERTY","IS NO VICE", "A FOOL","RUSHES IN WHERE ANGELS FEAR TO TREAD", "MY CUP","RUNNETH OVER", "A CRIMINAL","ALWAYS RETURNS TO THE SCENE OF THE CRIME", "EARLY TO BED, EARLY TO RISE","MAKES A MAN HEALTHY, WEALTHY, AND WISE", "TO ERR IS HUMAN, TO FORGIVE","IS DIVINE", "THE GOODNESS OF THE LORD","LEADS A MAN TO REPENTANCE", "A CHAIN","IS ONLY AS STRONG AS THE WEAKEST LINK", "TWO IS COMPANY BUT THREE","IS A CROWD", "CURIOSITY","KILLS THE CAT", "WHAT THIS COUNTRY NEEDS","IS A GOOD FIVE-CENT CIGAR", "A CHILD","SHOULD BE SEEN AND NOT HEARD", "CANDY","IS DANDY BUT LIQUOR IS QUICKER", "AN OLD SOLDIER","NEVER DIES", "THE DOG","IS MAN'S BEST FRIEND", "IGNORANCE OF THE LAW","IS NO EXCUSE", "MISERY","LOVES COMPANY", "POLITICS","MAKES STRANGE BEDFELLOWS", "ONE BAD APPLE","SPOILS THE BARREL", "PRIDE","GOES BEFORE A FALL", "A WOMAN'S PLACE","IS IN THE HOME", "THE FAMILY THAT PRAYS TOGETHER","STAYS TOGETHER", "HE WHO FIGHTS AND RUNS AWAY","LIVES TO FIGHT ANOTHER DAY", "CRIME","DOES NOT PAY", "ALL WORK AND NO PLAY","MAKES JACK A DULL BOY", "A PUBLIC OFFICE","IS A PUBLIC TRUST", "BREVITY","IS THE SOUL OF WIT", "THE HAND","IS QUICKER THAN THE EYE", "POSSESSION","IS NINE-TENTHS OF THE LAW", "HALF A LOAF","IS BETTER THAN NONE", "MAN","CANNOT LIVE BY BREAD ALONE", "THE WORST","IS YET TO COME", "A HOUSE DIVIDED AGAINST ITSELF","CANNOT STAND", "THE ONLY GOOD INDIAN","IS A DEAD INDIAN", "ONCE BITTEN","IS TWICE SHY", "A CAT","HAS NINE LIVES", "AN ELEPHANT","NEVER FORGETS", "HELL","HATH NO FURY LIKE A WOMAN SCORNED", "THE PROOF OF THE PUDDING","IS IN THE EATING", "MUSIC","HATH CHARMS TO SOOTH THE SAVAGE BREAST", "NO MAN","IS AN ISLAND", "HE WHO LAUGHS LAST","LAUGHS BEST", "THE PEN","IS MIGHTIER THAN THE SWORD", "TIME","HEALS ALL WOUNDS", "A LITTLE LEARNING","IS A DANGEROUS THING", "CLOTHING","MAKES THE MAN", "NO NEWS","IS GOOD NEWS", "BAD NEWS","TRAVELS FAST", "LOVE","MAKES THE WORLD GO 'ROUND", "A RULE","IS MADE TO BE BROKEN", "STILL WATER","RUNS DEEP", "IN SPRING A YOUNG MAN'S FANCY","TURNS TO THOUGHTS OF LOVE", "LIGHTNING","NEVER STRIKES TWICE IN THE SAME PLACE", "HOME","IS WHERE THE HEART IS", "HOPE","SPRINGS ETERNAL", "VARIETY","IS THE SPICE OF LIFE", "WELL BEGUN","IS HALF DONE", "WHAT'S SAUCE FOR THE GOOSE","IS SAUCE FOR THE GANDER", "ONE MAN'S MEAT","IS ANOTHER MAN'S POISON", "THE NIGHT","IS ALWAYS DARKEST BEFORE THE DAWN", "HASTE","MAKES WASTE", "SLOW AND STEADY","WINS THE RACE", "THE FEAR OF THE LORD","IS THE BEGINNING OF WISDOM", "THE EARLY BIRD","GETS THE WORM", "BLOOD","IS THICKER THAN WATER", "PRACTICE","MAKES PERFECT", "AN OUNCE OF PREVENTION","IS WORTH A POUND OF CURE", "FOREWARNED","IS FOREARMED", "IGNORANCE","IS BLISS", "FACT","IS STRANGER THAN FICTION", "TRUTH","IS BEAUTY", "RELIGION","IS THE OPIATE OF THE MASSES", "OPPORTUNITY","KNOCKS BUT ONCE", "GOD","HELPS THOSE WHO HELP THEMSELVES", "CHARITY","BEGINS AT HOME", "ONE GOOD TURN","DESERVES ANOTHER", "A WOMAN'S WORK","IS NEVER DONE", "THE ROAD TO HELL","IS PAVED WITH GOOD INTENTIONS", "FAMILIARITY","BREEDS CONTEMPT", "A FAINT HEART","NEVER WON A FAIR LADY", "HONESTY","IS THE BEST POLICY", "MIGHT","MAKES RIGHT", "EVERY CLOUD","HAS A SILVER LINING", "SOMETHING","IS ROTTEN IN THE STATE OF DENMARK", "ALL MANKIND","LOVES A LOVER", "THE SUN","NEVER SETS ON THE BRITISH EMPIRE", "HAPPINESS","IS A WARM PUPPY-DOG", "ABSENCE","MAKES THE HEART GROW FONDER", "CLEANLINESS","IS NEXT TO GODLINESS", "A STITCH IN TIME","SAVES NINE", "A FRIEND IN NEED","IS A FRIEND INDEED", "NECESSITY","IS THE MOTHER OF INVENTION", "A MISS","IS AS GOOD AS A MILE", "ALL THAT GLITTERS","IS NOT GOLD", "A BIRD IN THE HAND","IS WORTH TWO IN THE BUSH", "A WATCHED POT","IS LONG IN BOILING", "VIRTUE","IS ITS OWN REWARD", "AN APPLE A DAY","KEEPS THE DOCTOR AWAY", "DISCRETION","IS THE BETTER PART OF VALOR", "A THING OF BEAUTY","IS A JOY FOREVER", "LOVE OF MONEY","IS THE ROOT OF ALL EVIL", "WHAT GOES UP","MUST COME DOWN", "TOO MANY COOKS","SPOILS THE BROTH", "A PENNY SAVED","IS A PENNY EARNED", "A DIAMOND","IS A GIRL'S BEST FRIEND", "HE WHO HESITATES","IS LOST", "A NEW BROOM","SWEEPS CLEAN", "SILENCE","IS GOLDEN", "BEAUTY","IS IN THE EYE OF THE BEHOLDER", "CONSCIENCE","DOTH MAKE COWARDS OF US ALL", "DISTANCE","LENDS ENCHANTMENT TO THE VIEW", "FRAILTY, THY NAME","IS WOMAN", "IT'S A LONG LANE THAT","HAS NO TURNING", "NONE BUT THE BRAVE","DESERVES THE FAIR", "PROCRASTINATION","IS THE THIEF OF TIME", "TIME AND TIDE","WAITS FOR NO MAN", "TWO HEADS","IS BETTER THAN ONE" }; typedef struct { int left, right; } Proverb; void mk_proverbs(char **src, int src_len, Proverb *dest) { int dest_idx = 0; for (int left = 0; left < src_len; left += 2) { for (int right = 1; right < src_len; right += 2) { if (right == left + 1) continue; /* ignore true wisdom */ dest[dest_idx].left = left; dest[dest_idx].right = right; dest_idx++; } } } void shuffle(Proverb *arr, int size) { for (int i = size - 1; i > 0; i--) { int j = random() % (i + 1); Proverb temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } void lowercase(char *dest, char *src, int skip) { while ( (*dest++ = skip-- < 1 ? tolower(*src++) : *src++)) ; } void print(char **src, Proverb *proverbs, int slice_len) { for (int idx = 0; idx < slice_len; ++idx) { Proverb p = proverbs[idx]; char left[strlen(src[p.left])+1]; lowercase(left, src[p.left], 1); char right[strlen(src[p.right])+1]; lowercase(right, src[p.right], 0); printf("%s %s.\n", left, right); } } int main(int argc, char **argv) { srandom(time(0)); int pairs_len = sizeof(PAIRS) / sizeof(PAIRS[0]); int templates_len = pairs_len / 2; int proverbs_len = templates_len * (templates_len - 1); /* max possible */ int n = atoi(argc > 1 ? argv[1] : "1"); if (n < 1 ) n = 1; if (n > proverbs_len) n = proverbs_len; Proverb proverbs[proverbs_len]; mk_proverbs(PAIRS, pairs_len, proverbs); shuffle(proverbs, proverbs_len); print(PAIRS, proverbs, n); }