diff options
Diffstat (limited to 'challenge-090')
| -rwxr-xr-x | challenge-090/roger-bell-west/perl/ch-1.pl | 19 | ||||
| -rwxr-xr-x | challenge-090/roger-bell-west/perl/ch-2.pl | 26 | ||||
| -rwxr-xr-x | challenge-090/roger-bell-west/python/ch-1.py | 15 | ||||
| -rwxr-xr-x | challenge-090/roger-bell-west/python/ch-2.py | 22 | ||||
| -rwxr-xr-x | challenge-090/roger-bell-west/raku/ch-1.p6 | 16 | ||||
| -rwxr-xr-x | challenge-090/roger-bell-west/raku/ch-2.p6 | 25 | ||||
| -rwxr-xr-x | challenge-090/roger-bell-west/ruby/ch-1.rb | 17 | ||||
| -rwxr-xr-x | challenge-090/roger-bell-west/ruby/ch-2.rb | 22 | ||||
| -rwxr-xr-x | challenge-090/roger-bell-west/rust/ch-1.rs | 22 | ||||
| -rwxr-xr-x | challenge-090/roger-bell-west/rust/ch-2.rs | 28 |
10 files changed, 212 insertions, 0 deletions
diff --git a/challenge-090/roger-bell-west/perl/ch-1.pl b/challenge-090/roger-bell-west/perl/ch-1.pl new file mode 100755 index 0000000000..e1c5e588ee --- /dev/null +++ b/challenge-090/roger-bell-west/perl/ch-1.pl @@ -0,0 +1,19 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 1; + +is_deeply(gs('GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG'),[67,'CATTTGGGGAAAAGTAAATCTGTCTAGCTGAGGAATAGGTAAGAGTCTCTACACAACGACCAGCGGC'],'example 1'); + +sub gs { + my $bs=shift; + (my $cs=$bs) =~ s/G/X/g; + $cs =~ s/C/G/g; + $cs =~ s/X/C/g; + $cs =~ s/A/X/g; + $cs =~ s/T/A/g; + $cs =~ s/X/T/g; + return [length($bs),$cs]; +} diff --git a/challenge-090/roger-bell-west/perl/ch-2.pl b/challenge-090/roger-bell-west/perl/ch-2.pl new file mode 100755 index 0000000000..b74215b6f3 --- /dev/null +++ b/challenge-090/roger-bell-west/perl/ch-2.pl @@ -0,0 +1,26 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +em(13,238); + +sub em { + my ($a,$b)=@_; + my $s=0; + my @demo; + while ($a > 0) { + my $line=sprintf('%5d %5d',$a,$b); + if ($a & 1 == 1) { + $s+=$b; + $line .= sprintf(' -> %5d',$b); + } + $a >>= 1; + $b <<= 1; + push @demo,$line; + } + push @demo,' -----'; + push @demo,sprintf(' %5d',$s); + print map {"$_\n"} @demo; + return $s; +} diff --git a/challenge-090/roger-bell-west/python/ch-1.py b/challenge-090/roger-bell-west/python/ch-1.py new file mode 100755 index 0000000000..64ac9905d0 --- /dev/null +++ b/challenge-090/roger-bell-west/python/ch-1.py @@ -0,0 +1,15 @@ +#! /usr/bin/python3 + +def gs(bs): + l={'A': 'T','T': 'A','C': 'G','G': 'C'} + os=''.join(l[i] for i in bs) + return [len(os),os] + +import unittest + +class TestGs(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(gs('GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG'),[67,'CATTTGGGGAAAAGTAAATCTGTCTAGCTGAGGAATAGGTAAGAGTCTCTACACAACGACCAGCGGC'],'example 1') + +unittest.main() diff --git a/challenge-090/roger-bell-west/python/ch-2.py b/challenge-090/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..e63182aa61 --- /dev/null +++ b/challenge-090/roger-bell-west/python/ch-2.py @@ -0,0 +1,22 @@ +#! /usr/bin/python3 + +def em(aa,bb): + a=aa + b=bb + s=0 + demo=list() + while (a > 0): + line=' '.join([format(a,'5d'),format(b,'5d')]) + if (a & 1 == 1): + s += b + line=' '.join([line,'->',format(b,'5d')]) + a = a >> 1 + b = b << 1 + demo.append(line) + demo.append(' -----') + demo.append(' ' + format(s,'5d')) + for i in demo: + print(i) + return s + +em(13,238) diff --git a/challenge-090/roger-bell-west/raku/ch-1.p6 b/challenge-090/roger-bell-west/raku/ch-1.p6 new file mode 100755 index 0000000000..3f6ffd473a --- /dev/null +++ b/challenge-090/roger-bell-west/raku/ch-1.p6 @@ -0,0 +1,16 @@ +#! /usr/bin/perl6 + +use Test; +plan 1; + +is-deeply(gs('GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG'),(67,'CATTTGGGGAAAAGTAAATCTGTCTAGCTGAGGAATAGGTAAGAGTCTCTACACAACGACCAGCGGC'),'example 1'); + +sub gs($bs) { + (my $cs=$bs) ~~ s:g/G/X/; + $cs ~~ s:g/C/G/; + $cs ~~ s:g/X/C/; + $cs ~~ s:g/A/X/; + $cs ~~ s:g/T/A/; + $cs ~~ s:g/X/T/; + return (chars($bs),$cs); +} diff --git a/challenge-090/roger-bell-west/raku/ch-2.p6 b/challenge-090/roger-bell-west/raku/ch-2.p6 new file mode 100755 index 0000000000..861ca26b81 --- /dev/null +++ b/challenge-090/roger-bell-west/raku/ch-2.p6 @@ -0,0 +1,25 @@ +#! /usr/bin/perl6 + +em(13,238); + +sub em($aa,$bb) { + my ($a,$b)=($aa,$bb); + my $s=0; + my @demo; + while ($a > 0) { + my $line=sprintf('%5d %5d',$a,$b); + if ($a +& 1 == 1) { + $s+=$b; + $line ~= sprintf(' -> %5d',$b); + } + $a +>= 1; + $b +<= 1; + push @demo,$line; + } + push @demo,' -----'; + push @demo,sprintf(' %5d',$s); + for @demo { + say $_; + } + return $s; +} diff --git a/challenge-090/roger-bell-west/ruby/ch-1.rb b/challenge-090/roger-bell-west/ruby/ch-1.rb new file mode 100755 index 0000000000..5a0a58f7f6 --- /dev/null +++ b/challenge-090/roger-bell-west/ruby/ch-1.rb @@ -0,0 +1,17 @@ +#! /usr/bin/ruby + +def gs(bs) + l={'A' => 'T', 'T' => 'A', 'C' => 'G', 'G' => 'C'} + os=bs.chars.map{|i| l[i]}.join('') + return [os.length(),os] +end + +require 'test/unit' + +class TestGs < Test::Unit::TestCase + + def test_ex1 + assert_equal([67,'CATTTGGGGAAAAGTAAATCTGTCTAGCTGAGGAATAGGTAAGAGTCTCTACACAACGACCAGCGGC'],gs('GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG')) + end + +end diff --git a/challenge-090/roger-bell-west/ruby/ch-2.rb b/challenge-090/roger-bell-west/ruby/ch-2.rb new file mode 100755 index 0000000000..0799b4cdc5 --- /dev/null +++ b/challenge-090/roger-bell-west/ruby/ch-2.rb @@ -0,0 +1,22 @@ +#! /usr/bin/ruby + +def em(a,b) + s=0 + demo=Array.new + while (a>0) do + line=sprintf('%5d %5d',a,b) + if (a & 1 == 1) then + s += b + line += sprintf(' -> %5d',b) + end + a >>= 1 + b <<= 1 + demo.push(line) + end + demo.push(' -----') + demo.push(sprintf(' %5d',s)); + demo.map{|i| print i,"\n"} + return s +end + +em(13,238) diff --git a/challenge-090/roger-bell-west/rust/ch-1.rs b/challenge-090/roger-bell-west/rust/ch-1.rs new file mode 100755 index 0000000000..8475b60a13 --- /dev/null +++ b/challenge-090/roger-bell-west/rust/ch-1.rs @@ -0,0 +1,22 @@ +#! /bin/sh +//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x; rm -f ${0}x ; exit + +use std::collections::HashMap; + +#[test] +fn test_ex1() { + assert_eq!(gs("GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG".to_string()),(67,"CATTTGGGGAAAAGTAAATCTGTCTAGCTGAGGAATAGGTAAGAGTCTCTACACAACGACCAGCGGC".to_string())); +} + +fn gs(bs: String) -> (i32, String) { + let mut l: HashMap<char, char>=HashMap::new(); + l.insert('C','G'); + l.insert('A','T'); + l.insert('G','C'); + l.insert('T','A'); + let mut os=String::new(); + for i in bs.chars() { + os.push(*l.get(&i).unwrap()); + } + return (os.len() as i32,os); +} diff --git a/challenge-090/roger-bell-west/rust/ch-2.rs b/challenge-090/roger-bell-west/rust/ch-2.rs new file mode 100755 index 0000000000..87f91dfd64 --- /dev/null +++ b/challenge-090/roger-bell-west/rust/ch-2.rs @@ -0,0 +1,28 @@ +#! /bin/sh +//usr/bin/env rustc $0 -o ${0}x && ./${0}x; rm -f ${0}x ; exit + +fn em(aa: i32, bb: i32) { + let mut a=aa; + let mut b=bb; + let mut s=0; + let mut demo=Vec::<String>::new(); + while a > 0 { + let mut line: String=format!("{:>5} {:>5}",a,b).to_string(); + if a & 1 == 1 { + s += b; + line.push_str(&format!(" -> {:>5}",b)[0..]); + } + a >>= 1; + b <<= 1; + demo.push(line); + } + demo.push(" -----".to_string()); + demo.push(format!(" {:>5}",s).to_string()); + for i in demo { + println!("{}",i); + } +} + +fn main() { + em(13,238); +} |
