Skip to content

Instantly share code, notes, and snippets.

@greymd
Last active April 17, 2018 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greymd/9527645a73662b641a34d6c07e459ae5 to your computer and use it in GitHub Desktop.
Save greymd/9527645a73662b641a34d6c07e459ae5 to your computer and use it in GitHub Desktop.
dc command practice
$ dc -e'0[1+ddn10P10>r]srlrx'
1
2
3
4
5
6
7
8
9
10
$ dc -e{1..10}'d^p'
1
4
27
256
3125
46656
823543
16777216
387420489
10000000000
$ seq 9 | dc -f- -e '[n11Pn10Pz1<r]srz1<rp'
9
 8
7
 6
5
 4
3
 2
1

dc -e '[70P105P122P122P]sF[66P117P122P122P]sB[lNdn32P3%0=FlN5%0=B10P]sJ[1+ddsNlJx15>r]sr0lrx'
1
2
3 Fizz
4
5 Buzz
6 Fizz
7
8
9 Fizz
10 Buzz
11
12 Fizz
13
14
15 FizzBuzz

Cyclic number in base 11 093425A17685

$ dc -e'11i10o 11 10 A 9 8 7 6 5 4 3 2 1 0n[93425A17685*nAPz0<r]srlrx' | nl
     1  093425A17685
     2  17685093425A
     3  25A176850934
     4  3425A1768509
     5  425A17685093
     6  5093425A1768
     7  5A1768509342
     8  685093425A17
     9  7685093425A1
    10  85093425A176
    11  93425A176850
    12  A17685093425
$ dc -e'11i10o 10 4 5 3 7 11 2 9 8 A 6 1 0n[93425A17685*nAPz0<r]srlrx' | sed 'y/093425A17685/HUGっと!プリキュア!/'
HUGっと!プリキュア!
!HUGっと!プリキュア
ア!HUGっと!プリキュ
ュア!HUGっと!プリキ
キュア!HUGっと!プリ
リキュア!HUGっと!プ
プリキュア!HUGっと!
!プリキュア!HUGっと
と!プリキュア!HUGっ
っと!プリキュア!HUG
Gっと!プリキュア!HU
UGっと!プリキュア!H

Convert base from 2 to 10

$ echo 101 | dc -e '2i' -f- -ep
5

Convert base from 10 to 2

$ echo 5 | dc -f- -e '2op'
101

Convert base 16 to 10

echo '16iAAp' | dc

Convert base 10 to 16

$ echo '10i 10 16op' | dc
A

Convert base N to M

$ echo 10 | dc -e<N>i -f- -e<M>op
$ echo '[うんこ]' | dc -f- -eppppppp
うんこ
うんこ
うんこ
うんこ
うんこ
うんこ
うんこ
$ dc -e '11o11i20k 123456789A AAAAAAAAAA/p1sc[d10*lc-plc1+scz9>r]srlrx'
.123456789A123456789A08
.23456789A123456789A084
.3456789A123456789A0843
.456789A123456789A08437
.56789A123456789A084377
.6789A123456789A0843770
.789A123456789A08437706
.89A123456789A084377065
.9A123456789A0843770653
dc -e '[響]0:a[け]1:a[!]2:a[ユ]3:a[ー]4:a[フ]5:a[ォ]6:a[ニ]7:a[ア]8:a[ム]9:a0sc[lclC+10%;anlC1+dsC10>#]s#[0sCl#x10Plc1+dsc10>^]ds^x'
響け!ユーフォニアム
け!ユーフォニアム響
!ユーフォニアム響け
ユーフォニアム響け!
ーフォニアム響け!ユ
フォニアム響け!ユー
ォニアム響け!ユーフ
ニアム響け!ユーフォ
アム響け!ユーフォニ
ム響け!ユーフォニア
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment