mirror of
https://github.com/aljazceru/cryptoanarchywiki.github.io.git
synced 2025-12-17 05:04:21 +01:00
added posts
This commit is contained in:
@@ -42,8 +42,8 @@ urls:
|
||||
|
||||
url: "https://agusmakmun.github.io"
|
||||
baseurl: ""
|
||||
paginate: 15
|
||||
per_page: 15
|
||||
paginate: 20
|
||||
per_page: 20
|
||||
paginate_path: "/page:num/"
|
||||
markdown: kramdown
|
||||
gems:
|
||||
|
||||
@@ -13,7 +13,7 @@ Next, each substring with length greater than one is replaced with a concatenati
|
||||
for example, substring `"bbb"` is replaced by `"3b"`
|
||||
Finally, all the new strings are concatenated together in the same order and a new string is returned.
|
||||
|
||||
####SUBSTRING
|
||||
#### SUBSTRING
|
||||
|
||||
A **substring** of a string `S` is another string `S'` that occurs in `S`. For example, `"Fights"` is a substring of `"CodeFights"`, but `"CoFi"` isn't.
|
||||
|
||||
@@ -23,14 +23,12 @@ For `s = "aabbbc"`, the output should be `lineEncoding(s) = "2a3bc"`.
|
||||
|
||||
**Input/Output**
|
||||
|
||||
* [time limit] 4000ms (py)
|
||||
* [input] string s (String consisting of lowercase English letters.)
|
||||
* [time limit] 4000ms (py)
|
||||
* [input] string s (String consisting of lowercase English letters.)
|
||||
|
||||
_Constraints:_ `4 ≤ s.length ≤ 15.`
|
||||
_Constraints:_ `4 ≤ s.length ≤ 15.`
|
||||
|
||||
* [output] string
|
||||
|
||||
Encoded version of s.
|
||||
* [output] string (Encoded version of s.)
|
||||
|
||||
**Solution:**
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
---
|
||||
layout: post
|
||||
title: "Find the number of even digits in the given integer [CF]"
|
||||
date: 2016-06-11 03:39:03 +0700
|
||||
categories: [python, codefights]
|
||||
---
|
||||
|
||||
Find the number of even digits in the given integer.
|
||||
|
||||
**Example**
|
||||
|
||||
* For `n = 1010`, the output should be `numberOfEvenDigits(n) = 2`.
|
||||
* For `n = 123`, the output should be `numberOfEvenDigits(n) = 1`.
|
||||
|
||||
**Input/Output**
|
||||
|
||||
* [time limit] 4000ms (py)
|
||||
* [input] integer n (A positive integer).
|
||||
|
||||
**_Constraints:_**
|
||||
|
||||
* 1 ≤ n ≤ 106.
|
||||
|
||||
* **[output] integer**
|
||||
|
||||
**My Solution:**
|
||||
|
||||
```python
|
||||
def numberOfEvenDigits(n):
|
||||
return len(filter(lambda m: m.isdigit() and int(m) % 2 == 0, str(n)))
|
||||
```
|
||||
|
||||
**Rests Tests:**
|
||||
|
||||
```
|
||||
n: 1010
|
||||
Output: 2
|
||||
|
||||
n: 123
|
||||
Output: 1
|
||||
|
||||
n: 135
|
||||
Output: 0
|
||||
```
|
||||
48
_posts/2016-06-11-get-month-name-cf.md
Normal file
48
_posts/2016-06-11-get-month-name-cf.md
Normal file
@@ -0,0 +1,48 @@
|
||||
---
|
||||
layout: post
|
||||
title: "get Month Name [CF]"
|
||||
date: 2016-06-11 03:43:45 +0700
|
||||
categories: [python, codefights]
|
||||
---
|
||||
|
||||
Map the given integer to a month.
|
||||
|
||||
**Example:**
|
||||
|
||||
* For `mo = 1`, the output should be `getMonthName(mo) = "Jan"`,
|
||||
* For `mo = 0`, the output should be `getMonthName(mo) = "invalid month"`.
|
||||
|
||||
**Input/Output**
|
||||
|
||||
* [time limit] 4000ms (py)
|
||||
* [input] integer mo (A non-negative integer).
|
||||
* **Constraints:** `0 ≤ mo ≤ 15`.
|
||||
* **[output] string**
|
||||
|
||||
A `3`-letter abbreviation of month number `mo` or `"invalid month"` if the month doesn't exist.
|
||||
|
||||
Here are abbreviations of all months:
|
||||
|
||||
**My Solution:**
|
||||
|
||||
```python
|
||||
def getMonthName(mo):
|
||||
months = {
|
||||
1: "Jan", 2: "Feb", 3: "Mar", 4:"Apr",
|
||||
5: "May", 6: "Jun", 7: "Jul", 8:"Aug",
|
||||
9: "Sep", 10: "Oct", 11: "Nov", 12: "Dec"
|
||||
}
|
||||
if mo in months.keys():
|
||||
return months.get(mo)
|
||||
return "invalid month"
|
||||
```
|
||||
|
||||
**Result Tests**:
|
||||
|
||||
```python
|
||||
>>> getMonthName(1)
|
||||
"Jan"
|
||||
>>> getMonthName(0)
|
||||
"invalid month"
|
||||
>>>
|
||||
```
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 65 KiB |
Reference in New Issue
Block a user