回転しても安全な数字を印刷する


29

バックグラウンド

ボードゲームのメーカーで働いており、ゲームのために0からnまでの数字が刻まれた木製のタイルを作る必要があります。ただし、これ以上苦労しないと、一部のタイルは区別できなく6なり9ます。これを回避するには、曖昧さをなくすためのドットを他の(およびそれらとのみ)混同する可能性のある数字を装備する必要があります。たとえば、9.またはなどのタイルがあります6089.

残念ながら、これにはプログラム可能なすべての文字を手作業でエンコードしなければならない退屈なプロセスを必要とするインターフェイスが壊れている古いプログラム可能な木彫りデバイスを使用する必要があります。幸いなことに、デバイスはすべての既存のプログラミング言語を理解します。したがって、このようなタイルを印刷する最短のプログラムを探しています。

実際のタスク

次の最短プログラムを作成します。

  • 入力として正の整数nを取ります。入力の読み方はあなた次第です。
  • 出力し0からの数字のそれぞれのn(0およびnは正確に一度お好みの順番で含まれる)、(改行を含む)単一の空白文字で区切られています。数字は先行ゼロなしで印刷されます。
  • 数字がnより大きい場合でも、π(180°)回転すると、別の有効な数字になるすべての数字にドット(。)を追加します書体の0と8は回転対称で、9は回転6です。2と5は回転時に区別されます。1は回転対称ではありません。先行ゼロのある数字は無効です。

次の各番号は、この方法で正確に印刷する必要があります。

  • 2
  • 4
  • 5
  • 6.
  • 8
  • 9.
  • 16
  • 60
  • 66.
  • 68.
  • 69
  • 906
  • 909.
  • 8088.
  • 9806.
  • 9886
  • 9889.

すべきではない60こと60.
赤X 14

2
@ red-X「先行ゼロのある数字は無効です。」
Sp3000 14

2
@rationalis:これには標準的な抜け穴があります。(また、そのマシンにその言語を教える必要があるので、これはテーマ的に意味をなさないでしょう。)いずれにしても、既存のもの
Wrzlprmft 14

2
@rationalis一般的に起こることは、チャレンジの投稿前に存在する言語バージョンのみが勝者プログラムになる資格があるということです。以降に作成されたバージョンは、まだ楽しみのために投稿できますが、競合しないことを投稿で指定する必要があります。そのため、そのような言語定義することはできますが、その言語は不適格であり、標準の抜け穴であるため(上​​記のように)受け入れられない可能性が最も高いでしょう。
Sp3000 14

3
8088.6または9を持たない回転安全でない番号として例を含めると役立つと思います。
El'endiaStarman 14

回答:


6

パイス -34 38

VhQJ`N+J*\.&nJX_J`69`96&eN!-J"0689

4バイトの削除を支援してくれた@ Sp3000に感謝しなければなりません。私はもともと&@JK、数に6または9があることを確認する追加のチェックを持っていましたが、投稿する前に答えを熟読した後、私は彼の答えを読んで、私の同じ翻訳と逆転がすでにそれを処理していることに気付きました。

また、文字列は反復可能であることを指摘してくれた@isaacgにも感謝します。また、それらに対して集合演算を使用できます。また、現在のコードを作成するため;)

説明:

                                    : (implicit) Q=eval(input())
VhQ                                 : for N in range(Q+1):
   J`N                              : J=str(N)
      +J*\.                         : J + "." * ...
           &nJX_J`69`96             : J!=translate(reversed(J),"69","96") and...
                       &eN          : N%10 and...
                          !-J"0689  : not(setwise_difference(J, "0689"))

Kand に整数のリストを使用する必要はないと思いますJ-代わりに文字列を使用してください。K<backtick> 69およびJ<backtick> Nに切り替えるとK、結果のプログラムのインライン化と同様に、数文字が節約されます。そのテクニックで得られた最短はVhQJ``N+J*\.&nJX_J``69``96&eN!-J"068934文字でした。(2つのバック
ティック

@isaacgヒントをありがとう!何らかの理由で、 `を使用して数字の文字列を作成するのは本当に短いと忘れていたと思います。とにかく、\でエスケープすることにより、バックティックを使用してコードブロックを記述できます。例:hell`o wo`rld
FryAmTheEggman 14

説明では_、の前にが追加されているように見えます`96
isaacg 14

@isaacgありがとう、修正
FryAmTheEggman

10

CJam、46 44 43 42バイト

l~),{_A%g1$s_6890s-!\_69s_W%erW%=!&&'.*N}/

改善の余地があると思います。

ここでテストしてください。

説明

l~),{_A%g1$s_6890s-!\_69s_W%erW%=!&&'.*N}/
l~                                         "Read an eval input.";
  ),                                       "Get range from 0 to n.";
    {                                   }/ "For each...";
     _                                     "Get a copy of the integer.";
      A%g                                  "Ends with digit other than 0?";
         1$s_                              "Get another copy, convert to string, get a copy.";
             0689s-!                       "Contains rotation-safe digits?";
                    \                      "Swap with other copy.";
                     _                     "Get another copy.";
                      69s_W%er             "Swap 6 and 9.";
                              W%           "Reverse.";
                                =!         "Is different from original?";
                                  &&       "AND all three conditions.";
                                    '.*    "If true, push a period (else, an empty string).";
                                       N   "Push a newline.";

入力が8の場合、これは何を返しますか?(入力にコードを貼り付け、[実行]ボタンをクリックしましたが、エラーが呼び出されました。)
DavidC

@DavidCarraherは、コードを「コード」とn入力に入れました。
マーティンエンダー14

入力98では、プログラムは66の横にドットを置きますが、これは正しくありません。
スパー14

3
@Sparr回答が無効であると言う前に、OPが質問に回答するのを待つべきです。彼の声明:「以下の数字のそれぞれは、まさにこの方法で印刷されなければならない」とあなたの解釈は矛盾するようです。
FryAmTheEggman 14

私はCJamの説明の美しさが好きです。
nyuszika7h 14


5

APL 66

∊' ',¨{a←⌽'0.....9.86'[⎕D⍳b←⍕⍵]⋄'.'∊a:b⋄('0'=⊃a)∨⍵=⍎a:b⋄b,'.'}¨0,⍳

説明:

¨0,⍳           applies the function to each number 0-n
a←⌽'0.....9.86'[⎕D⍳b←⍕⍵] inverts 6s and 9s, leaving 8s and 0s, and replacing other numbers with dots. Reverses vector after substitution.
'.'∊a          if there is a dot in the number....
('0'=⊃a)       .. or if the number starts with 0...
⍵=⍎a           or if the (inverted) number is the same as original
:b             then print the original number
b,'.'          else print a dot in the end
∊' ',¨        Finally to give the result in the asked format i add a single space after each result and join them all 

tryapl.orgで試してください

オンラインインタープリターでは⍎関数が機能しないため、この場合も同じことを実行し、文字列を指定して数値を実行して返す2⊃⎕VFIで置き換える必要がありました。


間違っているように見える:60、69、90、および96にドットがあってはなりません。
ngn 14

@ngnに感謝します、私はそれを修正しました、私はそれが今正しく働くと思います。
モリスズッカ14

2
よくやった:)の代わりに、⊃,/または,/あなたはフロントで使用することができます。
ngn 14

そうそう!私は通常ml1では動作しないので、∊を忘れます。
モリスズッカ14


4

パイソン2、130の 116 113バイト

def f(n):S=`n`;n and f(n-1);print S+"."*all([n%10,set(S)<=set("0689"),(u""+S[::-1]).translate({54:57,57:54})!=S])

f数値を昇順でSTDOUTに出力する関数を定義します。

今回は、@ feersumの本から葉を取り出してみようと思いました.translate:)

拡張:

def f(n):
 S=`n`        
 n and f(n-1)                                      # Recurse if not 0                                     
 print S+"."*all([n%10,                            # Not divisible by 10
                  set(S)<=set("0689"),             # Consists of 0689
                  (u""+S[::-1]).translate
                  ({54:57,57:54})!=S])             # When rotated is not itself

以前のソリューション:

def f(n):S=`n`;print S+"."*all([n%10,set(S)<=set("0689"),eval("S[::-1]"+".replace('%s','%s')"*3%tuple("6a96a9"))!=S]);n and f(n-1)

.replace少し前にトリックを見せてくれた@xnorに感謝します。


(u''+S[::-1])代わりに使用できますunicode(S[::-1])。また、print呼び出しと再帰呼び出しを入れ替えると、数字が昇順になります。
ngn 14

@ngnああおかげで、私は考えていなかったu""+だろう実際に作業
SP3000

これはもっと小さくすべきだと思います。たとえば、「p」ではなく「print」が正しく印刷されるのはあなたのせいではありませんが、「p = print」と書いて「短くします!
アレックティール

4

C#、343 309文字

が長すぎる、とにかく:

namespace System.Linq{class C{static void Main(){int n=int.Parse(Console.ReadLine());for(int i=0;i<=n;i++){var b=i+"";var c=b.Replace("6","9");Console.Write(b+(b.All(x=>x=='0'|x=='8'|x=='6'|x=='9')&!b.EndsWith("0")&!(b.Count(x=>x=='6')==b.Count(x=>x=='9')&new String(c.Reverse().ToArray())==c)?". ":" "));}}}}

どのように機能しますか?番号にピリオドを追加するには、次の要件に一致する必要があります。

  • のみで構成され0869
  • ゼロで終了しません。
  • 回転させると同じ数ではありません:
    • 数値の6sと9sの量が等しい場合、および
    • if c=すべて6のsを含む数がsで置き換えられます9
    • c== c
    • その後:回転した数値は、数値自体と同じです。

数字はスペースで区切られます。

インデント付きのコード:

namespace System.Linq
{
    class C
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i <= n; i++)
            {
                var b = i + "";
                var c = b.Replace("6", "9");
                Console.Write(b +
                    (b.All(x => x == '0' | x == '8' | x == '6' | x == '9') &
                    !b.EndsWith("0") &
                    !(b.Count(x => x == '6') == b.Count(x => x == '9') &
                    new String(c.Reverse().ToArray()) == c) ? ". " : " "));
            }
        }
    }
}

1
私の答えはもっと長いです;)ゴルフ場でボーリングをしているようです。
デジタル外傷14

1
8808はどうですか?6や9はありませんが、回転すると8088です。
エレンディアスターマン14

1
@ El'endiaStarmanどうもありがとう!提出物を修正しながら、実際に文字を保存しました:)
ProgramFOX 14

4

M(ムンプス)-72 70

R n F i=0:1:n W !,i S r=$TR($RE(i),69,96) W:r=+r*r'=i*'$TR(i,0689) "."

Mのほとんどの組み込みコマンドおよび関数には、短縮バージョンがあります。以下のフルネームを使用しました。

READ n-キーボードから文字列を読み取り、保存しnます。

FOR i=0:1:n-ゼロからnにループし、i毎回1ずつ増加します。(行の残りはループの本体を構成します。)

WRITE !,i-改行の後に値を出力しiます。

SET r=$TRANSLATE($REVERSE(i),69,96))-逆にi、9を6に、6を9に置き換えて、に保存しrます。

WRITE:r=+r*r'=i*'$TRANSLATE(i,0689) "."

  • :-事後条件式を示します。そのため、WRITEコマンドはr=+r*r'=i*'$TRANSLATE(i,0689)、真の値に評価された場合にのみ実行されます。
  • r=+r- r先行ゼロがないことを確認します。単項+演算子は、文字列を数値に変換します。数値がある場合、先行ゼロを取り除きます。
  • *-乗算演算子。Mには操作の順序はありません。すべての二項演算子は、左から右に現れる順序で評価されます。
  • r'=i- i反転バージョンと同じではないことを確認しrます。
  • '$TRANSLATE(i,0689)-からすべてのゼロ、6、8、9を削除し、i何も残っていないことを確認します。('は論理否定演算子です。)
  • "."-最後に、WRITEコマンドへの引数(リテラル文字列)。

編集:乗算演算子を乱用することで、少し短くしました。前のバージョン:

R n F i=0:1:n W !,i S r=$TR($RE(i),69,96) I '$TR(i,0689),i'=r,r=+r W "."

3

APL、53文字

∊{⍵,'. '↓⍨∨/(3≡⊃i)(5∊i),⍵≡'9608x'[i←⌽'6908'⍳⍵]}∘⍕¨0,⍳

0,⍳N        numbers 0..N
{...}∘⍕¨    format each number as a string and do the thing in curly braces
                inside the braces ⍵ is the current string
'6908'⍳⍵    encode '6' as 1, '9' as 2, '0' as 3, '8' as 4, and all others as 5
⌽           reverse
'9608x'[A]  use each element of A as an index in '9608x':
                effectively: swap '9'←→'6', preserve '08', mask other digits
⍵≡          does it match the original string?
                this is the first boolean condition, two more to come
5∊i         did we have a digit other than '0689'?
3≡⊃i        is the first of i (that is, the last of ⍵) a '0' (encoded as 3)?
∨/          disjunction ("or") over the three conditions, returns 0 or 1
'. '↓⍨      drop 0 or 1 elements from the beginning of the string '. '
⍵,          prepend ⍵
∊           flatten the results to obtain a single output string

3

C#205 209

C#はそれほど長くする必要はありません...
多かれ少なかれ、私のJavaScriptの答えのポート

class P{static void Main(string[]a){for(int n=int.Parse(a[0]);n>=0;--n){string p="",u=n+p;int e=n%10;foreach(var d in u)p=(d<56?d!=54?d>48?e=0:0:9:120-d-d)+p;System.Console.WriteLine(e!=0&p!=u?u+".":u);}}}

非ゴルフ

class P 
{
    static void Main(string[] a)
    {
        for (int n = int.Parse(a[0]); n >= 0; --n)
        {
            string p = "", u = n + p;
            int e = n % 10;
            foreach (var d in u) p = (d < 56 ? d != 54 ? d > 48 ? e = 0 : 0 : 9 : 120 - d - d) + p;
            System.Console.WriteLine(e != 0 & p != u ? u + "." : u);
        }
    }
}

2

ルビー、81

?0.upto(*$*){|x|puts x.reverse.tr('69','96')!=x&&x=~/^[0689]+$/&&/0$/!~x ?x+?.:x}

入力はコマンドラインから取得されます。

Stringからのリストを生成0nます。それらをループして印刷します。すべての条件が満たされる場合、ドットを追加します。

  • 番号を逆にして6sを9sに置き換えても、元の
  • 番号は数字だけで構成され068および9
  • 数字はで終わらない 0

2

JavaScriptの(ES6)101 104 106 109

console.log介し引数、出力としてnの関数
編集 0導くための試験に10%を使用して
編集2 for結局再編成は、Iは配列理解を必要としない
編集3が(再び)修飾0をリードするためのチェックを

F=n=>{
   for(;e=~n;console.log(e*l&&p-n?n+'.':n),--n)
     for(d of(p='')+n)p=(l=d<8?d-6?-d?e=0:0:9:24-d-d)+p
}

ゴルフをしないでテストが簡単

F=n=>
{
  o = '';
  for( ; ~n; --n) // loop on n decreasing to 0 (~n is 0 when n==-1)
  {
    e = ~n; // init to a nonzero value, zero will mark 'invalid digit'
    p = ''; // build rotated number in p
    for(d of '' + n)
    {
      // l is the current digit, on exit will be the first digit of p
      l = d < 8 ?
            d != 6 ?
              d != 0 ?
                e = 0 // invalid char found, no matter what
                : 0 
              : 9 // 6 become 9
            : 24 - d - d; // calc 8 => 8, 9 => 6
      p = l + p;
    }       
    // e==0 if invalid char, l==0 if leading 0
    o += ' ' + ( e * l && p-n ? n+'.' : n);
  }
  console.log(o);
}

F(100)

出力

100 99. 98. 97 96 95 94 93 92 91 90 89. 88 87 86. 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68. 67 66. 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9. 8 7 6. 5 4 3 2 1 0

括弧内にforループを含む構成の名前はあります[]か?私はこれをこれまでPythonからしか知らなかったので、ドキュメントを探しています。
flawr

1
ここで改行を節約できると思います。
英国茶

1
@britishteaの改行とインデントは読みやすくするために追加され、カウントされません。これは、単一のラインだ
edc65


1

Bash + coreutils、105

for((i=0;i<=$1;i++));{
[ ${i//[0689]/} ]||[ $i = `rev<<<$i|tr 69 96` ]||((!${i: -1}))||d=.
echo $i$d
d=
}

テスト:

$ ./rotproof.sh 100 | grep "\."
6.
9.
66.
68.
86.
89.
98.
99.
$ 

1

sed、467

C#より長い...

@ edc65が、答えはnだけでなく0-nの数字を処理する必要があると指摘したとき、私はこれをほぼ完了しました。sedコードを追加して0-nをインクリメントすると、このタスクは算術演算なしのsedには不向きであるため、さらに多くのコードが追加されます。

:l
/^[0689]*$/{
h
s/$/:/
:x
s/([0-9]):(.*)/:\2\1/
tx
s/://
y/69/96/
G
/^([0-9]+)\n\1/be
s/^[^0].*/&./
:e
s/.*\n//
}
p
s/\.//
s/[0-9]/<&/g
s/0//g;s/1/_/g;s/2/__/g;s/3/___/g;s/4/____/g;s/5/_____/g
s/6/______/g;s/7/_______/g;s/8/________/g;s/9/_________/g
:t
s/_</<__________/
tt
s/<//g
s/_//
:b
s/__________/</g
s/<([0-9]*)$/<0\1/
s/_________/9/;s/________/8/;s/_______/7/;s/______/6/
s/_____/5/;s/____/4/;s/___/3/;s/__/2/;s/_/1/
s/</_/g
tb
s/^$/0/
/^0$/by
bl
:y
c\
0
p

OPによると、順序は重要ではないため、nから0まで下に向かって作業します。

出力:

$ sed -rnf rotproof.sed <<< 100 | grep "\."
99.
98.
89.
86.
68.
66.
9.
6.
$ 

1

AWK:120

{a[a[6]=9]=6;a[8]=8;for(j=a[0]=0;j<=$0;++j){r="";for(i=j;i;i=int(i/10))r=r a[i%10];print(j~/[^0689]|0$/||j==r)?j:j"."}}

stdinからn値を読み取ります。

テスト:

C:\ AWK> gawk -f revnum.awk | grep \。
100
^ Z
6.
9.
66.
68.
86.
89.
98.
99。


1

レボル-195

for n 0 do input 1[b: copy a: form n d: c: 0 parse reverse a[any[m:"6"(change m"9"++ c)|"9"(change m"6"++ c)|"0"|"8"| skip(++ d)]]print rejoin [b either all[d = 0 c > 0 a != b a/1 != #"0"]"."{}]]

Ungolfed +いくつかの注釈:

for n 0 do input 1 [
    b: copy a: form n
    d: c: 0

    ; reverse number and rotate "6" & "9"
    ; and do some counts (c when "6" or "9" and d when != "0689")
    parse reverse a [
        any [
            m:
              "6" (change m "9" ++ c)
            | "9" (change m "6" ++ c)
            | "0"
            | "8"
            | skip (++ d)
        ]
    ]

    print rejoin [
        b either all [
            d = 0               ; only has 0689 digits
            c > 0               ; must have at least one "6" or "9"
            a != b              ; not same when reversed
            a/1 != #"0"         ; does not "end" with zero
        ]
        "." {}                  ; if ALL then print "." else blank {}
    ]
]

1

bc、158

ネイティブの算術演算なしですべての文字列および正規表現操作を使用して純粋にsedでこれを行った後、これがどのように見えるか、つまりすべての算術および論理演算で文字列/正規表現なしでどのように見えるか興味がありました:

for(i=read();i+1;r=0){p=1
for(x=i;x;x/=A){d=x%A
if(x==i&&!d)p=0
if(d==6||d==9)d=F-d else if(d%8)p=0
r=r*A+d}
if(r==i)p=0
print i--
if(p)print "."
print "\n"}

出力は降順でソートされます。

出力:

$ bc rotproof.bc <<< 100 | grep "\."
99.
98.
89.
86.
68.
66.
9.
6.
$ 

1

Python-152

for i in range(input()+1):print`i`+("."*all([j in"0689"for j in`i`])and`i`[-1]!="0"and`i`!=`i`.replace("9","x").replace("6","9").replace("x","6")[::-1])

+1。見栄えが良い...短くするためのいくつかのトリックを学びたい場合は、Pythonの2で別の答えがあり、置換の代わりに翻訳を使用します。編集履歴では、これらの3つの置換を1に結合する方法もあります...将来の質問に便利で
センモウヒラムシ

2
順調です!:上記に加えて、ここでいくつかのより多くのgolfsだ"."if a[i]else"" -> "."*a[i]int(raw_input()) -> input()(実際にはあるeval(raw_input())
SP3000

いくつかのgolfes:(1)はPython 2では、あなたは置き換えることができstr(i)`i`。(2)a一度しか使用しないので、なぜ変数に割り当てるのか。
Wrzlprmft

2番目の提案を使用しますが、str(i)数回使用します。どちらに置き換えることができiますか?
KSFT

1
ではなくii逆ティックを使用しrepr(i)ます。これはと同義です。str(i)どこでも使用できますがstr(i)、何度も使用する場合は、変数に割り当ててバックティックを使用することに加えて使用する方が短い場合があります。(つまりx=`i`; (do stuff with x)
SP3000

1

JavaScriptを- 168 129 119 113 111 108

F=n=>{for(;~n;n--){r='';for(c of""+n)r=(c-6?c-9?c:6:9)+r;console.log(r-n&&!/[1-57]/.test(r)&&n%10?n+".":n)}}

4 5 6. 8 9. 16 60 66. 68. 69 906 909. 6090 9806. 9886 9889。

または読み取り可能なバージョン:

F=n=>{for(;~n;n--){
    r='';for(c of ""+n)r=(c-6?c-9?c:6:9)+r; // rotate
    console.log( // output, new-line is added
        // original number, and
        // append dot only if number is different than its rotated version and no un-rotatable digit is present and there is no zero at the end
        r-n && !/[1-57]/.test(r) && n%10
           ?n+".":n
    )}}

私は正規表現にあまり満足していません、何かアイデアはありますか?

編集:で学んだ巧妙なトリック~for (... of ...)@ edc65から
EDIT2再編成条件:
EDIT3 @ edc65によって適用の提案を:


悪い瞳:) i=n+"";for(c of i)=>は、for(c of i=n+"")2バイト保存
edc65

... and c==6?A:B=> c!=6=>B:A=>c-6?B:A
edc65 14

また、通常、1バイト短いString.match(Regexp)の代わりにRegexp.test(String)を使用できます。
edc65

合計で6バイトです。おかげで:) for(c of i=n+"")を見ると、かなり論理的ですが、思いつきません。 c-6?B:A神は私が今まで生産コードにこれを入れ禁じる
zabalajka

正規表現についてのアイデア:1つ以上の無効な文字ではなく1つ以上の文字をチェックする必要があるため、「+」は必要ありません。短すぎるだろう
edc65

1

05AB1E38 37 30 29 バイト

ÝεÐSUT%ĀiŽR!XåPiÐ69‡RÊi'.«]»

オンラインでお試しください。

説明:

Ý                # Inclusive 0-based range: [0, (implicit) input]
 ε               # Map each integer to:
  Ð              #  Triplicate the current integer
  SU             #  Convert it to a list of digits, and pop and store it in variable `X`
    Ti         #  If the current integer contains no trailing zeros
    ŽR!XåPi      #  And if the current integer only consists of the digits [0689]
    Ð69‡RÊi     #  And if the current integer is not the same when its 6s and 9s
                 #  are swapped and then the total is reversed
             '.« #   Concat a '.'
                 #  Implicit else: use the top of the stack (the duplicate current integer)
]                # Close all three ifs and the map
 »               # Join the resulting list by newlines (and output implicitly)

一部の部品に関する追加説明:

Ti       # Check if the integer contains no trailing zeros:
T          #  Push 10 (T is a builtin for 10)
 %         #  Modulo
  Ā        #  Trutified: 0 remains 0 (falsey), everything else becomes 1 (truthy)
           #   i.e. 12 % 10 → 2 → 1 (truthy)
           #   i.e. 68 % 10 → 8 → 1 (truthy)
           #   i.e. 70 % 10 → 0 → 0 (falsey) (70 remains as is)
           #   i.e. 609 % 10 → 9 → 1 (truthy)
           #   i.e. 808 % 10 → 8 → 1 (truthy)

ŽR!XåPi    # Check if the integer only consists of the digits 0, 6, 8 and/or 9:
ŽR!        #  Push 6890 (Ž is a builtin for 2-char compressed integers, where R! is 6890)
   X       #  Push variable `X` (the list of digits)
    å      #  Check for each of these digits if they're in "6890"
     P     #  Take the product of that list
           #   i.e. [1,2] → [0,0] → 0 (falsey) (12 remains as is)
           #   i.e. [6,8] → [1,1] → 1 (truthy)
           #   i.e. [6,0,9] → [1,1,1] → 1 (truthy)
           #   i.e. [8,0,8] → [1,1,1] → 1 (truthy)

Ð69‡RÊi   # Check if the integer with 6s and 9s swapped and then reversed isn't unchanged:
Ð          #  Triplicate the integer
 69        #  Push 69
   Â       #  Bifurcate (short for Duplicate & Reverse)
          #  Transliterate (in `a` replace all characters `b` with characters `c`)
     R     #  Reverse
      Ê    #  Check for inequality
           #   i.e. 68 → "68" → "98" → "89" → 68 != "89" → 1 (truthy) (68 becomes "68.")
           #   i.e. 609 → "609" → "906" → "609" → 609 != "609" → 0 (falsey) (609 remains as is)
           #   i.e. 808 → "808" → "808" → "808" → 808 != "808" → 0 (falsey) (808 remains as is)

0

Perl-84

for(0..$ARGV[0]){s/6/x/g;s/9/6/g;s/x/9/g;printf"$_%s\n",$_=~/^[0689]+[689]$/?".":""}

0

Powershell、111 102バイト

param($s)$s+'.'*!($s-match'[1-57]|0$|'+-join$(switch -r($s[($s.Length-1)..0]){'0|8'{$_}'6'{9}'9'{6}}))

テストスクリプトの説明:

$f = {

param($s)           # input string
$l=$s.Length        # length of the string
$c=$s[($l-1)..0]    # chars of the string in the reversed order
$d=switch -r($c){   # do switch with regex cases for each char
    '0|8'{$_}       # returns the current char if it equal to 8 or 0
    '6'{9}          # returns 9 if the current char is 6
    '9'{6}          # returns 6 if the current char is 9
}                   # returns array of new chars (contains 0,6,8,9 only)
$s+'.'*!(            # returns s. Add '.' if not...
    $s-match'[1-57]|0$|'+-join$d
                    # $s contains chars 1,2,3,4,5,7 or
                    # ends with 0 or
                    # equal to string of $d
)

}

@(
    ,('2'    ,'2'   )
    ,('4'    ,'4'   )
    ,('5'    ,'5'   )
    ,('6.'   ,'6'   )
    ,('7'    ,'7'   )
    ,('9.'   ,'9'   )
    ,('16'   ,'16'  )
    ,('60'   ,'60'  )
    ,('66.'  ,'66'  )
    ,('68.'  ,'68'  )
    ,('69'   ,'69'  )
    ,('906'  ,'906' )
    ,('909.' ,'909' )
    ,('8088.','8088')
    ,('9806.','9806')
    ,('9886' ,'9886')
    ,('9889.','9889')
) | % {
    $e,$s = $_
    $r = &$f $s
    "$($r-in$e): $r"
}

出力:

True: 2
True: 4
True: 5
True: 6.
True: 7
True: 9.
True: 16
True: 60
True: 66.
True: 68.
True: 69
True: 906
True: 909.
True: 8088.
True: 9806.
True: 9886
True: 9889.

0

スタックス、27 バイト

Ç▒≈♣▌╬"÷╜─B↓«âpø←╚S☼ì>♫è;&╛

実行してデバッグする

開梱されていない、コメントされていない、これはこのように見えます。

0p      print 0 with no line break
F       for each [1 .. n] execute the rest of the program, where n is the input
  zP    print a newline
  q     peek and print the iterating variable without newline
  A%!C  modulo 10, and cancel iteration if zero (this cancels for multiples of 10)
  _$cc  convert iterating value to string and duplicate it twice on the stack
  7R6-$ construct the string "123457"
  |&C   if the character intersection is truthy, cancel the iteration
  r     reverse string
  69$:t map 6 and 9 characters to each other
  =C    if this rotated string is equal to the original, cancel iteration
        print "." with no newline 
        (this comment precedes the instruction because it's an unterminated literal)
  ".

これを実行する

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.