Skip to content

Commit

Permalink
bitwise or
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzo committed Dec 19, 2023
1 parent fae102d commit 1bf1061
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 51 deletions.
49 changes: 25 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Do the thing in CI

on:
push:
branches: ['master']
branches: ["master"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -11,29 +11,30 @@ jobs:
run:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
build:
- assembly
- bun
- clang
- cobol
- crystal
- deno
- erlang
- fortran
- gcc
- go
- haskell
- java
- kotlin
- node
- perl
- php
- python3
- ruby
- rust
- scala
- zig
- assembly
- bun
- clang
- cobol
- crystal
- deno
- erlang
- fortran
- gcc
- go
- haskell
- java
- kotlin
- node
- perl
- php
- python3
- ruby
- rust
- scala
- zig
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -84,7 +85,7 @@ jobs:
path: "${{ matrix.build }}.json"

report:
needs: ['run']
needs: ["run"]
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -102,4 +103,4 @@ jobs:
cat summary.txt
- uses: actions/upload-artifact@v3
with:
path: scripts/summary.txt
path: scripts/summary.txt
12 changes: 4 additions & 8 deletions count.asm
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ parse_arg:
cmp byte [rdi + rcx], 0
jne parse_arg

mov ecx, eax
xor eax, eax
mov ebx, 2000000000
xor ecx, ecx
count:
mov eax, edx
inc eax
xor edx, edx
div ebx
cmp edx, ecx
inc ecx
or ecx, 1
cmp ecx, eax
jl count

; print
Expand Down
2 changes: 1 addition & 1 deletion count.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ int main(int argc, char *argv[]) {
int i = 0;
int target = atoi(argv[1]);
while(i < target) {
i = (i + 1) % 2000000000;
i = (i + 1) | 1;
}
printf("%d\n", i);
return 0;
Expand Down
3 changes: 1 addition & 2 deletions count.cbl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ PROCEDURE DIVISION.
ACCEPT target FROM COMMAND-LINE
PERFORM UNTIL i = target
ADD 1 TO i
DIVIDE i BY 2000000000 GIVING quotient REMAINDER rem
MOVE rem TO i
COMPUTE i = FUNCTION BINARY-OR(i, 1)
END-PERFORM.
DISPLAY i
STOP RUN.
2 changes: 1 addition & 1 deletion count.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
i = 0
target = ARGV[0].to_i.not_nil!
while i < target
i = (i + 1) % 2000000000
i = (i + 1) | 1
end

puts i
2 changes: 1 addition & 1 deletion count.deno
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let i = 0;
let target = parseInt(Deno.args[0]);
while (i < target) i = (i + 1) % 2000000000;
while (i < target) i = (i + 1) | 1;
console.log(i);
2 changes: 1 addition & 1 deletion count.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ start(Input) ->
count(0, Target).

count(N, T) when N < T ->
count((N+1) rem 2000000000, T);
count((N+1) bor 1, T);
count(N, _) ->
io:fwrite("~B~n", [N]),
init:stop(0).
2 changes: 1 addition & 1 deletion count.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ program count

i = 0
do while (i < target)
i = mod(i + 1, 2000000000);
i = ior(i + 1, 1);
end do

print *, i
Expand Down
2 changes: 1 addition & 1 deletion count.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func main() {
i := 0
target, _ := strconv.Atoi(os.Args[1])
for i < target {
i = (i + 1) % 2000000000
i = (i + 1) | 1
}
fmt.Println(i)
}
2 changes: 1 addition & 1 deletion count.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import System.Environment
count :: Int -> Int -> IO ()
count target n
| n == target = print n
| otherwise = count target ((n + 1) `mod` 2000000000)
| otherwise = count target ((n + 1) .|. 1)

main :: IO ()
main = do
Expand Down
2 changes: 1 addition & 1 deletion count.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ public static void main(String[] args){
int i = 0;
int target = Integer.parseInt(args[0]);
while (i < target) {
i = (i + 1) % 2000000000;
i = (i + 1) | 1;
}

System.out.println(i);
Expand Down
2 changes: 1 addition & 1 deletion count.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let i = 0;
let target = parseInt(process.argv[2]);
while (i < target) i = (i + 1) % 2000000000;
while (i < target) i = (i + 1) | 1;
console.log(i);
2 changes: 1 addition & 1 deletion count.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fun main(args: Array<String>) {
var i = 0
val target = args[0].toInt()
while (i < target) {
i = (i + 1) % 2000000000
i = (i + 1) or 1
}

println(i)
Expand Down
2 changes: 1 addition & 1 deletion count.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
$i = 0;
$target = (int) $argv[1];
while ($i < $target) {
$i = ($i + 1) % 2000000000;
$i = ($i + 1) | 1;
}
echo $i . "\n";
?>
2 changes: 1 addition & 1 deletion count.pl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
my $i = 0;
my $limit = $ARGV[0] + 0;
for ($i = 0; $i < $limit; $i = ($i + 1) % 2000000000) {}
for ($i = 0; $i < $limit; $i = ($i + 1) | 1) {}
print "$i\n";
2 changes: 1 addition & 1 deletion count.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
i = 0
target = int(sys.argv[1])
while i < target:
i = (i + 1) % 2000000000
i = (i + 1) | 1

print(i)
2 changes: 1 addition & 1 deletion count.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
i = 0
target = ARGV[0].to_i
while i < target do
i = (i + 1) % 2000000000
i = (i + 1) | 1
end

puts i
2 changes: 1 addition & 1 deletion count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fn main() {
let mut i = 0;
let target = env::args().nth(1).unwrap().parse::<i32>().unwrap();
while i < target {
i = (i + 1) % 2000000000;
i = (i + 1) | 1;
}

println!("{}", i);
Expand Down
2 changes: 1 addition & 1 deletion count.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ object count {
var num = 0
val target = args(0).toInt
while (num < target) {
num = (num + 1) % 2000000000
num = (num + 1) | 1
}

println(num)
Expand Down
2 changes: 1 addition & 1 deletion count.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn main() !void {
var target = try std.fmt.parseInt(u32, args[1], 10);
var i: u32 = 0;

while (i < target) : (i = (i + 1) % 2000000000) {}
while (i < target) : (i = (i + 1) | 1) {}

std.debug.print("{}\n", .{i});
}

0 comments on commit 1bf1061

Please sign in to comment.