A wayward human has entered the Forest of the Lost- a forest renowned for having monsters of the worst variety.
Given the coordinates of the human, the coordinates of a monster, and the monster's attack span return whether the human is deciminated or if he lives to see another day.
ex. DeadOrAlive([3, 4], [3, 6], 1) == 'Alive!';
ex. DeadOrAlive([7, 6], [3, 6], 5) == 'Dead!';
Things to keep in mind:
- The span will always be a whole number
- Human and monster can have the same coordinates
String DeadOrAlive(List<int> human, List<int> monster, int span) {
return ((monster[0] - human[0]).abs() <= span && (monster[1] - human[1]).abs() <= span) ? 'Dead!' : 'Alive!';
}
// See https://pub.dartlang.org/packages/test
import "package:test/test.dart";
import "package:solution/solution.dart";
void main() {
test("DeadOrAlive", () {
expect(DeadOrAlive([3, 4], [3, 6], 1), equals('Alive!'));
});
test("DeadOrAlive", () {
expect(DeadOrAlive([7, 6], [3, 6], 5), equals('Dead!'));
});
test("DeadOrAlive", () {
expect(DeadOrAlive([79, 6], [3, 69], 80), equals('Dead!'));
});
test("DeadOrAlive", () {
expect(DeadOrAlive([13, 50], [3, 6], 50), equals('Dead!'));
});
test("DeadOrAlive", () {
expect(DeadOrAlive([0, 0], [4, 0], 3), equals('Alive!'));
});
}
Palindrome:
A palindrome is a word that when reversed reads the same. An example is "evil rats star live."
Valid palindromes should output 'TRUE' while invalid ones should output 'FALSE'.
function palindrome (x) {
let s = x.split('').reverse().join('')
return x == s ? "TRUE" : "FALSE"
}
Test.assertEquals(palindrome('evil rats star live'), "TRUE");
Test.assertEquals(palindrome('Owu'), "FALSE");
Test.assertEquals(palindrome('level'), "TRUE");
Test.assertEquals(palindrome('uwu'), "TRUE");
Test.assertEquals(palindrome('stressed desserts'), "TRUE");