Last active
June 22, 2024 19:10
-
-
Save vtmx/040d98d106e58f590bc89ac177cfec9e to your computer and use it in GitHub Desktop.
dna.v
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| fn main() { | |
| mut argv := '' | |
| mut nucleos := ['A', 'C', 'T', 'G'] | |
| if os.args.len == 1 { | |
| argv = os.input('nucleo: ') | |
| } else if os.args.len == 2 { | |
| argv = os.args[1] | |
| } else { | |
| eprintln('dna: accept only one argument') | |
| print_example() | |
| exit(0) | |
| } | |
| if argv.len != nucleos.len { | |
| eprintln('dna: need four chars') | |
| print_example() | |
| exit(1) | |
| } | |
| argv = argv.to_upper() | |
| mut nnucleos := 0 | |
| for c := 0; c < argv.len; c++ { | |
| for nucleo in nucleos { | |
| if argv[c].ascii_str() == nucleo { | |
| nnucleos++ | |
| } | |
| } | |
| } | |
| if nnucleos != nucleos.len { | |
| eprintln('dna: need four chars valid') | |
| print_example() | |
| exit(1) | |
| } | |
| println('$argv - Ok') | |
| } | |
| fn print_example() { | |
| println(' ex: ./dna ACTG') | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment