How to resolve the algorithm Text processing/2 step by step in the Factor programming language
How to resolve the algorithm Text processing/2 step by step in the Factor programming language
Table of Contents
Problem Statement
The following task concerns data that came from a pollution monitoring station with twenty-four instruments monitoring twenty-four aspects of pollution in the air. Periodically a record is added to the file, each record being a line of 49 fields separated by white-space, which can be one or more space or tab characters. The fields (from the left) are: i.e. a datestamp followed by twenty-four repetitions of a floating-point instrument value and that instrument's associated integer flag. Flag values are >= 1 if the instrument is working and < 1 if there is some problem with it, in which case that instrument's value should be ignored. A sample from the full data file readings.txt, which is also used in the Text processing/1 task, follows: Data is no longer available at that link. Zipped mirror available here
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Text processing/2 step by step in the Factor programming language
Source code in the factor programming language
USING: io io.encodings.ascii io.files kernel math math.parser
prettyprint sequences sequences.extras sets splitting ;
: check-format ( seq -- )
[ " \t" split length 49 = ] all?
"Format okay." "Format not okay." ? print ;
"readings.txt" ascii file-lines [ check-format ] keep
[ "Duplicates:" print [ "\t" split1 drop ] map duplicates . ]
[ [ " \t" split rest <odds> [ string>number 0 <= ] none? ] count ]
bi pprint " records were good." print
You may also check:How to resolve the algorithm Compound data type step by step in the ActionScript programming language
You may also check:How to resolve the algorithm Sorting algorithms/Cocktail sort with shifting bounds step by step in the Julia programming language
You may also check:How to resolve the algorithm Operator precedence step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Truncatable primes step by step in the Delphi programming language
You may also check:How to resolve the algorithm Vector products step by step in the Crystal programming language