Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,5 +1,5 @@
|
|||
V doors = [0B] * 100
|
||||
L(i) 100
|
||||
L(i) 0.<100
|
||||
L(j) (i .< 100).step(i + 1)
|
||||
doors[j] = !doors[j]
|
||||
print(‘Door ’(i + 1)‘: ’(I doors[i] {‘open’} E ‘close’))
|
||||
|
|
|
|||
|
|
@ -1,58 +1,45 @@
|
|||
;------------------------------------------------------
|
||||
; useful equates
|
||||
;------------------------------------------------------
|
||||
wboot equ 0 ; jump to BIOS warm boot routine
|
||||
bdos equ 5 ; BDOS entry
|
||||
conout equ 2 ; BDOS console output function
|
||||
bdos equ 5 ; BDOS entry
|
||||
conout equ 2 ; BDOS console output function
|
||||
putstr equ 9 ; BDOS print string function
|
||||
ndoors equ 100
|
||||
ndoors equ 100 ; number of doors
|
||||
;
|
||||
org 100h
|
||||
lxi sp,stack ; set our own stack
|
||||
lxi d,signon ; print signon message
|
||||
lxi d,intro ; print introductory message
|
||||
mvi c,putstr
|
||||
call bdos
|
||||
call bdos
|
||||
;
|
||||
; generate sequence of squares from 1 to specified limit
|
||||
; generate sequence of squares to specified limit
|
||||
; HL holds the current square
|
||||
; DE holds the increment
|
||||
; BC holds the negative of the limit
|
||||
;
|
||||
gensqr:
|
||||
lxi h,1 ; starting value of square
|
||||
gensqr: lxi h,1 ; starting value of square
|
||||
lxi d,3 ; starting value of increment
|
||||
lxi b,ndoors+1
|
||||
sqrs2:
|
||||
call cmpbchl ; have we exceeded the limit?
|
||||
jnc done ; we're finished
|
||||
call putdec ; otherwise print current square
|
||||
mvi a,' ' ; separate with a space
|
||||
call putchr
|
||||
dad d ; square += incrememnt
|
||||
inx d ; increment += 2
|
||||
lxi b,-ndoors
|
||||
sqrs2: call putdec ; otherwise print current square
|
||||
mvi a,' ' ; separate with a space
|
||||
call putchr
|
||||
push h ; have we reached the limit?
|
||||
dad b
|
||||
pop h
|
||||
jc done ; CY if HL > limit
|
||||
dad d ; square += incrememnt
|
||||
inx d ; increment += 2
|
||||
inx d
|
||||
jmp sqrs2 ; repeat until finished
|
||||
jmp sqrs2 ; repeat until finished
|
||||
;
|
||||
done: jmp wboot ; exit to command prompt
|
||||
;
|
||||
;---------------------------------------------------
|
||||
; 16-bit unsigned comparison of HL and BC
|
||||
; if HL = BC then Z flag set
|
||||
; if HL < BC then CY flag set (NC if HL >= BC)
|
||||
;------------------------------------------------------
|
||||
cmpbchl:
|
||||
mov a,h
|
||||
cmp b
|
||||
rnz
|
||||
mov a,l
|
||||
cmp c
|
||||
ret
|
||||
done: jmp wboot ; exit with warm boot
|
||||
;---------------------------------------------------
|
||||
; console output of char in A register
|
||||
;---------------------------------------------------
|
||||
putchr: push h
|
||||
push d
|
||||
push b
|
||||
putchr: push h
|
||||
push d
|
||||
push b
|
||||
mov e,a
|
||||
mvi c,conout
|
||||
call bdos
|
||||
call bdos
|
||||
pop b
|
||||
pop d
|
||||
pop h
|
||||
|
|
@ -61,9 +48,9 @@ putchr: push h
|
|||
; Output decimal number to console
|
||||
; HL holds 16-bit unsigned binary number to print
|
||||
;---------------------------------------------------
|
||||
putdec: push b
|
||||
push d
|
||||
push h
|
||||
putdec: push b
|
||||
push d
|
||||
push h
|
||||
lxi b,-10
|
||||
lxi d,-1
|
||||
putdec2:
|
||||
|
|
@ -78,7 +65,7 @@ putdec2:
|
|||
cnz putdec ; recursive call
|
||||
mov a,e
|
||||
adi '0'
|
||||
call putchr
|
||||
call putchr
|
||||
pop h
|
||||
pop d
|
||||
pop b
|
||||
|
|
@ -86,7 +73,7 @@ putdec2:
|
|||
;---------------------------------------------------
|
||||
; data area and stack
|
||||
;---------------------------------------------------
|
||||
signon: db 'The open doors are: $'
|
||||
intro: db 'The open doors are: $'
|
||||
stack equ $+128 ; 64-level stack
|
||||
;
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
with Ada.Text_Io; use Ada.Text_Io;
|
||||
|
||||
procedure Doors is
|
||||
type Door_State is (Closed, Open);
|
||||
type Door_List is array(Positive range 1..100) of Door_State;
|
||||
The_Doors : Door_List := (others => Closed);
|
||||
begin
|
||||
for I in 1..100 loop
|
||||
for J in The_Doors'range loop
|
||||
if J mod I = 0 then
|
||||
if The_Doors(J) = Closed then
|
||||
The_Doors(J) := Open;
|
||||
else
|
||||
The_Doors(J) := Closed;
|
||||
end if;
|
||||
end if;
|
||||
end loop;
|
||||
end loop;
|
||||
for I in The_Doors'range loop
|
||||
Put_Line(Integer'Image(I) & " is " & Door_State'Image(The_Doors(I)));
|
||||
end loop;
|
||||
end Doors;
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
with Ada.Text_Io; use Ada.Text_Io;
|
||||
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
|
||||
|
||||
procedure Doors_Optimized is
|
||||
Num : Float;
|
||||
begin
|
||||
for I in 1..100 loop
|
||||
Num := Sqrt(Float(I));
|
||||
Put(Integer'Image(I) & " is ");
|
||||
if Float'Floor(Num) = Num then
|
||||
Put_Line("Opened");
|
||||
else
|
||||
Put_Line("Closed");
|
||||
end if;
|
||||
end loop;
|
||||
end Doors_Optimized;
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
# find the first few squares via the unoptimised door flipping method
|
||||
scope
|
||||
|
||||
local doorMax := 100;
|
||||
local door;
|
||||
create register door( doorMax );
|
||||
|
||||
# set all doors to closed
|
||||
for i to doorMax do door[ i ] := false od;
|
||||
|
||||
# repeatedly flip the doors
|
||||
for i to doorMax do
|
||||
for j from i to doorMax by i do door[ j ] := not door[ j ] od
|
||||
od;
|
||||
|
||||
# display the results
|
||||
for i to doorMax do if door[ i ] then write( " ", i ) fi od; print()
|
||||
|
||||
epocs
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
#include <array.au3>
|
||||
$doors = 100
|
||||
|
||||
;door array, 0 = closed, 1 = open
|
||||
Local $door[$doors +1]
|
||||
|
||||
For $ii = 1 To $doors
|
||||
For $i = $ii To $doors Step $ii
|
||||
$door[$i] = Not $door[$i]
|
||||
next
|
||||
Next
|
||||
|
||||
;display to screen
|
||||
For $i = 1 To $doors
|
||||
ConsoleWrite (Number($door[$i])& " ")
|
||||
If Mod($i,10) = 0 Then ConsoleWrite(@CRLF)
|
||||
Next
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
(defun CreateDoors (n / doors)
|
||||
(repeat n
|
||||
(setq doors (cons nil doors))
|
||||
)
|
||||
)
|
||||
|
||||
(defun Doors (doors / cnt)
|
||||
(setq cnt 0)
|
||||
(mapcar
|
||||
'(lambda (d)
|
||||
(zerop (rem (sqrt (setq cnt (1+ cnt))) 1))
|
||||
)
|
||||
doors
|
||||
)
|
||||
)
|
||||
|
||||
> (Doors (CreateDoors 100))
|
||||
(T nil nil T nil nil nil nil T nil nil nil nil nil nil T nil nil nil nil nil nil nil nil T nil nil nil nil nil nil nil nil nil nil T nil nil nil nil nil nil nil nil nil nil nil nil T nil nil nil nil nil nil nil nil nil nil nil nil nil nil T nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil T nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil T nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil T nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil T nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil T nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil T nil nil nil nil)
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. 100Doors.
|
||||
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 Current-n PIC 9(3).
|
||||
01 StepSize PIC 9(3).
|
||||
01 DoorTable.
|
||||
02 Doors PIC 9(1) OCCURS 100 TIMES.
|
||||
88 ClosedDoor VALUE ZERO.
|
||||
01 Idx PIC 9(3).
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
Begin.
|
||||
INITIALIZE DoorTable
|
||||
PERFORM VARYING StepSize FROM 1 BY 1 UNTIL StepSize > 100
|
||||
PERFORM VARYING Current-n FROM StepSize BY StepSize
|
||||
UNTIL Current-n > 100
|
||||
SUBTRACT Doors (Current-n) FROM 1 GIVING Doors (Current-n)
|
||||
END-PERFORM
|
||||
END-PERFORM
|
||||
|
||||
PERFORM VARYING Idx FROM 1 BY 1
|
||||
UNTIL Idx > 100
|
||||
IF ClosedDoor (Idx)
|
||||
DISPLAY Idx " is closed."
|
||||
ELSE
|
||||
DISPLAY Idx " is open."
|
||||
END-IF
|
||||
END-PERFORM
|
||||
|
||||
STOP RUN
|
||||
.
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
Require Import List.
|
||||
|
||||
Fixpoint rep {A} (a : A) n :=
|
||||
match n with
|
||||
| O => nil
|
||||
| S n' => a::(rep a n')
|
||||
end.
|
||||
|
||||
Fixpoint flip (l : list bool) (n k : nat) : list bool :=
|
||||
match l with
|
||||
| nil => nil
|
||||
| cons h t => match k with
|
||||
| O => (negb h) :: (flip t n n)
|
||||
| S k' => h :: (flip t n k')
|
||||
end
|
||||
end.
|
||||
|
||||
Definition flipeach l n := flip l n n.
|
||||
|
||||
Fixpoint flipwhile l n :=
|
||||
match n with
|
||||
| O => flipeach l 0
|
||||
| S n' => flipwhile (flipeach l (S n')) n'
|
||||
end.
|
||||
|
||||
Definition prison cells := flipwhile (rep false cells) cells.
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
Require Import List.
|
||||
|
||||
Fixpoint prisoo' nd n k accu :=
|
||||
match nd with
|
||||
| O => rev accu
|
||||
| S nd' => let ra := match k with
|
||||
| O => (true, S n, (n + n))
|
||||
| S k' => (false, n, k')
|
||||
end in
|
||||
prisoo' nd' (snd (fst ra)) (snd ra) ((fst (fst ra))::accu)
|
||||
end.
|
||||
|
||||
Definition prisoo cells := prisoo' cells 1 0 nil.
|
||||
|
|
@ -1 +0,0 @@
|
|||
Goal prison 100 = prisoo 100. compute. reflexivity. Qed.
|
||||
|
|
@ -1 +0,0 @@
|
|||
Goal forall n, prison n = prisoo n. Abort.
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import system'routines;
|
||||
import extensions;
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
var Doors := Array.allocate(100).populate::(n=>false);
|
||||
for(int i := 0; i < 100; i++)
|
||||
|
|
|
|||
|
|
@ -1,83 +0,0 @@
|
|||
(defun create-doors ()
|
||||
"Returns a list of closed doors
|
||||
|
||||
Each door only has two status: open or closed.
|
||||
If a door is closed it has the value 0, if it's open it has the value 1."
|
||||
(let ((return_value '(0))
|
||||
;; There is already a door in the return_value, so k starts at 1
|
||||
;; otherwise we would need to compare k against 99 and not 100 in
|
||||
;; the while loop
|
||||
(k 1))
|
||||
(while (< k 100)
|
||||
(setq return_value (cons 0 return_value))
|
||||
(setq k (+ 1 k)))
|
||||
return_value))
|
||||
|
||||
(defun toggle-single-door (doors)
|
||||
"Toggle the stat of the door at the `car' position of the DOORS list
|
||||
|
||||
DOORS is a list of integers with either the value 0 or 1 and it represents
|
||||
a row of doors.
|
||||
|
||||
Returns a list where the `car' of the list has it's value toggled (if open
|
||||
it becomes closed, if closed it becomes open)."
|
||||
(if (= (car doors) 1)
|
||||
(cons 0 (cdr doors))
|
||||
(cons 1 (cdr doors))))
|
||||
|
||||
(defun toggle-doors (doors step original-step)
|
||||
"Step through all elements of the doors' list and toggle a door when step is 1
|
||||
|
||||
DOORS is a list of integers with either the value 0 or 1 and it represents
|
||||
a row of doors.
|
||||
STEP is the number of doors we still need to transverse before we arrive
|
||||
at a door that has to be toggled.
|
||||
ORIGINAL-STEP is the value of the argument step when this function is
|
||||
called for the first time.
|
||||
|
||||
Returns a list of doors"
|
||||
(cond ((null doors)
|
||||
'())
|
||||
((= step 1)
|
||||
(cons (car (toggle-single-door doors))
|
||||
(toggle-doors (cdr doors) original-step original-step)))
|
||||
(t
|
||||
(cons (car doors)
|
||||
(toggle-doors (cdr doors) (- step 1) original-step)))))
|
||||
|
||||
(defun main-program ()
|
||||
"The main loop for the program"
|
||||
(let ((doors_list (create-doors))
|
||||
(k 1)
|
||||
;; We need to define max-specpdl-size and max-specpdl-size to big
|
||||
;; numbers otherwise the loop reaches the max recursion depth and
|
||||
;; throws an error.
|
||||
;; If you want more information about these variables, press Ctrl
|
||||
;; and h at the same time and then press v and then type the name
|
||||
;; of the variable that you want to read the documentation.
|
||||
(max-specpdl-size 5000)
|
||||
(max-lisp-eval-depth 2000))
|
||||
(while (< k 101)
|
||||
(setq doors_list (toggle-doors doors_list k k))
|
||||
(setq k (+ 1 k)))
|
||||
doors_list))
|
||||
|
||||
(defun print-doors (doors)
|
||||
"This function prints the values of the doors into the current buffer.
|
||||
|
||||
DOORS is a list of integers with either the value 0 or 1 and it represents
|
||||
a row of doors.
|
||||
"
|
||||
;; As in the main-program function, we need to set the variable
|
||||
;; max-lisp-eval-depth to a big number so it doesn't reach max recursion
|
||||
;; depth.
|
||||
(let ((max-lisp-eval-depth 5000))
|
||||
(unless (null doors)
|
||||
(insert (int-to-string (car doors)))
|
||||
(print-doors (cdr doors)))))
|
||||
|
||||
;; Returns a list with the final solution
|
||||
(main-program)
|
||||
|
||||
;; Print the final solution on the buffer
|
||||
(print-doors (main-program))
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
(defun one-hundred-doors(initial-state)
|
||||
"Turn doors in INITIAL-STATE according to 100 Doors problem."
|
||||
(interactive "nEnter initial doors' state (as a number): ")
|
||||
(cl-loop for x from 1 to 100
|
||||
do (cl-loop for y from (1- x) to 99 by x
|
||||
do (setq initial-state (logxor initial-state (ash 1 y)))))
|
||||
(let ((counter 1)
|
||||
(open-doors nil))
|
||||
(while (> initial-state 0)
|
||||
(when (eq (mod initial-state 2) 1)
|
||||
(push counter open-doors))
|
||||
(cl-incf counter)
|
||||
(setq initial-state (/ initial-state 2)))
|
||||
(message "Open doors are %s" (reverse open-doors))))
|
||||
|
||||
(one-hundred-doors 0)
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
-- doors.ex
|
||||
include std/console.e
|
||||
sequence doors
|
||||
doors = repeat( 0, 100 ) -- 1 to 100, initialised to false
|
||||
|
||||
for pass = 1 to 100 do
|
||||
for door = pass to 100 by pass do
|
||||
--printf( 1, "%d", doors[door] )
|
||||
--printf( 1, "%d", not doors[door] )
|
||||
doors[door] = not doors[door]
|
||||
end for
|
||||
end for
|
||||
|
||||
sequence oc
|
||||
|
||||
for i = 1 to 100 do
|
||||
if doors[i] then
|
||||
oc = "open"
|
||||
else
|
||||
oc = "closed"
|
||||
end if
|
||||
printf( 1, "door %d is %s\n", { i, oc } )
|
||||
end for
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
class Main
|
||||
{
|
||||
static public function main()
|
||||
{
|
||||
findOpenDoors( 100 );
|
||||
}
|
||||
|
||||
static function findOpenDoors( n : Int )
|
||||
{
|
||||
var door = [];
|
||||
for( i in 0...n + 1 ){ door[ i ] = false; }
|
||||
for( i in 1...n + 1 ){
|
||||
var j = i;
|
||||
while( j <= n ){
|
||||
door[ j ] = ! door[ j ];
|
||||
j += i;
|
||||
}
|
||||
}
|
||||
for( i in 1...n + 1 ){
|
||||
if( door[ i ] ){ Sys.print( ' $i' ); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
class RosettaDemo
|
||||
{
|
||||
static public function main()
|
||||
{
|
||||
findOpenLockers(100);
|
||||
}
|
||||
|
||||
static function findOpenLockers(n : Int)
|
||||
{
|
||||
var i = 1;
|
||||
|
||||
while((i*i) <= n)
|
||||
{
|
||||
Sys.println(i*i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
(for i (range 1 101)
|
||||
i2 (range (dec i) 100 i)
|
||||
(var! doors (set-at [i2] (! (i2 doors))))
|
||||
(var! doors (set-at [i2] (not (i2 doors))))
|
||||
(continue))
|
||||
|
||||
(-> (xmap vec doors)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,4 @@
|
|||
REM Author.....: Eva Broccoli
|
||||
REM Date.......: 23 May 2025
|
||||
REM Description: OPL solution for "100 doors" task on https://rosettacode.org
|
||||
REM Tested with: Psion Series 3a & Series 5
|
||||
REM Contact....: eva.klassen@kittymail.com
|
||||
|
||||
REM https://github.com/Eva-Broccoli/OPL-Rosetta-Code/blob/main/A100door.opl
|
||||
PROC main:
|
||||
LOCAL door%(100),i%,j%
|
||||
i%=1
|
||||
|
|
|
|||
|
|
@ -1,24 +1,22 @@
|
|||
package main
|
||||
package doors
|
||||
|
||||
import "core:fmt"
|
||||
|
||||
main :: proc() {
|
||||
using fmt
|
||||
doors: [100]bool
|
||||
|
||||
Door_State :: enum {Closed, Open}
|
||||
for every_n := 1; every_n < len(doors); every_n += 1 {
|
||||
i := every_n - 1
|
||||
for true {
|
||||
if i >= len(doors) do break
|
||||
|
||||
doors := [?]Door_State { 0..<100 = .Closed }
|
||||
doors[i] = !doors[i]
|
||||
|
||||
for i in 1..=100 {
|
||||
for j := i-1; j < 100; j += i {
|
||||
if doors[j] == .Closed {
|
||||
doors[j] = .Open
|
||||
} else {
|
||||
doors[j] = .Closed
|
||||
}
|
||||
}
|
||||
}
|
||||
for state, i in doors {
|
||||
println("Door: ",int(i+1)," -> ",state)
|
||||
}
|
||||
i += every_n
|
||||
}
|
||||
}
|
||||
|
||||
for &door, i in doors {
|
||||
if door do fmt.printf("%d ", i + 1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import "core:math"
|
||||
|
||||
main :: proc() {
|
||||
using fmt
|
||||
|
|
@ -11,12 +10,15 @@ main :: proc() {
|
|||
doors := [?]Door_State { 0..<100 = .Closed }
|
||||
|
||||
for i in 1..=100 {
|
||||
res := math.sqrt_f64( f64(i) )
|
||||
if math.mod_f64( res, 1) == 0 {
|
||||
doors[i-1] = .Open
|
||||
} else {
|
||||
doors[i-1] = .Closed
|
||||
}
|
||||
println("Door: ", i, " -> ", doors[i-1])
|
||||
for j := i-1; j < 100; j += i {
|
||||
if doors[j] == .Closed {
|
||||
doors[j] = .Open
|
||||
} else {
|
||||
doors[j] = .Closed
|
||||
}
|
||||
}
|
||||
}
|
||||
for state, i in doors {
|
||||
println("Door: ",int(i+1)," -> ",state)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
$doors = @(0..99)
|
||||
for($i=0; $i -lt 100; $i++) {
|
||||
$doors[$i] = 0 # start with all doors closed
|
||||
}
|
||||
for($i=0; $i -lt 100; $i++) {
|
||||
$step = $i + 1
|
||||
for($j=$i; $j -lt 100; $j = $j + $step) {
|
||||
$doors[$j] = $doors[$j] -bxor 1
|
||||
}
|
||||
}
|
||||
foreach($doornum in 1..100) {
|
||||
if($doors[($doornum-1)] -eq $true) {"$doornum open"}
|
||||
else {"$doornum closed"}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
function Get-DoorState($NumberOfDoors)
|
||||
{
|
||||
begin
|
||||
{
|
||||
$Doors = @()
|
||||
$Multiple = 1
|
||||
}
|
||||
|
||||
process
|
||||
{
|
||||
for ($i = 1; $i -le $NumberOfDoors; $i++)
|
||||
{
|
||||
$Door = [pscustomobject]@{
|
||||
Name = $i
|
||||
Open = $false
|
||||
}
|
||||
|
||||
$Doors += $Door
|
||||
}
|
||||
|
||||
While ($Multiple -le $NumberOfDoors)
|
||||
{
|
||||
Foreach ($Door in $Doors)
|
||||
{
|
||||
if ($Door.name % $Multiple -eq 0)
|
||||
{
|
||||
If ($Door.open -eq $False){$Door.open = $True}
|
||||
Else {$Door.open = $False}
|
||||
}
|
||||
}
|
||||
|
||||
$Multiple++
|
||||
}
|
||||
}
|
||||
|
||||
end {$Doors}
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
$doors = 1..100 | ForEach-Object {0}
|
||||
1..100 | ForEach-Object { $a=$_;1..100 | Where-Object { -not ( $_ % $a ) } | ForEach-Object { $doors[$_-1] = $doors[$_-1] -bxor 1 }; if ( $doors[$a-1] ) { "door opened" } else { "door closed" } }
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
$doors = 1..100 | ForEach-Object {0}
|
||||
$visited = 1..100
|
||||
1..100 | ForEach-Object { $a=$_;$visited[0..([math]::floor(100/$a)-1)] | Where-Object { -not ( $_ % $a ) } | ForEach-Object { $doors[$_-1] = $doors[$_-1] -bxor 1;$visited[$_/$a-1]+=($_/$a) }; if ( $doors[$a-1] ) { "door opened" } else { "door closed" } }
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
1..100|foreach-object {$pipe += "toggle $_ |"} -begin {$pipe=""}
|
||||
filter toggle($pass) {$_.door = $_.door -xor !($_.index % $pass);$_}
|
||||
invoke-expression "1..100| foreach-object {@{index=`$_;door=`$false}} | $pipe out-host"
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
Workflow Calc-Doors {
|
||||
Foreach –parallel ($number in 1..100) {
|
||||
"Door " + $number.ToString("0000") + ": " + @{$true="Closed";$false="Open"}[([Math]::pow($number, 0.5)%1) -ne 0]
|
||||
}
|
||||
}
|
||||
Calc-Doors | sort
|
||||
|
|
@ -1 +0,0 @@
|
|||
1..10|%{"Door "+ $_*$_ + " is open"}
|
||||
|
|
@ -1,6 +1,2 @@
|
|||
for i in range(1, 101):
|
||||
if i**0.5 % 1:
|
||||
state='closed'
|
||||
else:
|
||||
state='open'
|
||||
print("Door {}:{}".format(i, state))
|
||||
print(f"Door {i}:{"closed" if i**0.5 % 1 else "open"}")
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
for i in range(1,11): print("Door %s is open" % i**2)
|
||||
for i in range(1,11): print(f"Door {i**2} is open")
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
doors: array/initial 100 'closed
|
||||
repeat i 100 [
|
||||
door: at doors i
|
||||
forskip door i [change door either 'open = first door ['closed] ['open]]
|
||||
]
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
;; Create a bitset with capacity for 100 bits (representing 100 doors)
|
||||
;; Each bit represents a door state: 0 = closed, 1 = open
|
||||
doors: make bitset! 100
|
||||
|
||||
;; Outer loop: Make 100 passes (i = 1 to 100)
|
||||
repeat i 100 [
|
||||
;; Inner loop: Check each door position (j = 1 to 100)
|
||||
repeat j 100 [
|
||||
;; If door j index is divisible by pass number i (no remainder)
|
||||
if zero? (j // i) [
|
||||
;; Toggle the door's bit:
|
||||
;; doors/:j accesses door j in the bitset
|
||||
;; 'not' flips the bit value (0 -> 1, 1 -> 0)
|
||||
doors/:j: not doors/:j
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
;; Final loop: Check which doors are open, print their numbers
|
||||
repeat i 100 [
|
||||
;; If door i's bit is set (open)
|
||||
if doors/:i [
|
||||
;; Print the door's number and that it is open
|
||||
print ["door" i "is open"]
|
||||
]
|
||||
]
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
;; Loop variable i from 1 to 10 (since 10^2 = 100, covers doors 1 to 100)
|
||||
repeat i 10 [
|
||||
;; Print that door number (i squared) is open
|
||||
;; These are exactly the doors with perfect square numbers: 1, 4, 9, ..., 100
|
||||
print ["door" (i * i) "is open"]
|
||||
]
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
Dim doorIsOpen(100), pass, currentDoor, text
|
||||
|
||||
For currentDoor = 0 To 99
|
||||
doorIsOpen(currentDoor) = False
|
||||
Next
|
||||
|
||||
For pass = 0 To 99
|
||||
For currentDoor = pass To 99 Step pass + 1
|
||||
doorIsOpen(currentDoor) = Not doorIsOpen(currentDoor)
|
||||
Next
|
||||
Next
|
||||
|
||||
For currentDoor = 0 To 99
|
||||
text = "Door #" & currentDoor + 1 & " is "
|
||||
If doorIsOpen(currentDoor) Then
|
||||
text = text & "open."
|
||||
Else
|
||||
text = text & "closed."
|
||||
End If
|
||||
WScript.Echo(text)
|
||||
Next
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
library IEEE;
|
||||
use IEEE.STD_LOGIC_1164.ALL;
|
||||
|
||||
entity DOORS is
|
||||
port (CLK: in std_logic; OUTPUT: out std_logic_vector(1 to 100));
|
||||
end DOORS;
|
||||
|
||||
architecture Behavioral of DOORS is
|
||||
begin
|
||||
process (CLK)
|
||||
variable TEMP: std_logic_vector(1 to 100);
|
||||
begin
|
||||
--setup closed doors
|
||||
TEMP := (others => '0');
|
||||
|
||||
--looping through
|
||||
for i in 1 to TEMP'length loop
|
||||
for j in i to TEMP'length loop
|
||||
if (j mod i) = 0 then
|
||||
TEMP(j) := not TEMP(j);
|
||||
end if;
|
||||
end loop;
|
||||
end loop;
|
||||
|
||||
--assign output
|
||||
OUTPUT <= TEMP;
|
||||
end process;
|
||||
end Behavioral;
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
LIBRARY ieee;
|
||||
USE ieee.std_logic_1164.all;
|
||||
|
||||
|
||||
entity doors is
|
||||
port (
|
||||
clk : in std_logic;
|
||||
reset : in std_logic;
|
||||
door : buffer std_logic_vector(1 to 100)
|
||||
);
|
||||
end entity doors;
|
||||
|
||||
|
||||
architecture rtl of doors is
|
||||
signal step : integer range 1 to 101;
|
||||
signal addr : integer range 1 to 201;
|
||||
begin
|
||||
proc_step: process(clk, reset)
|
||||
begin
|
||||
if reset = '1' then
|
||||
step <= 1;
|
||||
addr <= 1;
|
||||
door <= (others => '0');
|
||||
elsif rising_edge(clk) then
|
||||
if addr <= 100 then
|
||||
door(addr) <= not door(addr);
|
||||
addr <= addr + step;
|
||||
elsif step <= 100 then
|
||||
addr <= step + 1;
|
||||
step <= step + 1;
|
||||
end if;
|
||||
end if;
|
||||
end process;
|
||||
end;
|
||||
Loading…
Add table
Add a link
Reference in a new issue