Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created March 25, 2015 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshCheek/36ee8bdd049d60238d04 to your computer and use it in GitHub Desktop.
Save JoshCheek/36ee8bdd049d60238d04 to your computer and use it in GitHub Desktop.
Generate boolean challenges
puts (2**9).times
.map { |iteration|
'%{paren1left}%{negation1}%{bool1} %{op1} %{paren2left}%{negation2}%{bool2}%{paren1right} %{op2} %{negation3}%{bool3}%{paren2right}' % {
bool1: iteration[0].zero?,
bool2: iteration[1].zero?,
bool3: iteration[2].zero?,
negation1: iteration[3].zero? ? '' : '!',
negation2: iteration[4].zero? ? '' : '!',
negation3: iteration[5].zero? ? '' : '!',
op1: iteration[6].zero? ? '||' : '&&',
op2: iteration[7].zero? ? '||' : '&&',
paren1left: iteration[8].zero? ? '(' : '',
paren1right: iteration[8].zero? ? ')' : '',
paren2left: iteration[8].zero? ? '' : '(',
paren2right: iteration[8].zero? ? '' : ')',
}
}
.shuffle
.take(40)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment