diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-07-22 11:52:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-22 11:52:07 +0100 |
| commit | d37e9589e35e921133aa0462787a143a81139813 (patch) | |
| tree | 82c33380775741efb6b198393a8d71a6eefbb97d | |
| parent | a5e15bd7067c1938f255cfa77f38290e5890b14e (diff) | |
| parent | 7ec4ca814e8fd29682110778ba2a8012688a0e58 (diff) | |
| download | perlweeklychallenge-club-d37e9589e35e921133aa0462787a143a81139813.tar.gz perlweeklychallenge-club-d37e9589e35e921133aa0462787a143a81139813.tar.bz2 perlweeklychallenge-club-d37e9589e35e921133aa0462787a143a81139813.zip | |
Merge pull request #12396 from Firedrake/rogerbw-challenge-331
RogerBW solutions for challenge no. 331
25 files changed, 991 insertions, 0 deletions
diff --git a/challenge-331/roger-bell-west/crystal/ch-1.cr b/challenge-331/roger-bell-west/crystal/ch-1.cr new file mode 100755 index 0000000000..e5a65495d9 --- /dev/null +++ b/challenge-331/roger-bell-west/crystal/ch-1.cr @@ -0,0 +1,19 @@ +#! /usr/bin/crystal + +def lastword(a) + w = a.split(" ").select{|x| x.size > 0} + w[w.size - 1].size +end + +require "spec" +describe "lastword" do + it "test_ex1" do + lastword("The Weekly Challenge").should eq 9 + end + it "test_ex2" do + lastword(" Hello World ").should eq 5 + end + it "test_ex3" do + lastword("Let's begin the fun").should eq 3 + end +end diff --git a/challenge-331/roger-bell-west/crystal/ch-2.cr b/challenge-331/roger-bell-west/crystal/ch-2.cr new file mode 100755 index 0000000000..356a415ef7 --- /dev/null +++ b/challenge-331/roger-bell-west/crystal/ch-2.cr @@ -0,0 +1,33 @@ +#! /usr/bin/crystal + +def buddystrings(a, b) + ac = a.chars + bc = b.chars + 0.upto(ac.size - 1) do |i| + (i + 1).upto(ac.size - 1) do |j| + acx = ac.clone + acx[i] = ac[j] + acx[j] = ac[i] + if acx == bc + return true + end + end + end + false +end + +require "spec" +describe "buddystrings" do + it "test_ex1" do + buddystrings("fuck", "fcuk").should eq true + end + it "test_ex2" do + buddystrings("love", "love").should eq false + end + it "test_ex3" do + buddystrings("fodo", "food").should eq true + end + it "test_ex4" do + buddystrings("feed", "feed").should eq true + end +end diff --git a/challenge-331/roger-bell-west/javascript/ch-1.js b/challenge-331/roger-bell-west/javascript/ch-1.js new file mode 100755 index 0000000000..a36fb0d113 --- /dev/null +++ b/challenge-331/roger-bell-west/javascript/ch-1.js @@ -0,0 +1,27 @@ +#! /usr/bin/node + +"use strict" + +function lastword(a) { + let w = a.split(" ").filter(i => i.length > 0); + return w[w.length - 1].length; +} + +if (lastword('The Weekly Challenge') == 9) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write(" "); +if (lastword(' Hello World ') == 5) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write(" "); +if (lastword("Let's begin the fun") == 3) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write("\n"); diff --git a/challenge-331/roger-bell-west/javascript/ch-2.js b/challenge-331/roger-bell-west/javascript/ch-2.js new file mode 100755 index 0000000000..ce508eac40 --- /dev/null +++ b/challenge-331/roger-bell-west/javascript/ch-2.js @@ -0,0 +1,43 @@ +#! /usr/bin/node + +"use strict" + +function buddystrings(a, b) { + let ac = a.split(""); + for (let i = 0; i < a.length - 1; i++) { + for (let j = i + 1; j < a.length; j++) { + let acx = a.split(""); + acx[i] = ac[j]; + acx[j] = ac[i]; + if (acx.join("") == b) { + return true; + } + } + } + return false; +} + +if (buddystrings('fuck', 'fcuk')) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write(" "); +if (!buddystrings('love', 'love')) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write(" "); +if (buddystrings('fodo', 'food')) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write(" "); +if (buddystrings('feed', 'feed')) { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write("\n"); diff --git a/challenge-331/roger-bell-west/kotlin/ch-1.kt b/challenge-331/roger-bell-west/kotlin/ch-1.kt new file mode 100644 index 0000000000..33f0131e0a --- /dev/null +++ b/challenge-331/roger-bell-west/kotlin/ch-1.kt @@ -0,0 +1,27 @@ +fun lastword(a: String): Int { + val w = a.split(" ").filter {it.length > 0} + return w[w.size - 1].length +} + +fun main() { + + if (lastword("The Weekly Challenge") == 9) { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (lastword(" Hello World ") == 5) { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (lastword("Let's begin the fun") == 3) { + print("Pass") + } else { + print("Fail") + } + println("") + +} diff --git a/challenge-331/roger-bell-west/kotlin/ch-2.kt b/challenge-331/roger-bell-west/kotlin/ch-2.kt new file mode 100644 index 0000000000..c351b9f3fd --- /dev/null +++ b/challenge-331/roger-bell-west/kotlin/ch-2.kt @@ -0,0 +1,44 @@ +fun buddystrings(a: String, b: String): Boolean { + val ac = a.toCharArray().toList() + val bc = b.toCharArray().toList() + for (i in 0 .. a.length - 2) { + for (j in i + 1 .. a.length - 1) { + var acx = ArrayList(ac) + acx[i] = ac[j] + acx[j] = ac[i] + if (acx.toList() == bc) { + return true + } + } + } + return false +} + +fun main() { + + if (buddystrings("fuck", "fcuk")) { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (!buddystrings("love", "love")) { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (buddystrings("fodo", "food")) { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (buddystrings("feed", "feed")) { + print("Pass") + } else { + print("Fail") + } + println("") + +} diff --git a/challenge-331/roger-bell-west/lua/ch-1.lua b/challenge-331/roger-bell-west/lua/ch-1.lua new file mode 100755 index 0000000000..87efdcffa1 --- /dev/null +++ b/challenge-331/roger-bell-west/lua/ch-1.lua @@ -0,0 +1,59 @@ +#! /usr/bin/lua + +function splits(inputstr, sep) + sep = sep or '%s' + local starts = {1} + local ends = {} + local n = 1 + while true do + local fs, fe = string.find(inputstr, sep, n) + if fs == nil then + break + end + table.insert(ends, fs - 1) + table.insert(starts, fe + 1) + n = fe + 1 + end + table.insert(ends, #inputstr) + local t = {} + for i = 1, #starts do + local s = starts[i] + local e = ends[i] + if e >= s then + table.insert(t, string.sub(inputstr, s, e)) + end + end + return t +end + +function lastword(a) + local w = splits(a, " ") + for i = #w, 1, -1 do + if #(w[i]) > 0 then + return #(w[i]) + end + end + return 0 +end + +if lastword("The Weekly Challenge") == 9 then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if lastword(" Hello World ") == 5 then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if lastword("Let's begin the fun") == 3 then + io.write("Pass") +else + io.write("FAIL") +end +print("") + diff --git a/challenge-331/roger-bell-west/lua/ch-2.lua b/challenge-331/roger-bell-west/lua/ch-2.lua new file mode 100755 index 0000000000..5d1049e608 --- /dev/null +++ b/challenge-331/roger-bell-west/lua/ch-2.lua @@ -0,0 +1,62 @@ +#! /usr/bin/lua + +function split(t) + local cl = {} + string.gsub(t, + "(.)", + function(c) + table.insert(cl, c) + end + ) + return cl +end + +function join(t) + local out="" + for i, v in ipairs(t) do + out = out .. v + end + return out +end + +function buddystrings(a, b) + for i = 1, #a - 1 do + for j = i + 1, #a do + local acx = split(a) + acx[i], acx[j] = acx[j], acx[i] + if join(acx) == b then + return true + end + end + end + return false +end + +if buddystrings("fuck", "fcuk") then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if not buddystrings("love", "love") then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if buddystrings("fodo", "food") then + io.write("Pass") +else + io.write("FAIL") +end +io.write(" ") + +if buddystrings("feed", "feed") then + io.write("Pass") +else + io.write("FAIL") +end +print("") + diff --git a/challenge-331/roger-bell-west/perl/ch-1.pl b/challenge-331/roger-bell-west/perl/ch-1.pl new file mode 100755 index 0000000000..baa9df0915 --- /dev/null +++ b/challenge-331/roger-bell-west/perl/ch-1.pl @@ -0,0 +1,16 @@ +#! /usr/bin/perl + +use strict; +use warnings; +use experimental 'signatures'; + +use Test::More tests => 3; + +is(lastword('The Weekly Challenge'), 9, 'example 1'); +is(lastword(' Hello World '), 5, 'example 2'); +is(lastword("Let's begin the fun"), 3, 'example 3'); + +sub lastword($a) { + my @w = grep {length($a) > 0} split ' ', $a; + length($w[-1]); +} diff --git a/challenge-331/roger-bell-west/perl/ch-2.pl b/challenge-331/roger-bell-west/perl/ch-2.pl new file mode 100755 index 0000000000..0e174969a4 --- /dev/null +++ b/challenge-331/roger-bell-west/perl/ch-2.pl @@ -0,0 +1,27 @@ +#! /usr/bin/perl + +use strict; +use warnings; +use experimental 'signatures'; + +use Test::More tests => 4; + +is(buddystrings('fuck', 'fcuk'), 1, 'example 1'); +is(buddystrings('love', 'love'), 0, 'example 2'); +is(buddystrings('fodo', 'food'), 1, 'example 3'); +is(buddystrings('feed', 'feed'), 1, 'example 4'); + +sub buddystrings($a, $b) { + my @ac = split '', $a; + foreach my $i (0 .. $#ac - 1) { + foreach my $j ($i + 1 .. $#ac) { + my @acx = split '', $a;; + $acx[$i] = $ac[$j]; + $acx[$j] = $ac[$i]; + if (join("", @acx) eq $b) { + return 1; + } + } + } + 0; +} diff --git a/challenge-331/roger-bell-west/postscript/ch-1.ps b/challenge-331/roger-bell-west/postscript/ch-1.ps new file mode 100644 index 0000000000..fbb97830e2 --- /dev/null +++ b/challenge-331/roger-bell-west/postscript/ch-1.ps @@ -0,0 +1,75 @@ +%!PS + +% begin included library code +% see https://codeberg.org/Firedrake/postscript-libraries/ +/test.start { + print (:) print + /test.pass 0 def + /test.count 0 def +} bind def + +/test { + /test.count test.count 1 add def + { + /test.pass test.pass 1 add def + } { + ( ) print + test.count (....) cvs print + (-fail) print + } ifelse +} bind def + +/test.end { + ( ) print + test.count 0 gt { + (Passed ) print + test.pass (...) cvs print + (/) print + test.count (...) cvs print + ( \() print + test.pass 100 mul test.count idiv (...) cvs print + (%\)) print + (\r\n) print + } if +} bind def + +/strsplit % (ajbjc) (j) -> [ (a) (b) (c) ] +{ + 1 dict begin + /sep exch def + [ exch + { + dup length 0 eq { + pop + exit + } { + sep search { + exch pop + dup length 0 eq { + pop + } { + exch + } ifelse + } { + () + } ifelse + } ifelse + } loop + ] + end +} bind def + + +% end included library code + +/lastword { + ( ) strsplit + dup length 1 sub get + length +} bind def + +(lastword) test.start +(The Weekly Challenge) lastword 9 eq test +( Hello World ) lastword 5 eq test +(Let's begin the fun) lastword 3 eq test +test.end diff --git a/challenge-331/roger-bell-west/postscript/ch-2.ps b/challenge-331/roger-bell-west/postscript/ch-2.ps new file mode 100644 index 0000000000..b5032bafbc --- /dev/null +++ b/challenge-331/roger-bell-west/postscript/ch-2.ps @@ -0,0 +1,167 @@ +%!PS + +% begin included library code +% see https://codeberg.org/Firedrake/postscript-libraries/ +/deepcopy { + 2 dict begin + /a exch def + a type /dicttype eq { + << + a keys { + /k exch def + k + a k get deepcopy + } forall + >> + } { + a type /arraytype eq { + [ + a { + deepcopy + } forall + ] + } { + a type /stringtype eq { + a dup length string cvs + } { + a + } ifelse + } ifelse + } ifelse + end +} bind def + +/deepeq { + 2 dict begin + /a exch def + /b exch def + a type b type eq { + a type /dicttype eq { + a length b length eq { + << + a { + pop + true + } forall + b { + pop + true + } forall + >> + true exch + { + pop + dup a exch known { + dup b exch known { + dup a exch get exch b exch get deepeq not { + pop false + } if + } { + false + } ifelse + } { + false + } ifelse + } forall + } { + false + } ifelse + } { + a type dup /arraytype eq exch /stringtype eq or { + a length b length eq { + true + 0 1 a length 1 sub { + dup a exch get exch b exch get deepeq not { + pop false + exit + } if + } for + } { + false + } ifelse + } { + a b eq + } ifelse + } ifelse + } { + false + } ifelse + end +} bind def + +/keys { % dict -> array of dict keys + [ exch + { + pop + } forall + ] +} bind def + +/test.start { + print (:) print + /test.pass 0 def + /test.count 0 def +} bind def + +/s2a { + [ exch { } forall ] +} bind def + +/test { + /test.count test.count 1 add def + { + /test.pass test.pass 1 add def + } { + ( ) print + test.count (....) cvs print + (-fail) print + } ifelse +} bind def + +/test.end { + ( ) print + test.count 0 gt { + (Passed ) print + test.pass (...) cvs print + (/) print + test.count (...) cvs print + ( \() print + test.pass 100 mul test.count idiv (...) cvs print + (%\)) print + (\r\n) print + } if +} bind def + + +% end included library code + +/buddystrings { + 0 dict begin + s2a /bc exch def + s2a /ac exch def + false + 0 1 ac length 2 sub { + /i exch def + i 1 add 1 ac length 1 sub { + /j exch def + /acx ac deepcopy def + acx i ac j get put + acx j ac i get put + acx bc deepeq { + pop true + exit + } if + } for + dup { + exit + } if + } for + end +} bind def + +(buddystrings) test.start +(fuck) (fcuk) buddystrings test +(love) (love) buddystrings not test +(fodo) (food) buddystrings test +(feed) (feed) buddystrings test +test.end diff --git a/challenge-331/roger-bell-west/python/ch-1.py b/challenge-331/roger-bell-west/python/ch-1.py new file mode 100755 index 0000000000..57d8acf1ba --- /dev/null +++ b/challenge-331/roger-bell-west/python/ch-1.py @@ -0,0 +1,19 @@ +#! /usr/bin/python3 + +def lastword(a): + w = [wx for wx in a.split(" ") if len(wx) > 0] + return len(w[-1]) +import unittest + +class TestLastword(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(lastword("The Weekly Challenge"), 9, 'example 1') + + def test_ex2(self): + self.assertEqual(lastword(" Hello World "), 5, 'example 2') + + def test_ex3(self): + self.assertEqual(lastword("Let's begin the fun"), 3, 'example 3') + +unittest.main() diff --git a/challenge-331/roger-bell-west/python/ch-2.py b/challenge-331/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..02b40869c3 --- /dev/null +++ b/challenge-331/roger-bell-west/python/ch-2.py @@ -0,0 +1,29 @@ +#! /usr/bin/python3 + +def buddystrings(a, b): + bc = list(b) + for i in range(len(a) - 1): + for j in range(i + 1, len(a)): + acx = list(a) + acx[i] = a[j] + acx[j] = a[i] + if acx == bc: + return True + return False +import unittest + +class TestBuddystrings(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(buddystrings("fuck", "fcuk"), True, 'example 1') + + def test_ex2(self): + self.assertEqual(buddystrings("love", "love"), False, 'example 2') + + def test_ex3(self): + self.assertEqual(buddystrings("fodo", "food"), True, 'example 3') + + def test_ex4(self): + self.assertEqual(buddystrings("feed", "feed"), True, 'example 4') + +unittest.main() diff --git a/challenge-331/roger-bell-west/raku/ch-1.p6 b/challenge-331/roger-bell-west/raku/ch-1.p6 new file mode 100755 index 0000000000..de69404593 --- /dev/null +++ b/challenge-331/roger-bell-west/raku/ch-1.p6 @@ -0,0 +1,14 @@ +#! /usr/bin/raku + +use Test; + +plan 3; + +is(lastword('The Weekly Challenge'), 9, 'example 1'); +is(lastword(' Hello World '), 5, 'example 2'); +is(lastword("Let's begin the fun"), 3, 'example 3'); + +sub lastword($a) { + my @w = $a.split(' ').grep({$_.chars > 0}); + @w[*-1].chars; +} diff --git a/challenge-331/roger-bell-west/raku/ch-2.p6 b/challenge-331/roger-bell-west/raku/ch-2.p6 new file mode 100755 index 0000000000..8a1ccdaf8a --- /dev/null +++ b/challenge-331/roger-bell-west/raku/ch-2.p6 @@ -0,0 +1,25 @@ +#! /usr/bin/raku + +use Test; + +plan 4; + +is(buddystrings('fuck', 'fcuk'), True, 'example 1'); +is(buddystrings('love', 'love'), False, 'example 2'); +is(buddystrings('fodo', 'food'), True, 'example 3'); +is(buddystrings('feed', 'feed'), True, 'example 4'); + +sub buddystrings($a, $b) { + my @ac = $a.comb; + for (0 .. @ac.elems - 2) -> $i { + for ($i + 1 .. @ac.elems - 1) -> $j { + my @acx = $a.comb; + @acx[$i] = @ac[$j]; + @acx[$j] = @ac[$i]; + if (@acx.join("") eq $b) { + return True; + } + } + } + False; +} diff --git a/challenge-331/roger-bell-west/ruby/ch-1.rb b/challenge-331/roger-bell-west/ruby/ch-1.rb new file mode 100755 index 0000000000..c1ae05d3c5 --- /dev/null +++ b/challenge-331/roger-bell-west/ruby/ch-1.rb @@ -0,0 +1,24 @@ +#! /usr/bin/ruby + +def lastword(a) + w = a.split(" ").select{|x| x.size > 0} + w[w.size - 1].size +end + +require 'test/unit' + +class TestLastword < Test::Unit::TestCase + + def test_ex1 + assert_equal(9, lastword('The Weekly Challenge')) + end + + def test_ex2 + assert_equal(5, lastword(' Hello World ')) + end + + def test_ex3 + assert_equal(3, lastword("Let's begin the fun")) + end + +end diff --git a/challenge-331/roger-bell-west/ruby/ch-2.rb b/challenge-331/roger-bell-west/ruby/ch-2.rb new file mode 100755 index 0000000000..e4ae1991c0 --- /dev/null +++ b/challenge-331/roger-bell-west/ruby/ch-2.rb @@ -0,0 +1,39 @@ +#! /usr/bin/ruby + +def buddystrings(a, b) + ac = a.chars + bc = b.chars + 0.upto(ac.size - 1) do |i| + (i + 1).upto(ac.size - 1) do |j| + acx = ac.clone + acx[i] = ac[j] + acx[j] = ac[i] + if acx == bc + return true + end + end + end + false +end + +require 'test/unit' + +class TestBuddystrings < Test::Unit::TestCase + + def test_ex1 + assert_equal(true, buddystrings('fuck', 'fcuk')) + end + + def test_ex2 + assert_equal(false, buddystrings('love', 'love')) + end + + def test_ex3 + assert_equal(true, buddystrings('fodo', 'food')) + end + + def test_ex4 + assert_equal(true, buddystrings('feed', 'feed')) + end + +end diff --git a/challenge-331/roger-bell-west/rust/ch-1.rs b/challenge-331/roger-bell-west/rust/ch-1.rs new file mode 100755 index 0000000000..bb05832219 --- /dev/null +++ b/challenge-331/roger-bell-west/rust/ch-1.rs @@ -0,0 +1,22 @@ +#! /bin/sh +//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x --nocapture; rm -f ${0}x ; exit + +#[test] +fn test_ex1() { + assert_eq!(lastword("The Weekly Challenge"), 9); +} + +#[test] +fn test_ex2() { + assert_eq!(lastword(" Hello World "), 5); +} + +#[test] +fn test_ex3() { + assert_eq!(lastword("Let's begin the fun"), 3); +} + +fn lastword(a: &str) -> usize { + let w = a.split(" ").filter(|x| x.len() > 0).collect::<Vec<_>>(); + w[w.len() - 1].len() +} diff --git a/challenge-331/roger-bell-west/rust/ch-2.rs b/challenge-331/roger-bell-west/rust/ch-2.rs new file mode 100755 index 0000000000..c0dad8bc91 --- /dev/null +++ b/challenge-331/roger-bell-west/rust/ch-2.rs @@ -0,0 +1,38 @@ +#! /bin/sh +//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x --nocapture; rm -f ${0}x ; exit + +#[test] +fn test_ex1() { + assert_eq!(buddystrings("fuck", "fcuk"), true); +} + +#[test] +fn test_ex2() { + assert_eq!(buddystrings("love", "love"), false); +} + +#[test] +fn test_ex3() { + assert_eq!(buddystrings("fodo", "food"), true); +} + +#[test] +fn test_ex4() { + assert_eq!(buddystrings("feed", "feed"), true); +} + +fn buddystrings(a: &str, b: &str) -> bool { + let ac = a.chars().collect::<Vec<_>>(); + let bc = b.chars().collect::<Vec<_>>(); + for i in 0 .. ac.len() - 1 { + for j in i + 1 .. ac.len() { + let mut acx = ac.clone(); + acx[i] = ac[j]; + acx[j] = ac[i]; + if acx == bc { + return true; + } + } + } + false +} diff --git a/challenge-331/roger-bell-west/scala/ch-1.scala b/challenge-331/roger-bell-west/scala/ch-1.scala new file mode 100644 index 0000000000..03471037d3 --- /dev/null +++ b/challenge-331/roger-bell-west/scala/ch-1.scala @@ -0,0 +1,28 @@ + +object Lastword { + def lastword(a: String): Int = { + val w = a.split(" ").filter (x => x.length > 0) + w(w.size - 1).length + } + def main(args: Array[String]) { + if (lastword("The Weekly Challenge") == 9) { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (lastword(" Hello World ") == 5) { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (lastword("Let's begin the fun") == 3) { + print("Pass") + } else { + print("Fail") + } + println("") + + } +} diff --git a/challenge-331/roger-bell-west/scala/ch-2.scala b/challenge-331/roger-bell-west/scala/ch-2.scala new file mode 100644 index 0000000000..22727508e6 --- /dev/null +++ b/challenge-331/roger-bell-west/scala/ch-2.scala @@ -0,0 +1,47 @@ +import scala.collection.mutable.ListBuffer + +object Buddystrings { + def buddystrings(a: String, b: String): Boolean = { + val ac = a.to[ListBuffer] + val bc = b.to[ListBuffer] + var v = false + for (i <- 0 until a.length - 1) { + for (j <- i + 1 until a.length) { + var acx = a.to[ListBuffer] + acx(i) = ac(j) + acx(j) = ac(i) + if (acx == bc) { + v = true + } + } + } + v + } + def main |
