호주 주 확장


9

8 개의 호주 주와 테리토리가 있으며 각각 2 자 또는 3 자의 약어가 있습니다 :

  • 행동 : 호주 수도권
  • NSW : 뉴 사우스 웨일즈
  • NT : 노던 테리토리
  • QLD : 퀸즐랜드
  • SA : 남호주
  • TAS : 태즈 매니아
  • VIC : 빅토리아
  • WA : 서호주

귀하의 임무는 대문자로 유효한 호주 약어를 사용하고 올바른 전체 이름을 반환하는 함수 / 프로그램을 작성하는 것입니다 (위와 같이 대소 문자 구분).

해당 언어의 모든 프로그램에서 피할 수없는 부작용 인 단일 후행 줄 바꿈 이외의 추가 공백은 허용되지 않습니다.

예를 들면 다음과 같습니다.

f("TAS") => "Tasmania"

표준 규칙 (바이트 단위의 가장 짧은 코드가 승리합니다!) 및 허점이 적용됩니다.


6
이 시점에서 [ state-abbreviation ] 태그 를 만들어야한다고 생각 합니다.
Cyoce

"New South (Far) Wales"는 어떻습니까? (알지 못하는 사람들을 위해, 그것은 "NSFW"입니다)
NoOneIsHereJun

3
내가 해결책을 가지고 놀던 동안 NSW는 "New South Western ales"로 확장하고있었습니다. :)
Steve Bennett

기묘한. 태그를 만들어 추가했지만 다른 사람이 다시 제거했습니다.
Steve Bennett

상태 약어가 너무 구체적 일 수 있습니다. 아마도 약어 / 약어에 대해 태그를 만들 수 있습니까?
Sparr

답변:


9

망막 , 135121 바이트

@Neil 덕분에 영리한 공간 삽입 전술을 사용하여 13 바이트의 골프를 쳤다.

AS
asmania
^W
Western 
NT
NorthernT
T$
 Territory
A
Australia
aC
an Capital
IC
ictoria
LD
ueensland
SW
ew SWales
S
South 

온라인으로 사용해보십시오!

네 번째 줄과 마지막 줄의 후행 공백에 유의하십시오.


당신이 교체하는 경우 ASasmania첫째, 당신은 나머지 모든 대체 할 수 A와들 Australia.
Neil

다음과 같은 공간 삽입으로 창의력을 발휘할 수도 있습니다. 온라인으로 사용해보십시오!
Neil

(그러나 그것은 \B[A-Z]2 바이트를 절약했을 것입니다.)
Neil

@Neil 팁을 주셔서 감사합니다. 나는 당신의 제안을 1 바이트 더 골프하기 위해 사용했습니다.
user41805

5

젤리 , 56 바이트

OS%15ị“ÞÑṿ“ıÐṁṾṗ“¡ʋẹḢ⁾ḅ“¢T¡ż¶““msẒw²ẉṪP“ØÑĊ“©$Ḅ3ẊḳƓ“ÇH°»

문자 목록을 가져오고 리턴하는 모나드 링크.

온라인 에서 사용해보십시오!

참고 : "호주"및 "지역"이라는 단어를 재사용해도 바이트 수를 줄이는 데 도움이되지 않습니다.

어떻게?

8 개의 상태 약어 모듈로 15의 서수의 합을 취하면 8 개의 고유 한 값이 제공됩니다. 이러한 모듈로 9의 결과를 가져와 독창성을 유지합니다.

OS%15ị“ ... » - Main link: list of characters a
O             - cast to ordinals
 S            - sum
  %15         - modulo 15
      “ ... » - list of compressed strings:
              -   "Victoria"
              -   "Western Australia"
              -   "Northern Territory"
              -   "South Australia"
              -   ""
              -   "Australian Capital Territory"
              -   "Tasmania"
              -   "New South Wales"
              -   "Queensland"
     ị        - index into (1-indexed and modular - hence the single empty entry)

호주와 테리토리의 재사용이 도움이되지 않는다는 것이 슬프다 : /
Steve Bennett

5

하스켈, 193192 바이트

f"NSW"="New South Wales"
f"QLD"="Queensland"
f"ACT"=a++"n Capital"++t
f"VIC"="Victoria"
f"TAS"="Tasmania"
f"SA"="South "++a
f"NT"="Northern"++t
f"WA"="Western "++a
a="Australia"
t=" Territory"

다소 순진한 해결책이지만 첫 번째로 상당히 간단한 도전을 원했습니다. Haskell에서 더 나은지 확실하지 않습니다.

공백을 t로 이동하여 바이트를 저장했습니다.


1
PPCG에 오신 것을 환영합니다!
L3via6

3

Mathematica, 177 바이트

명백한 해결책 : (199 바이트)

<|"ACT"->"Australian Capital Territory","NSW"->"New South Wales","NT"->"Northern Territory","QLD"->"Queensland","SA"->"South Australia","TAS"->"Tasmania","VIC"->"Victoria","WA"->"Western Australia"|>

개선 된 솔루션 : (182 바이트, Wolfram Mathematica 10.2 컴퓨터에서만 실행 가능)

{,"Northern Territory","Queensland",,,,,"Australian Capital Territory","New South Wales",,,"Tasmania",,,"Western Australia","Victoria",,,,,,,,,,,,"South Australia"}[[Hash@#~Mod~29]]&

최고의 솔루션 :

{,"Northern Territory","Queensland",a="Australia",,,,a<>"n Capital Territory","New South Wales",,,"Tasmania",,,"Western "<>a,"Victoria",,,,,,,,,,,,"South "<>a}[[Hash@#~Mod~29]]&

불행히도 반복 " Territory"은 0 바이트 만 저장할 수 있습니다.

Mathematica의 기본 해시 기능이 버전을 변경 한 것으로 보입니다. 그러나 메소드를 추가하면 코드가 더 길어집니다. Mathematica 샌드 박스의 기본 해시 기능을 사용하면 코드를 약 9 바이트 더 짧게 만들 수 있습니다.

Mathematica (샌드 박스-현재-버전 11), 168 바이트

{a="Australia","Western "<>a,,,,"South "<>a,,a<>"n Capital Territory",,,,"Tasmania","Northern Territory",,,,"New South Wales","Victoria","Queensland"}[[Hash@#~Mod~20]]&

젠장, 사소한 대답보다 21 바이트 만 좋습니다.
Steve Bennett

5
잠깐, Mathematica는 이것에 대한 내장이 없습니까?
Neil

@Neil 나는 그것에 대해 먼저 생각 했어야했다.
user202729

2

파이썬, 181 바이트

@Jonathan Allan 덕분에 1 바이트 절약

lambda a,s='Australia',t=' Territory':[s+'n Capital'+t,'New South Wales','Northern'+t,'Queensland','South '+s,'Tasmania','Victoria','Western '+s]['ACNSNTQLSATAVIWA'.index(a[:2])//2]

온라인으로 사용해보십시오!


t=' Territory'내가 생각하는 바이트를 저장해야합니다.
Jonathan Allan

2

SED, 167 157 바이트

s/T$/ Territory/
s/N /Northern /
s/AS/asmania/
s/IC/ictoria/
s/LD/ueensland/
s/W$/Wales/
s/A/Australia/
s/C/n Capital/
s/NS/New S/
s/^W/Western /
s/S/South /

나는 원래 연기 ern 했지만 두 번만 사용하면 비용이 절약됩니다.
Toby Speight 2016 년


0

C # , 289 바이트


데이터

  • 입력 String s 상태의 약어.
  • 출력 String 확장 된 상태 이름

골프

(string s)=>{return new System.Collections.Generic.Dictionary<string,string>(){{"ACT","Australian Capital Territory"},{"NSW","New South Wales"},{"NT","Northern Territory"},{"QLD","Queensland"},{"SA","South Australia"},{"TAS","Tasmania"},{"VIC","Victoria"},{"WA","Western Australia"}}[s];};

언 골프

( string s ) => {
    return new System.Collections.Generic.Dictionary<string, string>() {
        { "ACT", "Australian Capital Territory" },
        { "NSW", "New South Wales" },
        { "QLD", "Queensland" },
        { "TAS", "Tasmania" },
        { "VIC", "Victoria" },
        { "NT", "Northern Territory" },
        { "SA", "South Australia" },
        { "WA", "Western Australia" }
    }[ s ];
};

언 골프 가능

// Takes a state name abbreviated 
( string s ) => {

    // Creates a dictionary with the state name abbreviated and the full state name and returns the one that match
    return new System.Collections.Generic.Dictionary<string, string>() {
        { "ACT", "Australian Capital Territory" },
        { "NSW", "New South Wales" },
        { "QLD", "Queensland" },
        { "TAS", "Tasmania" },
        { "VIC", "Victoria" },
        { "NT", "Northern Territory" },
        { "SA", "South Australia" },
        { "WA", "Western Australia" }
    }[ s ];
};

전체 코드

using System;
using System.Collections.Generic;

namespace Namespace {
   class Program {
      static void Main( String[] args ) {
         Func<String, String> f = ( string s ) => {
             return new System.Collections.Generic.Dictionary<string, string>() {
                 { "ACT", "Australian Capital Territory" },
                 { "NSW", "New South Wales" },
                 { "QLD", "Queensland" },
                 { "TAS", "Tasmania" },
                 { "VIC", "Victoria" },
                 { "NT", "Northern Territory" },
                 { "SA", "South Australia" },
                 { "WA", "Western Australia" }
             }[ s ];
         };

         List<String>
             testCases = new List<String>() {
                 "ACT",
                 "NSW",
                 "QLD",
                 "TAS",
                 "VIC",
                 "NT",
                 "SA",
                 "WA",
             };

         foreach( String testCase in testCases ) {
             Console.WriteLine( $"Input: {testCase}\nOutput: {f( testCase )}\n");
         }

         Console.ReadLine();
      }
   }
}

자료

  • V1.0 - 289 bytes- 초기 솔루션입니다.

노트

  • 없음

(string s)단지 할 수있다 s, 당신은 암시 적 수익을 사용할 수 있습니다 : s=>new System....당신은 뒤에 세미콜론을 제거 할 수 있습니다.
TheLethalCoder


0

자바 스크립트 (ES6), 167 바이트

s=>({A:`${A='Australia'}n Capital ${T='Territory'}`,N:s[2]?'New South Wales':'Northern '+T,T:'Tasmania',Q:'Queensland',S:'South '+A,V:'Victoria',W:'Western '+A}[s[0]])

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.