EUが崩壊するのか、英国が崩壊するのか。西洋社会が崩壊するのか。
世界経済が崩壊するとなんですがね。
規制緩和、プライマリーバランス。官僚の無駄遣い。よく理解できますよね。EUってのね。
しかしですよ、英国がEU脱退すると影響力とかってなくなるわけですよね。
突っ走るEUとか、米国のポチと成り果てる英国とか。
閑話休題。
オンラインで電子工学の授業を視聴していたら、imref って単語が出てきました。
新しい単位でも定義したのかと思うと、この単語よくよく見てみると...
Fermi だっていうんですよ。フェルミ準位の Fermi です。で、imref が何かといえばこの Fermi の逆。逆読みだっていうんですね。
分からないものですね。一見まったく別の単語としか見えない。疑フェルミ準位を表すものだそうです。不純物が入るとフェルミ準位がずれるのでその値です。
ということで、文字を反転するプログラムを書いてみました。
まずは Elisp で。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun reverse-word(str) | |
"Reverse the given string" | |
(interactive "sWord:") | |
(eval (cons 'concat (reverse (mapcar (lambda(x) (string x)) str))))) | |
;(reverse-word "fermi") | |
(defun _reverse(lst) | |
"Reverse the given list" | |
(if (= (length lst) 1) | |
lst | |
(append (_reverse (cdr lst)) (list (car lst))))) | |
;(_reverse '( a b c d e)) | |
(defun reverse-region(start end) | |
"Reverse text in the region" | |
(interactive "r") | |
(insert (reverse-word (buffer-substring-no-properties start end))) | |
(kill-region start end)) | |
;edcba | |
;(apply 'string (scramble "abcdef")) | |
(defun scramble (str) | |
"Scramble the word specified" | |
(shuffle-list str)) | |
(defun shuffle-list (str) | |
"Return random ordered list." | |
(let* ((lst (string-to-list str)) | |
(len (length lst)) | |
(r (random len))) | |
(if (< len 1) | |
nil | |
(cons (nth r lst) | |
(scramble (append (head r lst)(nthcdr (1+ r) lst))))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<string> | |
#include<iostream> | |
using namespace std; | |
int main() | |
{ | |
string str; | |
cout << "Enter a word: "; | |
cin >> str; | |
int n=str.length(); | |
for(int i=0;i<n;i++) | |
{ | |
cout << str[n-i-1]; | |
} | |
cout << endl; | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <climits> | |
#include <cstdlib> | |
#include <iostream> | |
#include <unistd.h> | |
using namespace std; | |
string scramble(string str) | |
{ | |
int n=str.length(); | |
string res=""; | |
int filled[n]; | |
for(int i=0;i<n;i++) | |
filled[i]=0; | |
for(int i=0;i<n;i++) { | |
int r=rand() % (n-i); | |
int j=0; | |
int count=0; | |
do { | |
if(filled[j]==0) { | |
if(r<=count) { | |
filled[j]=1; | |
break; | |
} | |
count++; | |
} | |
} | |
while(++j<n); | |
res+=str[j]; | |
} | |
return res; | |
} | |
long factorial(int n) | |
{ | |
long res; | |
if(n==1) | |
res=n; | |
else | |
res=n*factorial(n-1); | |
return res; | |
} | |
int main(int argc, char* argv[]) | |
{ | |
string str; | |
srand(time(NULL)); | |
int nopt=0; | |
char *nparam=NULL; | |
int opt; | |
while((opt=getopt(argc, argv, "n:"))!=-1) { | |
switch(opt){ | |
case 'n': | |
nopt=1; | |
nparam=optarg; | |
break; | |
} | |
} | |
int n=INT_MAX; | |
if(nopt==1) | |
{ | |
n=atoi(nparam); | |
} | |
if(optind < argc) | |
{ | |
str=scramble(argv[optind]); | |
} | |
else | |
{ | |
cout << "Enter a word: "; | |
cin >> str; | |
} | |
int len=str.length(); | |
int n_res=min((int)factorial(len),n); | |
string resList[n_res]; | |
for(int i=0;i<n_res;i++) | |
{ | |
bool duplicate=true; | |
string new_str=""; | |
while(duplicate){ | |
new_str=scramble(str); | |
duplicate=false; | |
for(int a=0;a<i;a++) | |
{ | |
if(resList[a].compare(new_str)==0) | |
{ | |
duplicate=true; | |
break; | |
} | |
} | |
} | |
resList[i]=new_str; | |
} | |
for(int i=0;i<n_res;i++) | |
cout << resList[i] << endl; | |
return 0; | |
} |
乱数を計算する回数を減らすよう乱数を出してからはじくのではなく、必要な分だけ計算し文字列から選んでいます。