diff options
49 files changed, 4907 insertions, 2657 deletions
diff --git a/challenge-161/ildar-shaimordanov/README b/challenge-161/ildar-shaimordanov/README new file mode 100644 index 0000000000..1509c3983f --- /dev/null +++ b/challenge-161/ildar-shaimordanov/README @@ -0,0 +1 @@ +Solution by Ildar Shaimordanov diff --git a/challenge-161/ildar-shaimordanov/perl/ch-1.pl b/challenge-161/ildar-shaimordanov/perl/ch-1.pl new file mode 100644 index 0000000000..477d6164cf --- /dev/null +++ b/challenge-161/ildar-shaimordanov/perl/ch-1.pl @@ -0,0 +1,50 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +# https://theweeklychallenge.org/blog/perl-weekly-challenge-161/ +# +# Task 1: Abecedarian Words +# Submitted by: Ryan J Thompson +# +# An abecedarian word is a word whose letters are arranged in alphabetical +# order. For example, knotty is an abecedarian word, but knots +# is not. Output or return a list of all abecedarian words in the +# dictionary, sorted in decreasing order of length. + +# ========================================================================= + +# The version using regex + +# The same approach as one-liner +# perl -nle 'BEGIN { $A = join "", "a".."z" } $a = $A; ( $w = $_ ) =~ s/(.)\1*/$a =~ s#.*$1## ? "" : $&/eg; $w or print' + +my $A = join "", "a".."z"; + +while ( <> ) { + my $a = $A; + + chomp( my $word = $_ ); + + $word =~ s/(.)\1*/ $a =~ s|.*$1|| ? "" : $& /eg; + + $word or print; +} + +# ========================================================================= + +# The version using split/sort/join + +# The same approach as one-liner +# perl -nle '( join "", sort split // ) eq $_ && print' + +#while ( <> ) { +# chomp( my $word = $_ ); +# my $sorted = join '', sort split //, $word; +# $sorted eq $word && print; +#} + +# ========================================================================= + +# EOF diff --git a/challenge-162/conor-hoekstra/apl/ch-1.apl b/challenge-162/conor-hoekstra/apl/ch-1.apl new file mode 100644 index 0000000000..a93ba65c05 --- /dev/null +++ b/challenge-162/conor-hoekstra/apl/ch-1.apl @@ -0,0 +1,5 @@ +checkDigit ← {10-10|+/(⊢×1 3⍴⍨≢)⍎¨¯1↓⍵~'-'} + +⍝ Test +checkDigit '978-0-306-40615-7' ⍝ 7 +checkDigit '978-1-861-97271-2' ⍝ 2 diff --git a/challenge-162/eric-cheung/python/ch-1.py b/challenge-162/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..e2586a422c --- /dev/null +++ b/challenge-162/eric-cheung/python/ch-1.py @@ -0,0 +1,17 @@ +
+def getCheckDigit_13(strISBN_12):
+
+ arrFactor = [1, 3]
+ nSum = 0
+ for nLoop in range(0, len(strISBN_12)):
+ nSum = nSum + int(strISBN_12[nLoop]) * arrFactor[nLoop % 2]
+
+ return (10 - nSum % 10) % 10
+
+
+strISBN = "978030640615"
+
+strISBN_Nu = "{}-{}-{}-{}".format(strISBN[:3], strISBN[3:4], strISBN[4:7], strISBN[7:])
+
+## print ("ISBN-13 check digit for " + strISBN + " is " + str(getCheckDigit_13(strISBN)))
+print ("ISBN-13 check digit for " + strISBN_Nu + " is " + str(getCheckDigit_13(strISBN)))
diff --git a/challenge-162/eric-cheung/python/ch-2.py b/challenge-162/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..d002908802 --- /dev/null +++ b/challenge-162/eric-cheung/python/ch-2.py @@ -0,0 +1,142 @@ +
+nMaxElem = 25
+nDiv = 5
+arrKey = []
+
+def getKeyTable(strWord):
+ nCount = 0
+
+ for nLoop in range(0, len(strWord)):
+ strLetter = strWord[nLoop].upper()
+
+ if strLetter == " ":
+ continue
+
+ if not strLetter in arrKey:
+ arrKey.append(strLetter)
+ nCount = nCount + 1
+
+ nIndex = 65
+ nLoop = nCount
+ while nLoop < nMaxElem:
+ strLetter = chr(nIndex)
+
+ if strLetter == "I" or strLetter == "J":
+ if not "I" in arrKey and not "J" in arrKey:
+ arrKey.append(strLetter)
+ nLoop = nLoop + 1
+ elif not strLetter in arrKey:
+ arrKey.append(strLetter)
+ nLoop = nLoop + 1
+
+ nIndex = nIndex + 1
+
+def getRowColFromKey(strChar):
+
+ nIndx = -1
+ if strChar == "I" or strChar == "J":
+ if "I" in arrKey:
+ nIndx = arrKey.index("I")
+ else:
+ nIndx = arrKey.index("J")
+ else:
+ nIndx = arrKey.index(strChar)
+
+ nRowIndx = int (nIndx / nDiv)
+ nColIndx = nIndx % nDiv
+
+ return [nRowIndx, nColIndx]
+
+
+def getRefineNewMsg(strWord, bIsEncrypt):
+
+ strNuWord = ""
+ for nLoop in range(0, len(strWord)):
+ strLetter = strWord[nLoop].upper()
+
+ if strLetter == " ":
+ continue
+
+ if nLoop == 0:
+ strNuWord = strLetter
+ elif strLetter == strWord[nLoop - 1].upper():
+ if bIsEncrypt:
+ strNuWord = strNuWord + "X" + strLetter
+ else:
+ strNuWord = strNuWord + strLetter
+ else:
+ strNuWord = strNuWord + strLetter
+
+ return strNuWord
+
+def getEncryptDecryptPair(strLetterPair, bIsEncrypt):
+
+ nRowNum_01, nColNum_01 = getRowColFromKey(strLetterPair[0])
+ nRowNum_02, nColNum_02 = getRowColFromKey(strLetterPair[1])
+
+ if nRowNum_01 == nRowNum_02 and nColNum_01 == nColNum_02:
+
+ return strLetterPair
+
+ if nRowNum_01 != nRowNum_02 and nColNum_01 != nColNum_02:
+
+ nMinCol = min(nColNum_01, nColNum_02)
+ nMaxCol = max(nColNum_01, nColNum_02)
+
+ nRowNum_Nu_01 = nRowNum_01
+ nRowNum_Nu_02 = nRowNum_02
+
+ nColNum_Nu_01 = nMaxCol - nColNum_01 + nMinCol
+ nColNum_Nu_02 = nMaxCol - nColNum_02 + nMinCol
+
+ elif nRowNum_01 == nRowNum_02:
+
+ nColDiff = 1
+
+ nRowNum_Nu_01 = nRowNum_01
+ nRowNum_Nu_02 = nRowNum_02
+
+ if bIsEncrypt:
+ nColNum_Nu_01 = nColNum_01 + nColDiff if nColNum_01 + nColDiff < nDiv else nColNum_01 + nColDiff - nDiv
+ nColNum_Nu_02 = nColNum_02 + nColDiff if nColNum_02 + nColDiff < nDiv else nColNum_02 + nColDiff - nDiv
+ else:
+ nColNum_Nu_01 = nColNum_01 - nColDiff if nColNum_01 - nColDiff > -1 else nColNum_01 - nColDiff + nDiv
+ nColNum_Nu_02 = nColNum_02 - nColDiff if nColNum_02 - nColDiff > -1 else nColNum_02 - nColDiff + nDiv
+ else:
+
+ nRowDiff = 1
+
+ if bIsEncrypt:
+ nRowNum_Nu_01 = nRowNum_01 + nRowDiff if nRowNum_01 + nRowDiff < nDiv else nRowNum_01 + nRowDiff - nDiv
+ nRowNum_Nu_02 = nRowNum_02 + nRowDiff if nRowNum_02 + nRowDiff < nDiv else nRowNum_02 + nRowDiff - nDiv
+ else:
+ nRowNum_Nu_01 = nRowNum_01 - nRowDiff if nRowNum_01 - nRowDiff > -1 else nRowNum_01 - nRowDiff + nDiv
+ nRowNum_Nu_02 = nRowNum_02 - nRowDiff if nRowNum_02 - nRowDiff > -1 else nRowNum_02 - nRowDiff + nDiv
+
+ nColNum_Nu_01 = nColNum_01
+ nColNum_Nu_02 = nColNum_02
+
+ return arrKey[nRowNum_Nu_01 * nDiv + nColNum_Nu_01] + arrKey[nRowNum_Nu_02 * nDiv + nColNum_Nu_02]
+
+
+def getEncryptDecrytMsg(strWord, bIsEncrypt):
+
+ strEncryWord = ""
+ for nLoop in range(0, len(strWord)):
+ if nLoop % 2 == 1:
+ continue
+
+ ## print (strWord[nLoop:nLoop + 2] + "-" + getEncryptDecryptPair(strWord[nLoop:nLoop + 2], bIsEncrypt))
+ strEncryWord = strEncryWord + getEncryptDecryptPair(strWord[nLoop:nLoop + 2], bIsEncrypt)
+
+ return strEncryWord.lower()
+
+
+def EncryptDecryptPart(strKeyWord, strEncryptWord, bIsEncrypt):
+
+ getKeyTable(strKeyWord)
+
+ return getEncryptDecrytMsg(getRefineNewMsg(strEncryptWord, bIsEncrypt), bIsEncrypt)
+
+## print (EncryptDecryptPart("playfair example", "hide the gold in the tree stump", True))
+print (EncryptDecryptPart("perl and raku", "siderwrdulfipaarkcrw", False))
diff --git a/challenge-162/mark-anderson/raku/ch-1.raku b/challenge-162/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..f7c2bc9145 --- /dev/null +++ b/challenge-162/mark-anderson/raku/ch-1.raku @@ -0,0 +1,14 @@ +#!/usr/bin/env raku + +use Test; + +is check-digit('978-0-306-40615-7'), 7; +is check-digit('012-3-456-78921-0'), 0; + +sub check-digit(\isbn) +{ + 10 - (sum isbn.chop.comb(/\d/) >>*>> < 1 3 >) mod 10 + + andthen .item < 10 ?? .item !! 0 +} + diff --git a/challenge-162/perlboy1967/perl/ch-1.pl b/challenge-162/perlboy1967/perl/ch-1.pl new file mode 100755 index 0000000000..841bcd915b --- /dev/null +++ b/challenge-162/perlboy1967/perl/ch-1.pl @@ -0,0 +1,25 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 162 + - https://perlweeklychallenge.org/blog/perl-weekly-challenge-162/#TASK1 + +Author: Niels 'PerlBoy' van Dijke + +Task 1: ISBN-13 +Submitted by: Mohammad S Anwar + +Write a script to generate the check digit of given ISBN-13 code. Please refer to +wikipedia for more information. + +=cut + +use v5.16; + +use List::Util qw(sum0); +use List::MoreUtils qw(pairwise); + +my @isbnDigits = (grep/\d/,split//,shift // '978-0-306-40615-7')[0..11]; +my @factors = split//,1313131313131; +say -(sum0 pairwise {$a*$b} @isbnDigits,@factors) % 10; diff --git a/challenge-162/perlboy1967/perl/ch-2.pl b/challenge-162/perlboy1967/perl/ch-2.pl new file mode 100755 index 0000000000..9f96f473d8 --- /dev/null +++ b/challenge-162/perlboy1967/perl/ch-2.pl @@ -0,0 +1,101 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 162 + - https://perlweeklychallenge.org/blog/perl-weekly-challenge-162/#TASK2 + +Author: Niels 'PerlBoy' van Dijke + +Task 2: Wheatstone-Playfair +Submitted by: Roger Bell_West + +Implement encryption and decryption using the Wheatstone-Playfair cipher. + +=cut + +use v5.16; + +use constant WP_ENCRYPT => 1; +use constant WP_DECRYPT => -1; + +use Test::More; + +is(encrypt('playfair example', 'hide the gold in the tree stump'), 'bmodzbxdnabekudmuixmmouvif'); +is(decrypt('perl and raku', 'siderwrdulfipaarkcrw'), 'thewexeklychallengex'); + +done_testing(); + + +sub encrypt ($$) { + _wpCrypt($_[0],$_[1],WP_ENCRYPT); +} + + +sub decrypt ($$) { + _wpCrypt($_[0],$_[1],WP_DECRYPT); +} + + +sub _wpCrypt ($$$) { + my ($key,$text,$mode) = (lc $_[0], lc $_[1], $_[2]); + + my ($hrC2L,$arL2C,@return); + + # Remove spaces from key + $key =~ s/\s//g; + + my @keyChars = split//,$key; + my %chars = map { $_ => 1 } ('a' .. 'z'); + my %usedChars; + + # Build encryption matrix + for my $row (0..4) { + for my $col (0..4) { + my $char; + do { + $char = (scalar @keyChars ? shift @keyChars : (sort keys %chars)[0]); + delete $chars{$char}; + delete $chars{j} if $char eq 'i'; + delete $chars{i} if $char eq 'j'; + } while (exists $usedChars{$char}); + $hrC2L->{$char} = [$row,$col]; + $arL2C->[$row][$col] = $char; + $usedChars{$char} = 1; + $usedChars{j} = 1 if $char eq 'i'; + $usedChars{i} = 1 if $char eq 'j'; + } + } + + # Remove spaces from text + $text =~ s/\s//g; + + # On ecryption, insert 'x' before repeating characters + $text =~ s/(.)(?=\1)/$1x/g + if $mode == WP_ENCRYPT; + + # Process per 2 chars of plaintext + while ($text =~ s#^(.)(.)?##c) { + my ($char1,$char2) = ($1, $2 // 'x'); + + my ($c1,$c2) = ($hrC2L->{$char1},$hrC2L->{$char2}); + + # Coords form rectangle? + if ($c1->[0] != $c2->[0] and $c1->[1] != $c2->[1]) { + push(@return,$arL2C->[$c1->[0]][$c2->[1]]); + push(@return,$arL2C->[$c2->[0]][$c1->[1]]); + } elsif ($c1->[0] == $c2->[0]) { + # row + push(@return,$arL2C->[$c1->[0]][($c1->[1]+$mode)%5]); + push(@return,$arL2C->[$c2->[0]][($c2->[1]+$mode)%5]); + } else { + # column + push(@return,$arL2C->[($c1->[0]+$mode)%5][$c1->[1]]); + push(@return,$arL2C->[($c2->[0]+$mode)%5][$c2->[1]]); + } + } + + return join('',@return); +} + + diff --git a/challenge-162/pokgopun/perl/ch-1.pl b/challenge-162/pokgopun/perl/ch-1.pl new file mode 100644 index 0000000000..8eaae334ba --- /dev/null +++ b/challenge-162/pokgopun/perl/ch-1.pl @@ -0,0 +1,20 @@ +use strict; +use warnings; + +### Each argument being passed to script must contain 13 or 12 decimal digits (i.e. ISBN-13 with 13 digits or 12 digits for 13th to be computed +### If not, deault to the ISBN-13 given in the pwc162's task#3 example +my @sample = @ARGV && @ARGV == scalar(grep{$_ =~ /^(?:12|13)$/} map{scalar @{[$_ =~ /(\d)/g]} } @ARGV) ? @ARGV : ("978-0-306-40615-7"); + +### Extract only decimal digits for further processing +foreach (map{join "", $_ =~ /(\d)/g} @sample) { + + ### From https://en.wikipedia.org/wiki/ISBN#ISBN-13_check_digit_calculation + ### r = (10 - (x1 + 3*x2 + x3 + 3*x4 + ... +x11 + 3x12) mod 10) + my $r = 10 - eval(join(" + ", map{$_->[0]." + 3*".$_->[1]} map{[split //, $_]} $_ =~ /(\d\d)/g)) % 10; + + ### Convert AAABCCCDDDDDE to AAA-B-CCC-DDDDD-E + $_ = join "-", $_ =~ /^(\d{3})(\d)(\d{3})(\d{5})(.?)/; + + ### x13 = r, r < 10 or x13 = 0, r = 10 + printf "ISBN-13 check digit for '%s' is %d.\n", $_, $r < 10 ? $r : 0; +} diff --git a/challenge-162/pokgopun/perl/ch-2.pl b/challenge-162/pokgopun/perl/ch-2.pl new file mode 100644 index 0000000000..09a72039fb --- /dev/null +++ b/challenge-162/pokgopun/perl/ch-2.pl @@ -0,0 +1,70 @@ +use strict; +use warnings; +my $debug = 0; + +my($key,$msg2encrypt) = @ARGV ? @ARGV : ("playfair example", "hide the gold in the tree stump"); +$key = lc($key); +$msg2encrypt = lc($msg2encrypt); +my $converter = genConverter($key); +my $msg2decrypt = &$converter($msg2encrypt); +printf 'encrypt("%s", "%s") = "%s"'."\n\n", $key, $msg2encrypt, $msg2decrypt; +unless (@ARGV){ + $key = "perl and raku"; + $converter = genConverter($key); + $msg2decrypt = "siderwrdulfipaarkcrw"; +} +printf 'decrypt("%s", "%s") = "%s"'."\n\n", $key, $msg2decrypt, &$converter($msg2decrypt,1); + +sub genConverter{ + my $key = shift; + my %seen; + my @c; + my ($i,$j) = (0,0); + foreach ( ( $key =~ /(\w)/g, 'a'..'z') ) { + next if $seen{$_}; + if ( $_ eq 'i' || $_ eq 'j') { + $seen{i}=[$i,$j]; + $seen{j}=[$i,$j]; + } else { + $seen{$_}=[$i,$j]; + } + $c[$i][$j] = $_; + $j++; + unless ($j < 5) { + $j = 0; + $i++; + } + last unless $i < 5; + } + if ($debug){ + print join(" ", @$_)."\n" foreach @c; + printf("%s => (%s)\n", $_, join(", ",@{$seen{$_}})) foreach sort{$a cmp $b} keys %seen; + printf "%d\n", scalar(keys %seen); + } + return sub{ + my $msg = shift; + my $o = -1; + unless (@_){ + $msg =~ s/\s//g; + $msg =~ s/(\w)(\1)/$1x$2/g; + $msg .= 'x' if length($msg) % 2; + $o = 1; + } + my @res; + foreach my $pair ($msg =~ /(\w\w)/g){ + my($a,$b) = @seen{$pair =~ /(\w)(\w)/}; + #printf "$pair => (%s),(%s)\n", join(", ",@$a), join(", ",@$b); + my($w,$h) = ($a->[1] - $b->[1], $a->[0] - $b->[0]); + #printf "$pair => %s\n", $w==0 ? "column" : $h==0 ? "row" : "rectangle"; + if ($w==0){ + push @res, $c[($a->[0]+$o)%5][$a->[1]], $c[($b->[0]+$o)%5][$b->[1]]; + } elsif ($h==0){ + push @res, $c[$a->[0]][($a->[1]+$o)%5], $c[$b->[0]][($b->[1]+$o)%5]; + } else { + push @res, $c[$a->[0]][$a->[1]-$w], $c[$b->[0]][$b->[1]+$w]; + } + #printf "$pair => %s\n", join("",@res[-2,-1]); + } + return join("",@res); + } +} diff --git a/challenge-162/roger-bell-west/javascript/ch-1.js b/challenge-162/roger-bell-west/javascript/ch-1.js new file mode 100755 index 0000000000..352d732648 --- /dev/null +++ b/challenge-162/roger-bell-west/javascript/ch-1.js @@ -0,0 +1,52 @@ +#! /usr/bin/node + +function generate(in0) { + let in1 = in0.replace(/[^0-9]+/g,"") + if (in1.length < 12) { + return 99 + } + in1 = in1.substring(0,12) + let s = 0 + let m = 1 + for (let i of String(in1)) { + s += parseInt(i) * m + m = 4 - m + } + return (10-(s % 10)) % 10 +} + +function validate(in0) { + let in1 = in0.replace(/[^0-9]+/g,"") + if (in1.length < 13) { + return false + } + return generate(in1) == parseInt(in1.charAt(12)) +} + +if (generate("978-0-306-40615-") == 7) { + process.stdout.write("Pass") +} else { + process.stdout.write("FAIL") +} +process.stdout.write(" "); + +if (generate("978-0-306-40615-7") == 7) { + process.stdout.write("Pass") +} else { + process.stdout.write("FAIL") +} +process.stdout.write(" "); + +if (validate("978-0-306-40615-7") == true) { + process.stdout.write("Pass") +} else { + process.stdout.write("FAIL") +} +process.stdout.write(" "); + +if (validate("978-0-306-46015-7") == false) { + process.stdout.write("Pass") +} else { + process.stdout.write("FAIL") +} +process.stdout.write("\n"); diff --git a/challenge-162/roger-bell-west/javascript/ch-2.js b/challenge-162/roger-bell-west/javascript/ch-2.js new file mode 100755 index 0000000000..adfa0aa2dc --- /dev/null +++ b/challenge-162/roger-bell-west/javascript/ch-2.js @@ -0,0 +1,100 @@ +#! /usr/bin/node + +function posmod(a,b) { + let m = a % b + while (m < 0) { + m += b + } + return m +} + +function playfair(dir,kwi0,input) { + let kw = "" + let k = new Map() + let kwi = kwi0.toLowerCase().replace(/[^a-z]+/g,"") + for (let lx = 'a'.charCodeAt(0); lx <= 'z'.charCodeAt(0); lx++) { + kwi = kwi + String.fromCharCode(lx) + } + for (let char0 of kwi.split("")) { + let char1 = char0 + if (char1 == 'j') { + char1 = 'i' + } + if (!k.has(char1)) { + k.set(char1,true) + kw = kw + char1 + } + } + let grid = [] + let gc = new Map() + let index = 0 + for (let row = 0; row <= 4; row++) { + let r = [] + for (let column = 0; column <= 4; column++) { + r.push(kw.charAt(index)) + gc.set(kw.charAt(index),[row,column]) + index++ + } + grid.push(r) + } + let ii = input.toLowerCase().replace(/[^a-z]+/g,"").replace(/j/g,"i") + let out = "" + index = 0 + while (index < ii.length) { + let ca = ii.charAt(index) + let cb = "x" + if (index + 1 < ii.length) { + cb = ii.charAt(index+1) + } + index += 2 + if (ca == cb) { + cb = "x" + index-- + } + let car = gc.get(ca)[0] + let cac = gc.get(ca)[1] + let cbr = gc.get(cb)[0] + let cbc = gc.get(cb)[1] + let oar = car + let oac = cac + let obr = cbr + let obc = cbc + if (car == cbr) { + oac = posmod(cac + dir, 5) + obc = posmod(cbc + dir, 5) + } else if (cac == cbc) { + oar = posmod(car + dir, 5) + obr = posmod(cbr + dir, 5) + } else { + oac = cbc + obc = cac + } + out = out + grid[oar][oac] + out = out + grid[obr][obc] + } + return out +} + +function encrypt(kw,plaintext) { + return playfair(1,kw,plaintext) +} + +function decrypt(kw,ciphertext) { + return playfair(-1,kw,ciphertext) +} + +if (encrypt("playfair example","hide the gold in the tree stump") == + "bmodzbxdnabekudmuixmmouvif") { + process.stdout.write("Pass") +} else { + process.stdout.write("FAIL") +} +process.stdout.write(" "); + +if (decrypt("perl and raku","siderwrdulfipaarkcrw") == + "thewexeklychallengex") { + process.stdout.write("Pass") +} else { + process.stdout.write("FAIL") +} +process.stdout.write("\n"); diff --git a/challenge-162/roger-bell-west/kotlin/ch-1.kt b/challenge-162/roger-bell-west/kotlin/ch-1.kt new file mode 100644 index 0000000000..fc35aa2bde --- /dev/null +++ b/challenge-162/roger-bell-west/kotlin/ch-1.kt @@ -0,0 +1,51 @@ +fun generate(in0: String): Int { + val re = "[^0-9]+".toRegex() + var in1 = re.replace(in0,"") + if (in1.length < 12) { + return 99 + } + in1 = in1.substring(0..11) + var s = 0 + var m = 1 + for (i in in1.toCharArray().toList()) { + s += m * i.digitToInt() + m = 4 - m + } + return (10-(s % 10)) % 10 +} + +fun validate(in0: String): Boolean { + val re = "[^0-9]+".toRegex() + var in1 = re.replace(in0,"") + if (in1.length != 13) { + return false + } + return generate(in1) == in1.get(12).digitToInt() +} + +fun main() { + if (generate("978-0-306-40615-") == 7) { + print("Pass") + } else { + print("FAIL") + } + print(" ") + if (generate("978-0-306-40615-7") == 7) { + print("Pass") + } else { + print("FAIL") + } + print(" ") + if (validate("978-0-306-40615-7") == true) { + print("Pass") + } else { + print("FAIL") + } + print(" ") + if (validate("978-0-306-46015-7") == false) { + print("Pass") + } else { + print("FAIL") + } + println("") +} diff --git a/challenge-162/roger-bell-west/kotlin/ch-2.kt b/challenge-162/roger-bell-west/kotlin/ch-2.kt new file mode 100644 index 0000000000..bf1fe865ac --- /dev/null +++ b/challenge-162/roger-bell-west/kotlin/ch-2.kt @@ -0,0 +1,96 @@ +fun posmod(a: Int, b: Int): Int { + var m = a % b + while (m < 0) { + m = m + b + |
