Jump to content

24 game: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
imported>Arakov
Line 4,526:
auto level := new Integer(0);
s.forEach::(ch)
{
var node := new DynamicStruct();
Line 4,535:
$42 { node.Level := level + 2; node.Operation := mssg multiply } // *
$47 { node.Level := level + 2; node.Operation := mssg divide } // /
$40 { level.append(10); ^ self } // (
$41 { level.reduce(10); ^ self } // )
:! {
node.Leaf := ch.toString().toReal();
node.Level := level + 3
Line 4,625:
theNumbers := new object[]
{
1 + randomGenerator.nextInt:(9),
1 + randomGenerator.nextInt:(9),
1 + randomGenerator.nextInt:(9),
1 + randomGenerator.nextInt:(9)
}
}
Line 4,635:
{
console
.printLine:("------------------------------- Instructions ------------------------------")
.printLine:("Four digits will be displayed.")
.printLine:("Enter an equation using all of those four digits that evaluates to 24")
.printLine:("Only * / + - operators and () are allowed")
.printLine:("Digits can only be used once, but in any order you need.")
.printLine:("Digits cannot be combined - i.e.: 12 + 12 when given 1,2,2,1 is not allowed")
.printLine:("Submit a blank line to skip the current puzzle.")
.printLine:("Type 'q' to quit")
.writeLine()
.printLine:("Example: given 2 3 8 2, answer should resemble 8*3-(2-2)")
.printLine:("------------------------------- --------------------------------------------")
}
prompt()
{
theNumbers.forEach::(n){ console.print(n," ") };
console.print:(": ")
}
Line 4,660:
var leaves := new ArrayList();
tree.readLeaves:(leaves);
ifnot (leaves.ascendant().sequenceEqual(theNumbers.ascendant())) {
{ console.printLine:("Invalid input. Enter an equation using all of those four digits. Try again."); ^ self };
console
.printLine:"Invalid input. Enter an equation using all of those four digits. Try again.";
^ self
};
var result := tree.Value;
Line 4,694 ⟶ 4,691:
if (expr == "")
{
console.printLine:("Skipping this puzzle"); self.newPuzzle()
}
else
Line 4,704 ⟶ 4,701:
catch(Exception e)
{
console.printLine:(e)
//console.printLine:"An error occurred. Check your input and try again."
}
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.