Subscribe to MentalFloss Minutes

## Complex Logic And Matrices

So, let's say that you have some problem that involves pretty complex logic, and only two parameters. Instead of writing a bunch of if statements, you can construct an output matrix, and fetch the values that way. For an example, let's mix some paint.

We have our colors: Red, Yellow, Blue.
Red + Yellow = Orange
Red + Blue = Purple
Yellow...

## C++ Enum Flip Flop OR Junk Fields?

Disclaimer: This is probably bad code, but I came across this in trying to solve a problem, and I want to share. Feel free to offer suggestions for improvement.

`...`

## Logic Exploration

I want to talk a bit about the various ways of manipulating logic for potentially more readable code.

Let's consider a problem:

You are to test two fruits (APPLE, BANANA, LEMON, LIME) to report on them. There are two conditions:

• ...

## Big IF Or List?

Let's create a contrived example where the user has selected from an assortment of food. If the user selects a fruit, we want to say "Don't forget to eat your vegetables.", and if they select a vegetable, we'll say "Remember, an apple a day keeps the doctor away."

We might have some such enumeration:

`...`

From my experience in an academic setting, project requirements can often be poorly defined. It is up to you to take the initiative, and clarify every vague notion about the project. It's best to get it in writing via email (just like in the workplace), so that you can reference it in the event of miscommunication.

## Loops

For this post we shall consider Java, but it will apply equally well to C++.

Knowing what loop to use for a given situation is an important skill. There are many options, and picking the right one can be confusing at first.

for(type var_name = value; condition; increment)...

## I/O Redirect Tutorial

You might be interested in reading https://www.dreaminc...75-io-redirect/ which explains the I/O redirect option available in developing text-based software (command line).

## Source Control

If you're developing projects, you should be using source control.

Now, people really push github, but I am a much bigger fan of bitbucket because you can have private repos for free. This isn't something github offers.

Plus, bitbucket (technically Atlassian) has a pretty awesome GUI for git called SoureTree. The OAuth is a little wacky,...

## C++ Set Exploration

This entry is just a slow walk through getting familiar with sets.

Compile:
`g++ -std=c++11 program.cc -o demo`

References:
http://www.cplusplus...erence/set/set/
http://www.cplusplus...ce/set/set/set/
http://www.cplusplus...ence/algorithm/

Getting Started

Let's just get started with some boilerplate:

`...`

## Comma Separated Lists

One thing that I have never really properly gotten a handle on is creating comma separated lists of items from a collection. The issue is that the last entry will print a comma: 1, 2, 3, for example. In the past, I would do all kinds of weird code gymnastics to ensure that trailing comma doesn't print, but today I found a wonderful entry on ...

• (2 Pages)
• 1
• 2

S M T W T F S
1
2345678
9 101112131415
16171819202122
23242526272829
3031