2020年3月13日金曜日

職場閉鎖

コロナウイルスの関係で、職場が閉鎖になった。
(3/16 - 4/3の三週間)

# 追記
5月18日から戻り始める人がでたけれど、プログラマーである私はリモートでも問題ないという話になり、6月終わり頃になりそう。

2020年3月9日月曜日

ABC 158 C

S = input().split()
[A,B] = [int(i) for i in S]

Alow = A*100//8
Ahi  = (A+1)*100//8

Blow = B*100//10
Bhi  = (B+1)*100//10

#print(Alow,Ahi,Blow,Bhi)

Aran = [i for i in range(Alow,Ahi+1) if int(i*0.08) == A]
Bran = [i for i in range(Blow,Bhi+1) if int(i*0.10) == B]


resRan = sorted(list(set(Aran) & set(Bran)))
#print(resRan)
if len(resRan) !=0:
  print(resRan[0])
else:
  print(-1)
S = input().split()
[A,B] = [int(i) for i in S]

Alow = A*100//8
Ahi  = (A+1)*100//8

Blow = B*100//10
Bhi  = (B+1)*100//10

#print(Alow,Ahi,Blow,Bhi)

Aran = [i for i in range(Alow,Ahi+1) if int(i*0.08) == A]
Bran = [i for i in range(Blow,Bhi+1) if int(i*0.10) == B]


resRan = sorted(list(set(Aran) & set(Bran)))
#print(resRan)
if len(resRan) !=0:
  print(resRan[0])
else:
  print(-1)
うーん。焦ってるとこれぐらいのことも思いつかないもんだなぁ。

S = input().split()
[A,B] = [int(i) for i in S]

Alow = A*100//8
Ahi  = (A+1)*100//8

Blow = B*100//10
Bhi  = (B+1)*100//10

Aran = [i for i in range(Alow,Ahi+1) if int(i*0.08) == A]
Bran = [i for i in range(Blow,Bhi+1) if int(i*0.10) == B]


resRan = sorted(list(set(Aran) & set(Bran)))
if len(resRan) !=0:
  print(resRan[0])
else:
  print(-1)

2020年3月4日水曜日

Atcoder ABC157 E

下記コード、pypyだと通るけど、python3だとTLEする。

https://atcoder.jp/contests/abc157/submissions/10530007
from collections import defaultdict
import bisect
alphabet="abcdefghijklmnopqrstuvwxyz"
bS = int(input())
S= input()
nQ = int(input())
S = [i for i in S]
query = []
for i in range(nQ):
  query.append(input().split())
locs =defaultdict(list)
for i,char in enumerate(S):
    locs[char].append(i)
   
def countChars(iter,ss,ee):
  nChar = 0
  for i in alphabet:
    if len(locs[i]) == 0:
      pass
    else:
      sptr = bisect.bisect_right(locs[i],ss)
      eptr = bisect.bisect_left(locs[i],ee)
      if sptr == eptr:
        if sptr < 1 or sptr > len(locs[i]):
          continue
        else:
          if locs[i][sptr-1] == ss:
            nChar+=1
      else:
        nChar += 1
  return nChar
   
 
res = []
for iter,iQ in enumerate(query):
  if int(iQ[0]) == 2:
    res.append(str( countChars(iter,int(iQ[1])-1,int(iQ[2])) ))
  if int(iQ[0]) == 1:
    location = int(iQ[1])-1
    curChar  = S[location]
    if curChar != iQ[2]:
      locs[curChar].remove(location) #remove from old
      bisect.insort(locs[iQ[2]],location)
      S[location] = iQ[2]
     
print(" ".join(res))
  

2020年2月27日木曜日

Q#で乱数表示

まず、新規プロジェクトを作る。Visual Studio Codeを使ってるので、下記参照。
Create a C# project, using VS Code

抜粋

  • Go to View -> Command Palette
  • Select Q#: Create New Project
  • Select Standalone console application
  • Navigate to the location on the file system where you would like to create the application
  • Click on the Open new project... button, once the project has been created
一番初歩っぽい、乱数発生機を使う練習


Program.qs (MSのサイトだとOperation.qsになってるけど、VS code 1.4.2 2020/1月最新版だとProgram.qsで動く)

namespace Qrng {
    open Microsoft.Quantum.Intrinsic;
    operation SampleQuantumRandomNumberGenerator() : Result {
        using (q = Qubit())  { // Allocate a qubit.
            H(q);             // Put the qubit to superposition. It now has a 50% chance of being 0 or 1.
            let r = M(q);     // Measure the qubit value.
            Reset(q);
            return r;
        }
    }
}

に書き換えて、
Driver.csを
using System;
using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;
using System.Linq;
namespace Qrng
{
    class Driver
    {
        static void Main(string[] args)
        {
            using (var sim = new QuantumSimulator())
            {
                // First we initialize all the variables:
                var bitString = "0"; // To save the bit string
                int max = 50; // The maximum of the range
                int size = Convert.ToInt32(Math.Floor(Math.Log(max, 2.0) + 1));
                // To calculate the amount of needed bits
                int output = max + 1; // Int to store the output
                while (output > max)  // Loop to generate the number
                {
                    bitString = "0"; // Restart the bit string if fails
                    bitString = String.Join("", Enumerable.Range(0, size).Select(idx =>
                                            SampleQuantumRandomNumberGenerator.Run(sim).Result == Result.One ? "1" : "0"
                                                                                )
                                           );
                    // Generate and concatenate the bits using using the Q# operation
                    output = Convert.ToInt32(bitString, 2);
                    // Convert the bit string to an integer
                }
                // Print the result
                Console.WriteLine($"The random number generated is {output}.");
            }
         }
      }
    }
に書き換えて terminal から"dotnet run"すると、乱数が出力された

2020年2月14日金曜日

Winnyの作者(金子さん)を持ち上げる風潮

なんでかしら無いが、最近Winnyの作者の金子さんがやたら持ち上げられるので、私は反対であることを表明しておく。

ツールを悪用した人物ではなく、ツールをつくったプログラマーに「悪意があった」とするのは過剰かつ不当な対応だ。そもそもWinny自体は合法なファイルも共有できる。いまでいえば、YouTubeに著作権違反の動画がアップされるたびに、YouTubeの経営者が投獄されるようなものである。
https://wired.jp/2018/11/10/winny-isamu-kaneko-1/

と書かれているけれども、
こんなこと発言してる人が著作権を違反する意図がなかったと言うの変じゃないですかね?
裁判所が無罪と言ったことには敬意を払いますが、善意のスーパーヒーローであったかのように扱うのには強い違和感があります。


43 名前:47 投稿日:02/04/06 01:17 ID:M5Lc7MaX main/1017590243.html#476
ソフト公開で逮捕というとFLMASKの例があるから絶対無いともいえんけど、
その前にトンズラできると思うなぁ。
初めは目立たないWEB上でひっそりやって目立ってきたら
自分で作ったワールド内に逃げればいいと思われ。

広まるほどの完成度に達すれば逃げられるし、
達しなければ捕まることも無いという二重の安全策(w

あとMXでの公開の方が絶対危険だよね。
あれ珍しいファイルだと提供者のIPが一発でばれるし。

2020年2月5日水曜日

XcalableMP/XcalableACC or OMNI Compiler

I have just built the OMNI Compiler 1.3.2 on DGX Station with Ubuntu 18.04.

Configure options:
env CPP=/usr/bin/cpp ./configure --enable-openacc --enable-xacc \
--with-cuda=/opt/pgi/linux86-64/2019/cuda/10.1 \
--with-gpu-cflags="-arch=sm_70 -O3" \
--prefix=/home/kushida/OMNI-Compiler/1.3.2


module file.
#%Module1.0
##
## OMNI Compiler 1.3.2
proc ModulesHelp { } {
        puts stderr "OMNI Compiler 1.3.2\n"
}

module-whatis   "OMNI Compiler 1.3.2"

# for Tcl script only
set     omni_path       /home/kushida/OMNI-Compiler/1.3.2

# append pathes
prepend-path    CPATH           $omni_path/include
prepend-path    PATH            $omni_path/bin
prepend-path    LD_LIBRARY_PATH $omni_path/lib
prepend-path    MANPATH         $omni_path/share/man

conflict omnicompiler
prereq pgi/19.10
prereq openmpi/3.1.3