Skip to main content
Tweeted twitter.com/StackCodeGolf/status/965022347257417728
edited body
Source Link
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282

First, you need to know the default form of largesome parts used in larger numbers.:

When koreansKoreans pronounce big numbers

First, you need to know the default form of large numbers.

When koreans pronounce big numbers

First, you need to know some parts used in larger numbers:

When Koreans pronounce big numbers

Typo
Source Link
user202729
  • 17.4k
  • 2
  • 37
  • 70

TechinicalTechnical details (Small)

Techinical details (Small)

Technical details (Small)

Source Link
0xrgb
  • 107
  • 8

Convert a number to Korean

Goal

You will be given a positive integer number less than 10^20. You must convert it to Korean.

For example, if the input is 12345, the output should be 일만이천삼백사십오.

Techinical details (Small)

Let's starts with simple numbers.

// 1 - 9
1 -> 일
2 -> 이
3 -> 삼
4 -> 사
5 -> 오
6 -> 육
7 -> 칠
8 -> 팔
9 -> 구

// 10, 100, 1000
10 -> 십
100 -> 백
1000 -> 천

You can concatenate 2 ~ 9 front of 10, 100, 1000.
However, you should not concatenate 1 front of 10, 100, 1000.

// 20 = 2 * 10
20 -> 이십

// 300 = 3 * 100
300 -> 삼백

// 9000 = 9 * 1000
9000 -> 구천

// 1000 is just 1000
1000 -> 천

For integer less than 10000, below rule is used for pronunciation.

// 1234 = 1000 + 200 + 30 + 4
1234 -> 천이백삼십사

// 1002 = 1000 + 2
1002 -> 천이

// 2048 = 2000 + 40 + 8
2048 -> 이천사십팔

// 510 = 500 + 10
510 -> 오백십

// 13 = 10 + 3
13 -> 십삼

Technical details (Large)

Now let's go to the hard part.

First, you need to know the default form of large numbers.

1 0000 -> 만
1 0000 0000 -> 억
1 0000 0000 0000 -> 조
1 0000 0000 0000 0000 -> 경

When koreans pronounce big numbers

  1. Cut it with width 4
  2. Convert each of them using methods for less than 10000
  3. Combine them with default form of big numbers

Here is some detailed examples. (I added some space to korean for readability)

// 12345678 = 1234 5678
// 1234 -> 천이백삼십사
// 5678 -> 오천육백칠십팔
12345678 -> 천이백삼십사 만 오천육백칠십팔

// 11122223333 = 111 2222 3333
// 111 -> 백십일
// 2222 -> 이천이백이십이
// 3333 -> 삼천삼백삼십삼
11122223333 -> 백십일 억 이천이백이십이 만 삼천삼백삼십삼

// 10900000014 = 109 0000 0014
// 109 -> 백구
// 0000 -> (None)
// 0014 -> 십사
10900000014 -> 백구 억 십사

// 100000000 -> 1 0000 0000
// 1 -> 일
// 0000 -> (None)
// 0000 -> (None)
100000000 -> 일 억

Here are some more examples.

Rule

You can make your program gets input from stdin and output to stdout, or make a function that gets string/integer and returns string.

This is , so answers will be scored in bytes with fewer bytes being better.