How to resolve the algorithm 24 game step by step in the J programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm 24 game step by step in the J programming language
Table of Contents
Problem Statement
The 24 Game tests one's mental arithmetic.
Write a program that randomly chooses and displays four digits, each from 1 ──► 9 (inclusive) with repetitions allowed. The program should prompt for the player to enter an arithmetic expression using just those, and all of those four digits, used exactly once each. The program should check then evaluate the expression. The goal is for the player to enter an expression that (numerically) evaluates to 24.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm 24 game step by step in the J programming language
Source code in the j programming language
require'misc'
deal=: 1 + ? bind 9 9 9 9
rules=: smoutput bind 'see http://en.wikipedia.org/wiki/24_Game'
input=: prompt @ ('enter 24 expression using ', ":, ': '"_)
wellformed=: (' '<;._1@, ":@[) -:&(/:~) '(+-*%)' -.&;:~ ]
is24=: 24 -: ". ::0:@]
respond=: (;:'no yes') {::~ wellformed * is24
game24=: (respond input)@deal@rules
You may also check:How to resolve the algorithm Strip whitespace from a string/Top and tail step by step in the Run BASIC programming language
You may also check:How to resolve the algorithm System time step by step in the Logo programming language
You may also check:How to resolve the algorithm Aliquot sequence classifications step by step in the zkl programming language
You may also check:How to resolve the algorithm Shoelace formula for polygonal area step by step in the D programming language
You may also check:How to resolve the algorithm HTTP step by step in the C# programming language