Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions challenge-348/roger-bell-west/crystal/ch-1.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#! /usr/bin/crystal

def stringalike(a)
if a.size % 2 == 1
return false
end
vt = 0
mode = 1
av = false
a.downcase.chars.each_with_index do |c, i|
if i * 2 == a.size
mode = -1
end
if c.in_set?("aeiou")
vt += mode
av = true
end
end
av && (vt == 0)
end

require "spec"
describe "stringalike" do
it "test_ex1" do
stringalike("textbook").should eq false
end
it "test_ex2" do
stringalike("book").should eq true
end
it "test_ex3" do
stringalike("AbCdEfGh").should eq true
end
it "test_ex4" do
stringalike("rhythmmyth").should eq false
end
it "test_ex5" do
stringalike("UmpireeAudio").should eq false
end
end
40 changes: 40 additions & 0 deletions challenge-348/roger-bell-west/crystal/ch-2.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#! /usr/bin/crystal

def hm2m(a)
p = a.split(":")
return p[0].to_i * 60 + p[1].to_i
end

def converttime(ssrc, ttgt)
src = hm2m(ssrc)
tgt = hm2m(ttgt)
if tgt < src
tgt += 24 * 60
end
delta = tgt - src
oc = 0
[60, 15, 5, 1].each do |op|
q, delta = delta.divmod(op)
oc += q
end
oc
end

require "spec"
describe "converttime" do
it "test_ex1" do
converttime("02:30", "02:45").should eq 1
end
it "test_ex2" do
converttime("11:55", "12:15").should eq 2
end
it "test_ex3" do
converttime("09:00", "13:00").should eq 4
end
it "test_ex4" do
converttime("23:45", "00:30").should eq 3
end
it "test_ex5" do
converttime("14:20", "15:25").should eq 2
end
end
53 changes: 53 additions & 0 deletions challenge-348/roger-bell-west/javascript/ch-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#! /usr/bin/node

"use strict"

function stringalike(a) {
if (a.length % 2 == 1) {
return false;
}
let vt = 0;
let mode = 1;
let av = false;
a.toLowerCase().split("").forEach((c, i) => {
if (i * 2 == a.length) {
mode = -1;
}
if (c.match(/[aeiou]/)) {
av = true;
vt += mode;
}
});
return av && (vt == 0);
}

if (!stringalike('textbook')) {
process.stdout.write("Pass");
} else {
process.stdout.write("FAIL");
}
process.stdout.write(" ");
if (stringalike('book')) {
process.stdout.write("Pass");
} else {
process.stdout.write("FAIL");
}
process.stdout.write(" ");
if (stringalike('AbCdEfGh')) {
process.stdout.write("Pass");
} else {
process.stdout.write("FAIL");
}
process.stdout.write(" ");
if (!stringalike('rhythmmyth')) {
process.stdout.write("Pass");
} else {
process.stdout.write("FAIL");
}
process.stdout.write(" ");
if (!stringalike('UmpireeAudio')) {
process.stdout.write("Pass");
} else {
process.stdout.write("FAIL");
}
process.stdout.write("\n");
54 changes: 54 additions & 0 deletions challenge-348/roger-bell-west/javascript/ch-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#! /usr/bin/node

"use strict"

function hm2m(a) {
const p = a.match(/(\d+):(\d+)/);
return parseInt(p[1]) * 60 + parseInt(p[2]);
}

function converttime(ssrc, ttgt) {
const src = hm2m(ssrc);
let tgt = hm2m(ttgt);
if (tgt < src) {
tgt += 24 * 60;
}
let delta = tgt - src;
let oc = 0;
for (let op of [60, 15, 5, 1]) {
oc += Math.floor(delta / op);
delta %= op;
}
return oc;
}

if (converttime('02:30', '02:45') == 1) {
process.stdout.write("Pass");
} else {
process.stdout.write("FAIL");
}
process.stdout.write(" ");
if (converttime('11:55', '12:15') == 2) {
process.stdout.write("Pass");
} else {
process.stdout.write("FAIL");
}
process.stdout.write(" ");
if (converttime('09:00', '13:00') == 4) {
process.stdout.write("Pass");
} else {
process.stdout.write("FAIL");
}
process.stdout.write(" ");
if (converttime('23:45', '00:30') == 3) {
process.stdout.write("Pass");
} else {
process.stdout.write("FAIL");
}
process.stdout.write(" ");
if (converttime('14:20', '15:25') == 2) {
process.stdout.write("Pass");
} else {
process.stdout.write("FAIL");
}
process.stdout.write("\n");
60 changes: 60 additions & 0 deletions challenge-348/roger-bell-west/kotlin/ch-1.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
fun is_vowel(c: Char): Boolean {
return when (c.lowercaseChar()) {
'a', 'e', 'i', 'o', 'u' -> true
else -> false
}
}

fun stringalike(a: String): Boolean {
if (a.length % 2 == 1) {
return false
}
var vt = 0
var mode = 1
var av = false
a.toList().forEachIndexed { i, c ->
if (i * 2 == a.length) {
mode = -1
}
if (is_vowel(c)) {
av = true
vt += mode
}
}
return av && (vt == 0)
}

fun main() {

if (!stringalike("textbook")) {
print("Pass")
} else {
print("Fail")
}
print(" ")
if (stringalike("book")) {
print("Pass")
} else {
print("Fail")
}
print(" ")
if (stringalike("AbCdEfGh")) {
print("Pass")
} else {
print("Fail")
}
print(" ")
if (!stringalike("rhythmmyth")) {
print("Pass")
} else {
print("Fail")
}
print(" ")
if (!stringalike("UmpireeAudio")) {
print("Pass")
} else {
print("Fail")
}
println("")

}
55 changes: 55 additions & 0 deletions challenge-348/roger-bell-west/kotlin/ch-2.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

fun hm2m(a: String): Int {
val p = a.split(":")
return p[0].toInt() * 60 + p[1].toInt()
}

fun converttime(ssrc: String, ttgt: String): Int {
val src = hm2m(ssrc)
var tgt = hm2m(ttgt)
if (tgt < src) {
tgt += 24 * 60
}
var delta: Int = tgt - src
var oc = 0
for (op in listOf(60, 15, 5, 1)) {
oc += delta / op
delta %= op
}
return oc
}

fun main() {

if (converttime("02:30", "02:45") == 1) {
print("Pass")
} else {
print("Fail")
}
print(" ")
if (converttime("11:55", "12:15") == 2) {
print("Pass")
} else {
print("Fail")
}
print(" ")
if (converttime("09:00", "13:00") == 4) {
print("Pass")
} else {
print("Fail")
}
print(" ")
if (converttime("23:45", "00:30") == 3) {
print("Pass")
} else {
print("Fail")
}
print(" ")
if (converttime("14:20", "15:25") == 2) {
print("Pass")
} else {
print("Fail")
}
println("")

}
75 changes: 75 additions & 0 deletions challenge-348/roger-bell-west/lua/ch-1.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#! /usr/bin/lua

function split(t)
local cl = {}
string.gsub(t,
"(.)",
function(c)
table.insert(cl, c)
end
)
return cl
end

function is_vowel(c)
if string.find(c, "[aeiou]") == 1 then
return true
else
return false
end
end

function stringalike(a)
if #a % 2 == 1 then
return false
end
local vt = 0
local mode = 1
local av = false
for i,c in ipairs(split(string.lower(a))) do
if is_vowel(c) then
av = true
vt = vt + mode
end
if i * 2 == #a then
mode = -1
end
end
return av and (vt == 0)
end

if not stringalike("textbook") then
io.write("Pass")
else
io.write("FAIL")
end
io.write(" ")

if stringalike("book") then
io.write("Pass")
else
io.write("FAIL")
end
io.write(" ")

if stringalike("AbCdEfGh") then
io.write("Pass")
else
io.write("FAIL")
end
io.write(" ")

if not stringalike("rhythmmyth") then
io.write("Pass")
else
io.write("FAIL")
end
io.write(" ")

if not stringalike("UmpireeAudio") then
io.write("Pass")
else
io.write("FAIL")
end
print("")

Loading