¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse

Similar documents
¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse

¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse

Windows Cygwin Mac *1 Emacs Ruby ( ) 1 Cygwin Bash Cygwin Windows Cygwin Cygwin Mac 1 Mac 1.2 *2 ls *3 *1 OS Linux *2 *3 Enter ( ) 2

8 if switch for while do while 2

haskell.gby

C言語によるアルゴリズムとデータ構造

ex01.dvi

Copyright c 2006 Zhenjiang Hu, All Right Reserved.

Java updated

K227 Java 2

,,,,., C Java,,.,,.,., ,,.,, i

3 Java 3.1 Hello World! Hello World public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World");

1.ppt

ex01.dvi

2

org/ghc/ Windows Linux RPM 3.2 GHCi GHC gcc javac ghc GHCi(ghci) GHCi Prelude> GHCi :load file :l file :also file :a file :reload :r :type expr :t exp

6-1

BASIC / / BA- SIC Web 1/10 1/10 / / JavaScript

Windows [ ] [ (R)..] cmd [OK] Z:\> mkdir progi [Enter] \ ) mkdir progi ) (command ) help [Enter] help ( help ) mkdir make directory Windows ) mkdir mk

tuat1.dvi

2

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

ohp02.dvi

I 2 tutimura/ I 2 p.1/??

2.2 Sage I 11 factor Sage Sage exit quit 1 sage : exit 2 Exiting Sage ( CPU time 0m0.06s, Wall time 2m8.71 s). 2.2 Sage Python Sage 1. Sage.sage 2. sa

つくって学ぶプログラミング言語 RubyによるScheme処理系の実装

Java (5) 1 Lesson 3: x 2 +4x +5 f(x) =x 2 +4x +5 x f(10) x Java , 3.0,..., 10.0, 1.0, 2.0,... flow rate (m**3/s) "flow

: : : TSTank 2

(CC Attribution) Lisp 2.1 (Gauche )

presen.gby

コンピュータ概論

解きながら学ぶC言語

:30 12:00 I. I VI II. III. IV. a d V. VI

Microsoft Word - keisankigairon.ch doc

新・明解Java入門

test.gby

新・明解Javaで学ぶアルゴリズムとデータ構造

明解Javaによるアルゴリズムとデータ構造

r02.dvi

bash on Ubuntu on Windows bash on Ubuntu on Windows bash on Ubuntu on Windows bash on Ubuntu on Windows bash on Ubuntu on Windows ˆ Windows10 64bit Wi

明解Javaによるアルゴリズムとデータ構造

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * *

2 1. Ubuntu 1.1 OS OS OS ( OS ) OS ( OS ) VMware Player VMware Player jp/download/player/ URL VMware Plaeyr VMware

(2 Linux Mozilla [ ] [ ] [ ] [ ] URL 2 qkc, nkc ~/.cshrc (emacs 2 set path=($path /usr/meiji/pub/linux/bin tcsh b

明解Java入門編

r1.dvi


Java学習教材

Java (7) Lesson = (1) 1 m 3 /s m 2 5 m 2 4 m 2 1 m 3 m 1 m 0.5 m 3 /ms 0.3 m 3 /ms 0.6 m 3 /ms 1 1 3

:30 12:00 I. I VI II. III. IV. a d V. VI

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* (

r07.dvi

やさしいJavaプログラミング -Great Ideas for Java Programming サンプルPDF

新・明解Javaで学ぶアルゴリズムとデータ構造

ohp07.dvi

bdd.gby

monad.gby

Java Java Java Java Java 4 p * *** ***** *** * Unix p a,b,c,d 100,200,250,500 a*b = a*b+c = a*b+c*d = (a+b)*(c+d) = 225

fp.gby

O(N) ( ) log 2 N

untitled

N88 BASIC 0.3 C: My Documents 0.6: 0.3: (R) (G) : enterreturn : (F) BA- SIC.bas 0.8: (V) 0.9: 0.5:

Java 3 p.2 3 Java : boolean Graphics draw3drect fill3drect C int C OK while (1) int boolean switch case C Calendar java.util.calendar A

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU

新・明解C言語で学ぶアルゴリズムとデータ構造

r08.dvi

1. A0 A B A0 A : A1,...,A5 B : B1,...,B

1. A0 A B A0 A : A1,...,A5 B : B1,...,B

syspro-0405.ppt

Ruby Ruby ruby Ruby G: Ruby>ruby Ks sample1.rb G: Ruby> irb (interactive Ruby) G: Ruby>irb -Ks irb(main):001:0> print( ) 44=>


A B 1: Ex. MPICH-G2 C.f. NXProxy [Tanaka] 2:


(Java/FX ) Java CD Java version Java VC++ Python Ruby Java Java Eclipse Java Java 3 Java for Everyone 2 10 Java Midi Java JavaFX Shape Canvas C

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

1-4 int a; std::cin >> a; std::cout << "a = " << a << std::endl; C++( 1-4 ) stdio.h iostream iostream.h C++ include.h 1-4 scanf() std::cin >>

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

Android Windows 8 AP 9 AP ios & Android 10 ST 11 ST ios 12 ST Android 13 ST Win & Mac 14 ST ios 15 ST Android

2

VDM-SL VDM VDM-SL Toolbox VDM++ Toolbox 1 VDM-SL VDM++ Web bool

untitled

ohp08.dvi

WinHPC ppt

問題1 以下に示すプログラムは、次の処理をするプログラムである

Ruby演習テキスト1

(1/2) 2/45 HPC top runner application programmer PC-9801F N88-BASIC Quick BASIC + DOS ( ) BCB Windows Percolation, Event-driven MD ActionScript Flash

DA100データアクイジションユニット通信インタフェースユーザーズマニュアル

untitled

,…I…y…„†[…e…B…fi…O…V…X…e…•‡Ì…J†[…l…‰fi®“ì‡Ì›Â”‰›»pdfauthor

Functional Programming

3 3.1 algebraic datatype data k = 1 1,1... 1,n1 2 2,1... 2,n2... m m,1... m,nm 1 m m m,1,..., m,nm m 1, 2,..., k 1 data Foo x y = Alice x [y] B

r3.dvi

(Eclipse\202\305\212w\202\324Java2\215\374.pdf)

Java プログラミング Ⅰ 7 回目 switch 文と論理演算子 今日の講義講義で学ぶ内容 switch 文 論理演算子 条件演算子 条件判断文 3 switch 文 switch 文 式が case のラベルと一致する場所から直後の break; まで処理しますどれにも一致致しない場合 def

10 (1) s 10.2 rails c Rails 7 > item = PlanItem.new => #<PlanItem id nil, name nil,...> > item.name = "" => "" > item.valid? => true valid? true false

10/8 Finder,, 1 1. Finder MAC OS X 2. ( ) MAC OS X Java ( ) 3. MAC OS X Java ( ) / 10

(search: ) [1] ( ) 2 (linear search) (sequential search) 1

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

PowerPoint プレゼンテーション

Emacs Ruby..

Transcription:

I Exercise on Programming I http://bit.ly/oitprog1 1, 2 of 14 ( RD S ) I 1, 2 of 14 1 / 44

Ruby Ruby ( RD S ) I 1, 2 of 14 2 / 44

7 5 9 2 9 3 3 2 6 5 1 3 2 5 6 4 7 8 4 5 2 7 9 6 4 7 1 3 ( RD S ) I 1, 2 of 14 3 / 44

3 q q = 7 5 9 2 9 3 1, 2,, 9 3 2 6 5 1 3 2 5 6 4 7 8 4 5 2 7 9 6 4 7 1 3 1 q 2 q q 3 q 1 9 q 1, q 2,, q 9 q i ( RD S ) I 1, 2 of 14 4 / 44

solvesdk q = if chksdk q == False then [] else if zp == 81 then q (81) q else concat (map (\i -> let q' = (take zp q) ++ [i] ++ drop (zp + 1) q in solvesdk q') [1..9]) where zp = index q 0 q q ( RD S ) I 1, 2 of 14 5 / 44

( Haskell) q0 = [7, 0, 0, 0, 0, 5, 9, 0, 0, 0, 2, 0, 0, 9, 0, 0, 3, 0, 0, 0, 3, 2, 0, 6, 0, 0, 5, 1, 3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 7, 8, 4, 0, 0, 5, 0, 2, 7, 0, 0, 0, 9, 0, 0, 6, 0, 0, 4, 0, 0, 0, 7, 1, 0, 0, 0, 0, 3] main = mapm_ (\i -> print (take 9 (drop i ans))) [0,9..72] where ans = solvesdk q0 chkdup a = foldl (&&) True (map (\i -> length (filter (== i) a) <= 1) [1..9]) chksdk x = foldl (&&) True (map (\i -> chkdup (take 9 (drop i x))) [0,9..72]) && foldl (&&) True (map (\i -> chkdup (map (\j -> x!!(i + j)) [0,9..72])) [0..8]) && foldl (&&) True (map (\i -> chkdup (map (\j -> x!!(i + j)) box)) tl) where box = [0, 1, 2, 9, 10, 11, 18, 19, 20] tl = [0, 3, 6, 27, 30, 33, 54, 57, 60] index [] _ = 0 index (x:xs) tgt = if x == tgt then 0 else 1 + index xs tgt -- solvesdk q = if chksdk q == False then [] else if zp == 81 then q else concat (map (\i -> let q' = (take zp q) ++ [i] ++ drop (zp + 1) q in solvesdk q') [1..9]) where zp = index q 0 ( RD S ) I 1, 2 of 14 6 / 44

( Ruby) 14 q0 = [7, 0, 0, 0, 0, 5, 9, 0, 0, 0, 2, 0, 0, 9, 0, 0, 3, 0, 0, 0, 3, 2, 0, 6, 0, 0, 5, 1, 3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 7, 8, 4, 0, 0, 5, 0, 2, 7, 0, 0, 0, 9, 0, 0, 6, 0, 0, 4, 0, 0, 0, 7, 1, 0, 0, 0, 0, 3, ] def chk9(ary) # dup test (1 line) (1..9).inject(true) { a, i ary.count(i) > 1? false : a } end def chk_all(ary) # dup test (all) 9.times { i return false unless chk9(ary[i*9,9]) return false unless chk9((0..8).map{ j ary[i + j * 9] }) } [0,3,6,27,30,33,54,57,60].each { i return false unless chk9( ary[i,3] + ary[i+9,3] + ary[i+18,3] ) } true end def solve_sdk(q) return nil unless chk_all(q) return q unless tgt = q.index(0) ans = nil (1..9).each { i q[tgt] = i return ans if ans = solve_sdk(q) } q[tgt] = 0 nil end ans = solve_sdk(q0) 9.times { i p ans[i * 9, 9] } ( RD S ) I 1, 2 of 14 7 / 44

=3 / ( =2, =0 ) =3 / ( 1 3 ) =16 :, ( ),,, ( ),, ( RD S ) I 1, 2 of 14 8 / 44

Wi-Fi ssh ( RD S ) I 1, 2 of 14 9 / 44

edu1 edu2 edu3 PC ( RD S ) I 1, 2 of 14 10 / 44

Wi-Fi Windows macos Wi-Fi OIT-AirLAN.1x ID e1 ( : e1x19123) OIT-AirLAN.1x OIT-AirLAN ( RD S ) I 1, 2 of 14 11 / 44

ssh Windows mac, Linux Windows https://gitforwindows.org [Download] ( RD S ) I 1, 2 of 14 12 / 44

( RD S ) I 1, 2 of 14 13 / 44

0 + 1 +... + 9 in C #include <stdio.h> int main() { int sum; int i; for (i = 0, sum = 0; i < 10; i++) { sum = sum + i; } printf("%d\n", sum); return 0; } ( RD S ) I 1, 2 of 14 14 / 44

0 + 1 +... + 9 in Java public class Sum { public static void main(string[] args) { int i; int sum; for (i = 0, sum = 0; i < 10; i++) { sum = sum + i; } System.out.println(sum); } } ( RD S ) I 1, 2 of 14 15 / 44

0 + 1 +... + 9 in JavaScript let sum = 0 for (let i = 0; i < 10; i++) { sum = sum + i } console.log(sum) ( RD S ) I 1, 2 of 14 16 / 44

0 + 1 +... + 9 in Python sum = 0 for i in range(10): sum = sum + i print(sum) ( RD S ) I 1, 2 of 14 17 / 44

0 + 1 +... + 9 in Ruby sum = 0 (0..9).each { i sum = sum + i } puts sum ( RD S ) I 1, 2 of 14 18 / 44

0 + 1 +... + 9 in Swift var sum = 0 (1...9).forEach{(i) in sum = sum + i } print(sum) ( RD S ) I 1, 2 of 14 19 / 44

0 + 1 +... + 9 in Haskell main = print $ mysum [0..9] mysum [a] = a mysum (car:cdr) = car + mysum cdr ( RD S ) I 1, 2 of 14 20 / 44

0 + 1 +... + 9 in (old) BASIC 10 S=0 20 FOR I=0 TO 9 30 S=S+I 40 NEXT I 50 PRINT S ( RD S ) I 1, 2 of 14 21 / 44

0 + 1 +... + 9 in Scratch ( RD S ) I 1, 2 of 14 22 / 44

classroom (1 of 2) 1 https://classroom.google.com 2 OIT Google OIT ( RD S ) I 1, 2 of 14 23 / 44

classroom (2 of 2) 3 ( 1nmp0c9) ( RD S ) I 1, 2 of 14 24 / 44

(Windows, ) 1 Git Git Bash 2 ( ) ($ ) $ ssh e1w19???@edu1.rd.oit.ac.jp $ ssh e1x19???@edu2.rd.oit.ac.jp $ ssh e1919???@edu3.rd.oit.ac.jp 3 (yes/no) yes 4 ( ) ( RD S ) I 1, 2 of 14 25 / 44

(macos, ) 1 Launcher 2 ( ) (mac $ ) mac: someone$ ssh e1w19???@edu1.rd.oit.ac.jp mac: someone$ ssh e1x19???@edu2.rd.oit.ac.jp mac: someone$ ssh e1919???@edu3.rd.oit.ac.jp 3 (yes/no) yes 4 ( ) ( RD S ) I 1, 2 of 14 26 / 44

(, ) Windows/macOS 1 URL https://edu2.rd.oit.ac.jp:3000 https://edu2.rd.oit.ac.jp:3001 https://edu2.rd.oit.ac.jp:3002 https://edu2.rd.oit.ac.jp:3003 https://edu3.rd.oit.ac.jp:3000 https://edu3.rd.oit.ac.jp:3001 https://edu3.rd.oit.ac.jp:3002 https://edu3.rd.oit.ac.jp:3003 2 (e1w1???? ) ( RD S ) I 1, 2 of 14 27 / 44

( ) logout logout ( exit ) ( RD S ) I 1, 2 of 14 28 / 44

1 Windows Git Bash 1 ( RD S ) I 1, 2 of 14 29 / 44

UNIX cal edu2: e1x19999$ cal 4 2019 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 cal 2020 cal 9 1752 cal edu2: e1x19999$ w date pi 1000 ( RD S ) I 1, 2 of 14 30 / 44

: program me 1. 2. 3. program(me) counter ( RD S ) I 1, 2 of 14 31 / 44

program (source code) editor 1 2 3 ( RD S ) I 1, 2 of 14 32 / 44

Ruby 1 buf = [] 2 while true do 3 buf.unshift(" " * rand(40) + "#") 4 puts(buf[0]) 5 sleep(0.03) 6 end ( ) ( RD S ) I 1, 2 of 14 33 / 44

(editor) nano nano game.rb game.rb.rb ruby ˆX [Control] [X] ( RD S ) I 1, 2 of 14 34 / 44

1 1 buf = [] [] ()( ) {}( ) =( ) ( RD S ) I 1, 2 of 14 35 / 44

2 1 buf 2 while = [] true do while true do ( RD S ) I 1, 2 of 14 36 / 44

3 1 buf = [] 2 while true do 3 buf.unshift(" " * rand(40) + "#") 3 2 ( ( ) ) " " ([SHIFT] [2]) *( ) [SHIFT] [L] 2 ( RD S ) I 1, 2 of 14 37 / 44

4, 5 1 buf = [] 2 while true do 3 buf.unshift(" " * rand(40) + "#") 4 puts(buf[0]) 5 sleep(0.03) 3 4 [0] 5 (0.03) ( RD S ) I 1, 2 of 14 38 / 44

6 ( ) 1 buf = [] 2 while true do 3 buf.unshift(" " * rand(40) + "#") 4 puts(buf[0]) 5 sleep(0.03) 6 end 0 ( )end ( RD S ) I 1, 2 of 14 39 / 44

1 ˆX ( [Control]+[X] ) 2 y 3 [Enter] ( [Return]) Y [Enter] ( RD S ) I 1, 2 of 14 40 / 44

ls e1w19999@edu1: $ ls game.rb e1w19999@edu1: $ ls ls list 2 2 ( RD S ) I 1, 2 of 14 41 / 44

Ruby ruby e1w19999@edu1: $ ruby game.rb (!?) ( RD S ) I 1, 2 of 14 42 / 44

Windows [Windows] [Print Screen (Prt Sc)] macos [Shift]+[command] [3] ( ) ( RD S ) I 1, 2 of 14 43 / 44

game.rb Google classroom (https://classroom.google.com) ( RD S ) I 1, 2 of 14 44 / 44