Skip to content

Instantly share code, notes, and snippets.

View TheAlienMann's full-sized avatar
🎯
Focusing

Mohamad Rahmani TheAlienMann

🎯
Focusing
View GitHub Profile
@TheAlienMann
TheAlienMann / README.md
Created August 17, 2023 17:19 — forked from IsaacXen/README.md
(Almost) Every WWDC videos download links for aria2c.
@Override
public String replaceThe(String str) {
StringBuilder res = new StringBuilder();
String vo = "aeiou";
String[] part = str.split("the");
res.append(part[0]);
for (int i = 1; i < part.length; i++) {
if (vo.contains(part[i].trim().charAt(0) + "")) {
import kotlin.math.pow
override fun isNarcisstic(num: Int): Boolean {
return when {
num < 10 -> true
num < 100 -> false
else -> num == ("" + num).chars()
.map { cp -> Character.getNumericValue(cp).toDouble().pow(("" + num).length.toDouble()).toInt() }
.sum()
}
@TheAlienMann
TheAlienMann / EdabitChallenges3.java
Created September 8, 2020 14:25
print out the first n vowels in a given string
private static int countMatches(Matcher matcher) {
int counter = 0;
while (matcher.find())
counter++;
return counter;
}
@Override
public String firstNVowels(String str, int n) {
Pattern pattern = Pattern.compile("(?i)[aeiou]");
@TheAlienMann
TheAlienMann / Grab The City
Last active December 8, 2019 15:58
"Grab The City" is a challenge that wants you to extract the name of the city in a given sentence which the name is wrapped in a pair of square brackets in the end of the sentence.
func grabCity(_ str: String) -> String {
// the commented line below (the regex to be exact) gets just the last word! which is wrong, my fault though, i didn't read the challenge corectly!
// let regex = try! NSRegularExpression(pattern: "(\\w+)(?!.*\\w)", options: [])
// the regex below get every matches in the sentence that is being wrapped in a pair of square brackets.
let regex = try! NSRegularExpression(pattern: "(?<=\\[)(.+?)(?=\\])", options: [])
// the "result" below is of type NSTextCheckingResult which is an array, since the challenge askes for the last match, and i couldn't get the last match through the regex, i ened up gtting the last match via the "last" item in the array.
let result = regex.matches(in: str, options: [], range: NSRange(location: 0, length: str.count)).last
/*
// from line 11 to 18, is an alternative for getting the matches out of the result array, since it is an array (of type NSTextCheckingResult) you can iterate thtough it (loop though it)
// you can use each o
@TheAlienMann
TheAlienMann / Grab The City
Created September 16, 2019 09:33
"Grab The City" is a challenge that wants you to extract the name of the city in a given sentence which the name is wrapped in pair of square bracket
func grabCity(_ str: String) -> String {
// let regex = try! NSRegularExpression(pattern: "(\\w+)(?!.*\\w)", options: [])
let regex = try! NSRegularExpression(pattern: "(?<=\\[)(.+?)(?=\\])", options: [])
let result = regex.matches(in: str, options: [], range: NSRange(location: 0, length: str.count)).last
/*
for match in result {
for n in 0..<match.numberOfRanges {
let range = match.range(at: n)
let r = str.index(str.startIndex, offsetBy: range.location)..<str.index(str.startIndex, offsetBy: range.location+range.length)
// print(#line, #file.components(separatedBy: "/").last!, str.substring(with: r))
func sumOfMultiplesOfThreeAndFiveBelowN(inputs: [UInt64?]) {
for input in inputs {
var res: UInt64 = 0
if let num = input, num > 0 {
for i in 1..<num {
if i % 3 == 0 || i % 5 == 0 || ((i % 3 == 0) && (i % 5 == 0)) {
res += i
}
}