我有一个 Haskell 程序,主要有两行代码:
putStrLn $ "Day11: part1: " ++ show (sum $ bigManhattan 1 galaxies <$> pairs)
putStrLn $ "Day11: part2: " ++ show (sum $ bigManhattan 999999 galaxies <$> pairs)
Run Code Online (Sandbox Code Playgroud)
如果我注释掉其中任何一个,程序将在 0.01 秒内运行。由于两者都存在,该程序需要 90 秒的时间。
我想知道有人有什么想法吗?他们是否会竞争查看数据并互相妨碍?
编译器选项 - 我不知道其中大多数是做什么的......
ghc-options:
- -Wall
- -Wcompat
- -Widentities
- -Wincomplete-record-updates
- -Wincomplete-uni-patterns
- -Wmissing-export-lists
- -Wmissing-home-modules
- -Wpartial-fields
- -Wredundant-constraints
- -O2
Run Code Online (Sandbox Code Playgroud)
代码:
module Day11(day11) where
import Data.List ((\\))
import Data.Maybe (catMaybes)
type Coord = (Int, Int)
manhattan :: …Run Code Online (Sandbox Code Playgroud) 最近的 (C23) 添加stdckdint.h提供了一种可移植的方法来检查整数算术中的溢出问题。我过去曾在用户提供相关整数的情况下使用过类似的编译器扩展,并且它们非常有帮助。现在我面临着一种情况,提供的值是浮点数,我需要对它们进行算术运算。
我的问题是是否有类似的解决方案(不一定在标准库中),以确保浮点变量(浮点数、双精度数、长双精度数)之间的操作不会遇到任何问题。如果不是,算术运算期间可能出现哪些问题(上溢、下溢等)以及如何检查这些问题?
我在 Angular 16 中有这个
<div *ngIf="post$ | async as post">
<h1>{{ post.attributes.title }}</h1>
</div>
Run Code Online (Sandbox Code Playgroud)
的类型post$是 Observable<ContentFile<BlogPost | Record<string, never>>>
我想用新的内置控制流语法重写它。
@if(post$|async as post) {
}
Run Code Online (Sandbox Code Playgroud)
as post部分结果为
解析器错误:[post$|async as post] 中的第 13 列出现意外标记“as”...
如何解决这个问题?
每当我使用 C++ 时,我都可以一次“引用”多个字节。例如:
char* charptr = new char;
Run Code Online (Sandbox Code Playgroud)
此行在堆栈上分配一个新变量,即指针charptr,该变量指向堆上的 1 个字节的数据。这是有道理的,因为我的计算机上的物理地址可以存储 1 个字节。
然而,混乱是从这样的一行代码开始的:
int* intptr = new int;
Run Code Online (Sandbox Code Playgroud)
该指针仅包含 8 字节整数的单个地址。
一个地址如何存储多个字节?
我尝试在 StackOverflow 上搜索,但找不到答案,我想知道这是如何工作的(我正在尝试制作一个小人计算机风格的模型,并希望为其实现一种高级语言)。
考虑使用默认比较稍微修改一下 cppreferenece.com 的示例:
struct Point
{
int x;
int y;
auto operator<=>(const Point&) const = default;
//bool operator!=(const Point&) const = default;
bool isDifferent(const Point& another) const
{
// Fails without explicit operator !=
return operator != (another);
}
bool isSame(const Point& another) const
{
// Always OK
return operator == (another);
}
};
int main()
{
Point pt1{1, 1}, pt2{1, 2};
std::cout << std::boolalpha
<< (pt1 == pt2) << ' ' // Always OK
<< (pt1 != …Run Code Online (Sandbox Code Playgroud) 我正在使用 GitLab CICD,处于定义的 docker-test 阶段
docker_test: image: docker:stable services: - docker:stable-dind stage: docker-test
......
昨天工作正常,但今天 - GitLab 管道 'docker_test' 失败并显示: TypeError: kwargs_from_env() got an Unexpected keywords argument 'ssl_version'
我在互联网上发现它可能升级到 7.0.0 https://docker-py.readthedocs.io/en/stable/change-log.html
这里有人建议(对于不同的设置)降级到以前的 6.3.1
搜索后 - 不知道该怎么做。也许还有其他解决方案?
我正在使用一种选择加入方法,可以通过自定义类的 std::cout 和 fmt::print 打印到控制台。为此,我创建了一个std::string to_string(const T& value)在一般情况下未定义的函数。专业课程应该:
to_string(const MyType& t)struct printable< MyType >: public std::true_type{}这将依次激活std::ostream并 fmt::formatter自动专门针对每种printable类型。一个完整的例子是这样的:
#include <fmt/format.h>
#include <fmt/ostream.h>
#include <fmt/ranges.h>
#include <concepts>
#include <iostream>
#include <string>
#include <vector>
namespace common {
template <typename T>
std::string to_string(const T& value);
template <typename T>
struct printable : std::false_type {};
template <typename T>
constexpr bool printable_v = printable<T>::value;
} // namespace common
template <typename T>
requires(common::printable_v<T>)
auto& operator<<(std::ostream& os, const …Run Code Online (Sandbox Code Playgroud) 我想实现这种外观并尝试相应地设置 JPanel 组件,但当我运行应用程序时,我看到了不同的位置。这就是我正在寻找的外观:
首先,顺序不正确,其次,项目之间没有空格,所以总的来说,这不是我想要的。如何修复它以使其看起来与我第一次添加的图像相似?我的代码:
package Lab5;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;
public class FontDesigner extends JFrame {
public FontDesigner() {
// JFrame
setSize(400, 400);
setTitle("Font Changer");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// String
JLabel text = new JLabel("Change Me");
text.setFont(new Font("Arial", 1, 28));
// Radio Button
JRadioButton button1 = new JRadioButton("Small");
JRadioButton button2 = new JRadioButton("Medium");
JRadioButton button3 = new JRadioButton("Large");
ButtonGroup radioGroup = new ButtonGroup();
radioGroup.add(button1);
radioGroup.add(button2);
radioGroup.add(button3);
/*
* if (button1.isSelected()) {
* text.setSize(1);
* }
*/
// Combo Box …Run Code Online (Sandbox Code Playgroud) 在 Azure DevOps 构建管道中构建我的 .NET 8 iOS MAUI 应用程序时,它抱怨我没有使用最新的 Xcode。
ILLink : iOS error IL7000: An error occured while executing the custom linker steps. Please review the build log for more information. [/Users/runner/work/1/s/MyProject/MyProject.csproj::TargetFramework=net8.0-iOS]
/Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/UIKit/UIApplication.g.cs(95): error MT4162: The type 'UIKit.UISceneSessionActivationRequest' (used as a parameter in UIKit.UIApplication.ActivateSceneSession) is not available in iOS 16.4 (it was introduced in iOS 17.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode). [/Users/runner/work/1/s/MyProject/MyProject.csproj::TargetFramework=net8.0-iOS]
ILLINK : error MT2362: The …Run Code Online (Sandbox Code Playgroud) Traceback (most recent call last):
File "/opt/ros/melodic/share/gencpp/cmake/../../../lib/gencpp/gen_cpp.py", line 50, in <module>
sys.argv, msg_template_map, srv_template_map)
File "/opt/ros/melodic/lib/python2.7/dist-packages/genmsg/template_tools.py", line 213, in generate_from_command_line_options
generate_from_file(argv[1], options.package, options.outdir, options.emdir, options.includepath, msg_template_dict, srv_template_dict)
File "/opt/ros/melodic/lib/python2.7/dist-packages/genmsg/template_tools.py", line 154, in generate_from_file
_generate_msg_from_file(input_file, output_dir, template_dir, search_path, package_name, msg_template_dict)
File "/opt/ros/melodic/lib/python2.7/dist-packages/genmsg/template_tools.py", line 99, in _generate_msg_from_file
search_path)
File "/opt/ros/melodic/lib/python2.7/dist-packages/genmsg/template_tools.py", line 77, in _generate_from_spec
interpreter = em.Interpreter(output=ofile, globals=g, options={em.RAW_OPT:True,em.BUFFERED_OPT:True})
AttributeError: 'module' object has no attribute 'RAW_OPT'
Traceback (most recent call last):
File "/opt/ros/melodic/share/gencpp/cmake/../../../lib/gencpp/gen_cpp.py", line 50, in <module>
sys.argv, msg_template_map, srv_template_map)
File "/opt/ros/melodic/lib/python2.7/dist-packages/genmsg/template_tools.py", …Run Code Online (Sandbox Code Playgroud)